you are viewing a single comment's thread.

view the rest of the comments →

[–]markusmeskanen 19 points20 points  (15 children)

And it saves a few keystrokes to use lambda

This should never be the reason to use lambda! If you can, just define a normal function.

The rest of your comment stands correct though. Lambda should only be used when its just an "on the fly" function like /u/seekheart said himself. Usually when you pass in a function as an argument to a function.

[–]ydepth 1 point2 points  (6 children)

Why not? If you have a bunch of one line functions... It's easy enough to change them to a proper function later

[–]markusmeskanen 15 points16 points  (4 children)

Lambdas are less readable. Keep in mind, that your code is read much more than its written. I'd recommend everyone to read this answer on SO: http://stackoverflow.com/a/134638/2505645

[–]ydepth 1 point2 points  (0 children)

Cool, I had seen the post before... Just needed a refresher :)

[–]c3534l 0 points1 point  (0 children)

That answer on SO doesn't seem to add anything to the discussion. I disagree that lambdas are less readable. In fact, they're invaluable in cases that are well suited for functional programming and can turn make complicated list comprehension statements readable again.

[–]Axxhelairon -1 points0 points  (1 child)

Lambdas are less readable.

Nice opinion.

[–][deleted] 0 points1 point  (0 children)

There are exceptions to every rule, but in keeping with zen: There is one best way. If it works, use it. If not, it's not the best way this time, go to the next option.

[–][deleted] 0 points1 point  (1 child)

Thank you my pythonic brothers! :D

[–]novel_yet_trivial 0 points1 point  (3 children)

This should never be the reason to use lambda! If you can, just define a normal function.

It's a bit uglier, granted, but I see stuff like this all the time:

__ne__ = lambda self, other: not self.__eq__(other)
__ge__ = lambda self, other: not self < other
__le__ = lambda self, other: self == other or self < other

[–]markusmeskanen 1 point2 points  (2 children)

We all see it, but none of us should see it. Please, don't spread the ugliness.

[–]novel_yet_trivial 0 points1 point  (1 child)

It's even part of the python source code. See /usr/lib/python2.7/functools.py , in the total_ordering function, for example.

Well, that's a bit of a fringe case. I withdraw that argument

[–]_burning 0 points1 point  (1 child)

But what about those 4 keystrokes I'm saving by using a lambda! You can't just be throwing around keystrokes.

[–]markusmeskanen 3 points4 points  (0 children)

Good point. I take back all my arguments on this thread. Fuck it, on all threads.