|
|
|
|
|
by zarzavat
806 days ago
|
|
It’s worth noting that even in Haskell, overuse of the so called point-free style is disliked for much the same reasons: https://wiki.haskell.org/Pointfree There is a sliding scale and even at the Haskellers have a limit of how much point-free they can take. In JavaScript use of the style is problematic in another way: unlike Haskell in JS the length of the argument list is variable, which means that if someone adds another argument to either the caller or callee it can break the code in subtle and unexpected ways. For this reason it’s good practice to always wrap functions being passed as arguments to another function in a lambda expression. i.e instead of writing: g(f), you should usually write: g(x => f(x)) unless you have good reason to believe that g(f) is safe. This makes it difficult to use point-free style at all in JS. For example arr.map(f) is generally unsafe in JS because if `f` adds an extra default argument of type number then your code will break and even TypeScript won’t let you know. |
|