Stop writing lambda expressions in Python
treyhunner.com
Stop writing lambda expressions in Python
1–10 of 202 posts
Re: Stop writing lambda expressions in Python
#2Re: Stop writing lambda expressions in Python
#3While in some functional languages (Haskell) and array programming languages (J), tacit or point-free style is often more idiomatic than lambda expressions (or equivalent).
There's something funny about that.
Re: Stop writing lambda expressions in Python
#4the fact that creating a function with lambda versus the normal way is different is bonkers. for example, in f# (and other sane languages), the following are identical:
let test1 = fun x -> x * x
let test2 x = x * x
both return: x:int -> int
are they really different in python or is it just a weird naming problem? the article isn't explicit on the actual differences other than what is reported by the REPL.also, you can't pass operators as functions in python? in f#, you simply wrap them in parentheses.
let test3 f x y = f x y
> test3 (*) 2 3 ;;
val it : int = 6
i read an interview with hal abelson where he called python's lambda broken. seems so.edit: also, this guy's thoughts on map and filter, in my opinion, show the python community's backwoods thinking regarding functional programming. yes, it seems generator expressions are nice (they are called sequence expressions in f#), but map and filter, even for his simple examples are much more clear. they communicate better what is actually happening. the fact that he never uses map and filter at all and then goes on to basically say map and filter aren't even needed in python says a lot.
Re: Stop writing lambda expressions in Python
#5I have never seen a code that wasn't made clearer when moving from a three-liner non-lambda somewhere upper in the code, to a one-liner lambda used at the right place
Re: Stop writing lambda expressions in Python
#6Re: Stop writing lambda expressions in Python
#7all i could think of is "stop writing python". it seems to me that a lot of these problems are fundamental problems with python. i continue to not understand why anybody likes python the language. the fact that creating a function with lambda versus the normal way is different is bonkers. for example, in f# (and other sane languages), the following are identical: let test1 = fun x -> x * x let test2 x = x * x both re…
Re: Stop writing lambda expressions in Python
#8 const points = [[[1, 2], 'red'], [[3, 4], 'green']]
const points_by_color = points
.sort(([point, color]) => color)
I know it's kind of futile to argue against a point using what-ifs, but personally I wish Python embraced this style of functional programming a little bit more and adapted its syntax to it, rather than coming across articles where people recommend against this style just because the language isn't (currently) as suitable to it.Re: Stop writing lambda expressions in Python
#9So in Python, imperative style is often more idiomatic than code that uses lambda expressions. While in some functional languages (Haskell) and array programming languages (J), tacit or point-free style is often more idiomatic than lambda expressions (or equivalent). There's something funny about that.
Re: Stop writing lambda expressions in Python
#10all i could think of is "stop writing python". it seems to me that a lot of these problems are fundamental problems with python. i continue to not understand why anybody likes python the language. the fact that creating a function with lambda versus the normal way is different is bonkers. for example, in f# (and other sane languages), the following are identical: let test1 = fun x -> x * x let test2 x = x * x both re…
That's what python is doing and why the two are different.
(I don't think a language should track that sort of thing, but that's a different story).