3 ms·
This operator proposal has been there for quite some time! Seems like it gets rediscovered periodically and continues to provoke heated discussions. Personally
by djedr 5y ago
This operator proposal has been there for quite some time! Seems like it gets rediscovered periodically and continues to provoke heated discussions.
Personally, I used to be fairly strongly against it, but nowadays I'm not sure if I care. I suppose I'm still not particularly in favor. But maybe I'm biased towards minimalism. I don't dislike the idea of the operator in itself, just how it fits (or rather doesn't fit) into JavaScript. I think it makes more sense in F#.
Four years ago I got really sucked into this topic and thought about this a lot. I had a lot of fun writing down a few counterarguments:
https://djedr.github.io/posts/random-2018-01-25.html https://djedr.github.io/posts/random-2018-01-25.html
This was partly inspired by this HN thread:
https://news.ycombinator.com/item?id=16193112 https://news.ycombinator.com/item?id=16193112
It seems that since that time `Function.pipe` appeared as a serious alternative or complement to the operator. Nice!
Besides `Function.pipe` these alternatives mentioned in the article are good:
https://2ality.com/2022/01/pipe-operator.html#using-intermediate-variables https://2ality.com/2022/01/pipe-operator.html#using-intermed...
https://2ality.com/2022/01/pipe-operator.html#reusing-a-variable-multiple-times https://2ality.com/2022/01/pipe-operator.html#reusing-a-vari...
The first one is actually the most simple, readable, safe, and has been supported forever. It's just verbose and suffers from the hard problem of naming things. Though sometimes just thinking about a good name for an intermediate variable can lead to good refactoring idea. And intermediate variables provide clean breakpoints -- easier for debugging.
The next alternative solves the naming and verbosity problem. Back when I was into this, I was writing a blog post about this technique. Ended up not finishing it before my interest in bikeshedding faded. Which reminds me to cut this post short and tend to more pressing matters.
It can be fun though.