What Is Functional Programming – In Python
coriers.com
coriers.com
The lambda calculus is functional programming, regardless of whether it was intended to be run on a computer or not.
> This is also known as “currying”, a term named after FP pioneer Haskell Curry.
So Curry — a mathematician — is an FP pioneer, but the lambda calculus is not functional programming. I find this a strange stance to take haha.
> These functions can turn many-line loops into incredibly concise one-liners. However, they are often harder for the average programmer to grapple with, especially when compared to the almost-English flow of imperative Python.
I'm undecided whether these concepts are actually more difficult to understand, or if they're more difficult for people who are used to imperative programming specifically because they're used to imperative programming. I'm interested to hear other people's perspectives on this.
> Personally, I can never remember the argument order [of these higher-order functions]
A fault of Python, not the author, I think.
> However, I wouldn’t recommend writing a lot of functional-first Python, especially in a shared or long-lived codebase.
I don't think the author really motivates this thesis, but strangely that's because the rest of the article doesn't seem to be about this thesis (in my opinion).
Writing functionally is, as the author says earlier in the piece, more of a way of life than anything inherent to the language. So long as your language supports higher-order functions, you can write functional code.
The rest of the article's suggestions — opting for pure functions, limiting use of classes, etc — all fit in with a functional-first paradigm, I think, despite the author's claim that they "wouldn't recommend writing a lot of functional-first Python". You don't need to use map/reduce to be a functional programmer. You just need to be working with functions and their composition instead of data and its mutation, and you're mostly all set.