Sadly, Python is a pretty poor functional language. The core of functional programming is about avoiding mutable states , not much about anonymous functions or passing functions as data. To do proper functional programming in Python, there should be IMO: - a way to enforce non-mutable variables/objects; - non-mutable collections; - proper support for recursion and tail-recursion optimization; - a better syntax for an…
Functional Python Programming
31–40 of 105 posts
Re: Functional Python Programming
#32What blows my mind is that Python was designed for maths and data science by a maths and data science guy. It should be natural to work with immutable values and pipelines in Python, which are natural functional constructs. Yet everything in Python is mutable and pipeline-style programming is not really supported. ??? (A long time ago I tried to teach programming fundamentals to a maths person. She was completely puz…
I don't think so.
> During Van Rossum's stay at CNRI, he launched the Computer Programming for Everybody (CP4E) initiative, intending to make programming more accessible to more people, with a basic "literacy" in programming languages, similar to the basic English literacy and mathematics skills required by most employers. Python served a central role in this
Re: Functional Python Programming
#33In their definition of programming languages types, I'm not sure I see how SQL which they cateogrize as declarative really differs from FP, especially with lazy evaluation. Both are a succession of functions applied onto a previously declared variable : just think of a long SQL query with many ctes modifying the previous ones; each of them can be thought of as a variable which takes its value from the application of…
Re: Functional Python Programming
#34Earlier quoted context omitted.
Just curious, but from a pragmatic view, what is the advantage of using anonymous functions instead of named functions for any mildly complex code?
Readability and scoping are two big advantages. Anonymous functions are often short and sweet, but also highly specific to a single section of the code. It's not meant to be reused. Having to name that one-off use case and hoist it into a function elsewhere makes it harder to maintain and understand. With proper anonymous functions, you can just read through it in one go.
Re: Functional Python Programming
#35What blows my mind is that Python was designed for maths and data science by a maths and data science guy. It should be natural to work with immutable values and pipelines in Python, which are natural functional constructs. Yet everything in Python is mutable and pipeline-style programming is not really supported. ??? (A long time ago I tried to teach programming fundamentals to a maths person. She was completely puz…
In python the C and even C++ heritage is quite clear, but it is in no way designed like Miranda and Haskell, which actually target to some extent expressing particular mathematical constructs in code, something which neither C, C++ not python ever aspired to.
Re: Functional Python Programming
#36In their definition of programming languages types, I'm not sure I see how SQL which they cateogrize as declarative really differs from FP, especially with lazy evaluation. Both are a succession of functions applied onto a previously declared variable : just think of a long SQL query with many ctes modifying the previous ones; each of them can be thought of as a variable which takes its value from the application of…
SQL does not support higher-order functions or lambdas (except possibly in some special dialect I'm not aware of)
Re: Functional Python Programming
#37Earlier quoted context omitted.
Readability and scoping are two big advantages. Anonymous functions are often short and sweet, but also highly specific to a single section of the code. It's not meant to be reused. Having to name that one-off use case and hoist it into a function elsewhere makes it harder to maintain and understand. With proper anonymous functions, you can just read through it in one go.
But you don't need to name it big or maintain it somewhere else? Just use a throwaway name and write it where you use it. I mean python even allows overriding functions with the same name in the same scope. You could literally go with using just the same name everywhere.
Re: Functional Python Programming
#38Sadly, Python is a pretty poor functional language. The core of functional programming is about avoiding mutable states , not much about anonymous functions or passing functions as data. To do proper functional programming in Python, there should be IMO: - a way to enforce non-mutable variables/objects; - non-mutable collections; - proper support for recursion and tail-recursion optimization; - a better syntax for an…
Why do you consider anonymous functions so important? Regular functions can be used the same way?
Re: Functional Python Programming
#39Earlier quoted context omitted.
But you don't need to name it big or maintain it somewhere else? Just use a throwaway name and write it where you use it. I mean python even allows overriding functions with the same name in the same scope. You could literally go with using just the same name everywhere.
True, but you're missing the point.