9 ms·
Why do people want anonymous functions so much? Is it just because naming things is hard? Classically trained math focused types tend to be especially bad at n
by somat 3y ago
Why do people want anonymous functions so much? Is it just because naming things is hard?
Classically trained math focused types tend to be especially bad at naming things. Which, I guess, is fine when developing the infernal equation. but it sure does not do anyone any favors when they have to understand the thing.
personally, in python, I refuse to use lambda functions on ethical grounds, all my functions are named. And then you should see my javascript, all those names would probably make any real JS dev sick.
- zacmps 3y agoWhat? Anonymous functions are amazing for: * Iterators (map, reduce, filter) * Callbacks (ui actions) * Threads/async tasks The reason I don't name them isn't because I can't think of a name, it's because: * There's no point, they'll only be referred to once * Introducing a separate function block breaks the flow of the code and makes it harder to read (especially for iterators!)
- orangecat 3y agoWhy 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.
- winwang 3y agoAre you seriously going to name "obvious" functions like `[x + 1 for x in xs]`?
- fullspectrumdev 3y agoI agree - I also don’t use lambdas in Python, because they make the code significantly less readable or maintainable down the line.
- notfed 3y agoBecause coming from other languages like Rust, Kotlin, and ES6, going back to Python feels archaic. A huge reason for that comes down to lambda syntax.
- zmmmmm 3y ago> I refuse to use lambda functions on ethical grounds, all my functions are named This is embarrassingly more literal than I would like, but I in large part refuse to use Python on something similar to "ethical" grounds because it doesn't support inline / multiline functions (and a couple of other similar issues). After using typescript/ruby/groovy/scala/kotlin it's just so fused into my way of thinking about programming that each time I have to pull out an incidental function from its context and it reduces the clarity of the code, I grind my teeth. I'm guessing you just won't understand this unless you immerse yourself in another language and its idioms.