foo(bar(baz(new_function(other_function(my_input)))))
You have the option to write:
my_input |> other_function() |> new_function() |> baz() |> bar() |> foo()
The readability benefit is clear - you don't have to read the code "backwards" to understand what it really does.
—- (end of snippet)
This is a nice example of fixing a problem that does not need be there at all.
Just use intermediate variables instead of doing clever stuff. Benefits:
- 1 way of doing stuff
- variable names will help readers understand the intention of the function calls
- you can do explicit error handling for each call
Note: in contrast, in shell prompts the pipe operator is useful because:
- less typing counts here
- prompts are use-once mostly, maybe repeated (history & scripts), but readability is not a mayor concern
- commands deal with large amount of data often, hence storing in intermediate variables can be expensive or even impossible.
None of these points are valid for a programming language. (Unless of course you just fancy the syntax)
Btw I find the joke about “bearded wizards” not very inclusive towards women. It feels assuming that only men (can) be that wizardry.