3 ms·
Why do people want anonymous functions so much? Because in many cases a function is tightly associated with a particular context, and making it a separate name
by orangecat 3y ago
Why do people want anonymous functions so much?
Because in many cases a function is tightly associated with a particular context, and making it a separate named function is actually harmful for understanding.
personally, in python, I refuse to use lambda functions on ethical grounds
Do you really find this:
def get_name(x):
return x.name
sorted_by_name = sorted(people, key=get_name)
more readable than:
sorted_by_name = sorted(people, key=lambda x: x.name)
- fullspectrumdev 3y agoYes actually, it’s significantly more readable.
- dvfjsdhgfv 3y agoIt's debatable if it's more readable or not, for sure it's shorter.
- ipaddr 3y agoThe first is more readable and easy to follow but takes more effort to track down the original fuction
- bofaGuy 3y agoUnless you’re using a modern IDE… Then you just command click, and it takes you right to the function.
- zmmmmm 3y agothe "lambda" keyword is a problem. Compare to say, groovy: sorted_by_name = people.sort { it.name }
- bofaGuy 3y agoI’ve worked on several large and prominent projects; most of which experienced a large layoff of engineers in the middle of development. As the team who regularly takes over laid off team’s work with 1 engineer to the previous 10. The top things that slows our team down is “legacy” node applications (it seems like every time you turn around, whatever JavaScript or node version you used is out of date) and figuring out why an anonymous function exists and what it does. Also due to the multiple style choices and options in JavaScript the readability is trash.