3 ms·
> Point-free programming has always been a controversial subject. Some people passionately hate it (particularly people that haven't invested in learning to use
by Tainnor 4y ago
> Point-free programming has always been a controversial subject. Some people passionately hate it (particularly people that haven't invested in learning to use it) and some passionately love it.
And for other people, such as myself, it depends on the particular case.
I think that point-free style can be clearer and more concise in certain cases (particularly when you're chaining a sequence of operations), but you can also really overdo it. I think when you start to use (in Haskell) "flip", "uncurry", etc., the question is whether it wouldn't be more readable to just name the arguments instead. But obviously, people are going to have varying levels of tolerance for such things.
- chriswarbo 4y agoPoint-free style can be useful as an intermediate step when refactoring, since making code point-free (a) is largely mechanical (although judgement can still useful to avoid horrible results!), and (b) removes many of the abstractions and variable names in the code. The latter are often historical baggage, telling us what the code used to do, or was meant to do; whilst a point-free version shows us more directly what it actually does. If the point-free version makes sense as-is, we can leave it; but that's rarely the case. Usually, we'll introduce a few abstractions and variables; but this time they'll be more appropriate for the current codebase.
- heavenlyblue 4y agoYou can also look at the generated assembly to figure out exactly what the code does
- chriswarbo 4y agoAssembly obfuscates the implementation with memory allocation, garbage collection, etc. which is often worse than even 'the wrong' (i.e. legacy) abstractions in a high level language.
- Xophmeister 4y agoIn my (admittedly newbie) experience, it's particularly useful when application of your function is going to be in a context where η-reduction is natural. For example, your fmap is going to look cleaner without a wrapping lambda inside it.
- Avshalom 4y ago>>start to use (in Haskell) "flip", "uncurry This I think lines up with the general Forth advice to avoid stack juggling (swap, roll, over, dup etc).
- zozbot234 4y agoSure, but some amount of stack juggling is unavoidable once you allow for multiple arguments/return values. It's a rare case when function arguments simply map "naturally" to the top values on the stack.
- thesz 4y agoJoy allows to return a concatenation on top of stack. That's a single element that can contain several elements, just like tuple in Haskell.