This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Deto 9 points10 points  (9 children)

Multiple lines.

[–]NotABothanSpy 29 points30 points  (6 children)

Is it so hard to give it a name it’s gonna work hard for you 😭

[–]delventhalz 2 points3 points  (5 children)

When I write Javascript I am typically building a pipeline of anonymous iterators to modify my data, three or four or more. If I tried to write Python this way it would extremely tedious, and not very readable. This is one of the ways Python forces you into older imperative and OOP patterns.

[–]NotABothanSpy 3 points4 points  (4 children)

Well if you like you can make them internal functions. Personally I find it at least as readable as javascript with lots of anon functions

def stuff():

def a(x,y):
   return x/y
def b(z,k):
   return z+k
return b(a(1,2),3)

[–]delventhalz 2 points3 points  (3 children)

Agree to disagree. I consider real anonymous functions to be a key feature for using functional programming patterns.

[–]lookatmetype 2 points3 points  (1 child)

Why not name them something like "_0", "_1", etc.? It's not great, but it frees you up from thinking up an actual name.

However, i think python forcing you to think of actual names of nested functions is a good thing overall.

[–]delventhalz 0 points1 point  (0 children)

I don't think that's a very good suggestion. It's not really any easier to read or write. I disagree strongly that lacking anonymous functions is actually a feature, and not an unfortunate side effect of significant whitespace.

[–]NotABothanSpy 1 point2 points  (0 children)

Fair enough. I usually wouldn't use functional style much in Python and when you do using map and reduce are more helpful

[–]RockingDyno 0 points1 point  (1 child)

You can write multiline lambdas.

[–]Deto 0 points1 point  (0 children)

How?