Hacker News new | ask | show | jobs
by tikhonj 5152 days ago
Simplest case: custom control structures.

In JavaScript, a broadly comparable language, I mainly use anonymous functions for event handling and map/each/fold. They are also useful for implementing more advanced code like arrows cleanly.

In a lot of ways the anonymous function in these cases is more akin to a block than a named function--it's only used once and in a very clear place. Having to name my click and onload handlers would make the code more confusing.

Coincidentally, this brings me to something that annoys me in both languages: lambdas are too verbose. Having much simpler and more concise lambda syntax (I'm personally a fan of Haskell's \ x -> x because it looks like a lambda if you squint) would make a lot of common idioms more readable and would encourage wider use of custom control abstractions, which can significantly improve code.

Amusingly I don't find myself using lambda syntax nearly as much in Haskell despite the fact that it looks really nice. A surprising amount of the time simple point-free code is all that's needed, and anything too complex gets moved into a where clause. But Haskell is not really comparable with JavaScript/Python at all.