3 ms·
That deep nest of function calls is why I love languages that have bash-style pipelining as a built in feature, either with explicit shell piping features, or w
by Pxtl 2y ago
That deep nest of function calls is why I love languages that have bash-style pipelining as a built in feature, either with explicit shell piping features, or where everything Function(myObj) is also implicitly myObj.Method()
Then it becomes (eg PowerShell, a language I hate but use constantly)
Faz |
Far |
Baz |
Bar |
Foo
Or (more C++/Java/C#-ish)
Faz()
.Far()
.Baz()
.Bar()
.Foo()
In this way the data and execution flows forwards instead of backwards and you don't have a pyramid of indentation.
I don't know why we're so stuck on prefix notation for function calls. Postfix is just easier to read in long chains.
- sitkack 2y agoIn Python you have the wonderful https://github.com/pytoolz/toolz https://github.com/pytoolz/toolz from toolz import pipe pipe('hello',lambda w: ( "foo", w ), lambda y: [ 0, y, 1 ]) [0, ('foo', 'hello'), 1] You can used named functions, but they would need to be define above in upper scope def h(x): return ( "foo", x ) def g(x): return [ 0, x, 1] pipe('hello', h, g)
- behnamoh 2y agothanks, I'll check this out. I've seen similar libs before, like "pipes" which also does piping through the "|" symbol.
- aartaka 2y agoThis is a good style indeed, and I'm using it a lot in JavaScript, but you have to admit that it's never as consistent as that—there are basic functions mixed into it, and some lambdas, and whatever.