Admittedly I don't have a stellar solution to this though. Only alternative I can think of is ~
[0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
> const y = h(g(f(x)))
This example of nested function calls needs to be read from the inside out (execution is f, g, then h) which is unintuitive to how we read and parse text.
The alternative is to use intermediate variables instead of nested function calls to represent the control flow of f, g, h.
Debugging becomes a lot easier this way with a break point available at each step of the process.
There's nearly no disadvantage to creating the extra variables given how quickly they can be cleaned up by the GC in these cases.
The intermediate variables still have value, just not as much as they used to, and they do (arguably) increase the cognitive load for the reader
That's one alternative.
Another alternative is to use a function to apply functions in readable order (which effectively creates a context where “,” is the pipe operator.)
const pipe = (x, ...fns) => funs.reduce((acc, fn) => fn(acc), x);I agree that pipe is more readable.
I didn't say it was a better alternative, just one that is available.
> Besides that how many times do you need to call three functions without additional parameters?
That...depends on programming style, quite a lot.
TC39, as the article notes, and where the F#-style pipe has been shot down enough that it's been abandoned in favor of the Hack-style one by those championing a pipe operator.
Checkout this list of new JS/Node.js features [0] as an example.
Will a world with the following be an improvement? [1]
- ??=
- ||=
- &&=
And don't forget the strife around the Python "walrus operator" := [2]
Or is Scala's way what languages eventually converge into?
Funnily, in Scala, all of these are just simple plain methods. Including the pipe "operator". So Scala as a language is actually simpler here.
In repos you're contributing to.