3 ms·
This will be a great thing for Javascript. One thing I noticed, however, was that the main arguments for Hack-style pipes over F# pipes really highlight the dif
by gtf21 5y ago
This will be a great thing for Javascript. One thing I noticed, however, was that the main arguments for Hack-style pipes over F# pipes really highlight the difference between functional languages like Haskell and languages like JS: in Haskell one designs functions for composition (and more generally, one designs structures for combination), whereas the fact that F# pipes cause awkward contortions in JS is mostly related to the fact that functions aren't designed for composition.
While I marginally prefer F# pipes, both will drastically improve the readability of JS code.
- lostmsu 5y agoI did a lot of of F#, and I disagree. While many functions have an argument that is clearly "primary", some just don't. I personally find placeholder to be a better option, especially if used with named arguments. Seeing your later comment about functional languages, I think they suffer from lack of overloading. E.g. F#'s fold2 would be much better as |> fold(a, %, func). Sometimes there's just no way around it.
- gtf21 5y agoI have never written anything in F# and I have no familiarity with the language, so I'm speaking more from my (IMO quite basic) familiarity with Haskell and Clojure, and most especially the former. In Haskell composition is just such a natural part of the design of programmes, and yes, functions often have many arguments. One just designed with composition in mind so this "piping" works really easily.
- Spivak 5y agoI think that’s my main issue with them. You shouldn’t need to write your code in a particular style to make a core language construct useful because of how often you deal with code that isn’t yours. Having to carry around a bunch of adapter functions kills any readability benefit.
- gtf21 5y agoI don't understand which "them" you mean -- are you talking about pipes or functional languages like Haskell?
- nine_k 5y agoThe Hack-style pipes are immediately useful even when you introduce steps that are not unary functions. With a lot of stdlib using functions / methods of higher arity, I suppose the Hack version will lead to shorter and easier-to-read pipes in most real codebases.
- gtf21 5y agoI understand why the Hack-style pipes are probably a better choice for JS as we find it and its ecosystem, it's just that, having switched from my main languages being JS/TS and Python to now using Haskell most of the time, this contortion was what really struck me -- the emphasis on currying and function composition in pure functional languages just makes this a lot more natural. As I said above, however, I think either method will be a fantastic addition to JS.