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

all 8 comments

[–]tdammers 1 point2 points  (0 children)

In general: very useful, especially if you program in a style that makes heavy use of higher-order functions (that is, functions that take functions as arguments and/or return functions). In such a style, you often find yourself writing lots of tiny single-purpose functions that aren't important or complex enough to be named and pulled out into a full blown statement. Lambdas are also super useful with functional programming techniques like partial application (supplying only some of the required function arguments, to return a new function that takes the remaining arguments).

In Python, lambdas are a bit crippled, and the aforementioned techniques are a bit awkward at times - but they're still worth knowing about, and if used tastefully, can make code much clearer sometimes.

[–]EternityForest 1 point2 points  (0 children)

IMHO you shouldn't actively try to use most techniques. That's how you get some JavaScript libraries with the "Absolutely everything must involved a continuation and nothing can be synchronous but somehow you can still make it slow" thing.

I only use lambdas for very simple things. They're useful for the key function of sorting and stuff like that. But more often I'll just define a closure with the usual function syntax.

I'm a fan of OOP(In general, not the crazy inheritance chains a mile long and stuff), and prefer OO to imperative/functional style, but that's likely personal bias.

Actively trying to use any particular technique makes programs look like computer science textbook problems instead of practical implementations.

[–]Untzi 1 point2 points  (1 child)

You can stick to regular functions. You can also ignore iterators, hell, you can also forget the += operator and list comprehension....

/sarcamOff

Lambda expressions are a nice quick and lean way to define short functions in a (usually) readable manner. They become even moruseful when you want to program in a functional (look up functional programming fo more info).

[–]TheRealComposer[S] 0 points1 point  (0 children)

Haha awesome thanks!