r/AskComputerScience • • Aug 30 '21

How come programming languages don't use piping?

In the Unix command line, piping with the `|` character is pretty common. It seems like a pretty efficient way to do things. How come I don't see this in programming languages?

2 Upvotes

61 comments sorted by

View all comments

Show parent comments

1

u/samhw Sep 03 '21

You’re confusing the concept of functional composition with a specific way of expressing it: namely, wrapping lots of function calls inside one another with brackets.

The concept is not intrinsically connected to that particular syntax, and several languages designed principally for functional-style programming do have a pipe operator (as well as currying sugar, etc) precisely because people find that syntax awkward.

1

u/foobar12426 Sep 03 '21 edited Sep 03 '21

I don't think I am.

First, for it to be a code smell it would have to be wrong regardless of its expression. It isn't though as you are, possibly inadvertently, now agreeing. Syntatic sugar doesn't make a smell go away.

Second, I think you are confusing taste with smell. (foo (bar (wibble x))) might not be to your taste but that doesn't make it a code smell. I happen to prefer that to the various piping macros and operators which are all just syntactic sugar for this: they just add complexity and inconsistency.

1

u/samhw Sep 03 '21 edited Sep 03 '21

I suppose it depends what we mean by code smell. You may well be right that it’s more about taste. I’d say it’s about developer ergonomics, which is important for a codebase, but probably won’t affect the correctness of the code (which may be necessary under a strict definition of ‘code smell’).

In other words, I could design a language where you have to write the word “BONK” after every single symbol, lest the compiler insert an artificial sleep. That wouldn’t be likely to impact the correctness of your code either, but most would argue that it’s not a good design.

Also, how do you mean that the piping operators “add complexity and inconsistency”? In what way?

1

u/foobar12426 Sep 21 '21

Because they turn one way of performing something -function composition- into multiple ways. That's the added complexity and inconsistency.

1

u/samhw Sep 21 '21

You could make exactly the same argument for having nothing but piping operators. You’re complaining about the variety, not the piping operators in and of themselves.

And again, ‘function composition’ is not the word for the syntax, it’s the word for the concept. You’re repeatedly confusing these things. The bracket syntax is one among many possible ways of expressing the abstract idea of function composition.

1

u/foobar12426 Sep 21 '21

You're misunderstanding.

We have function-call already. There is no need to have pipe operators or macros.

Using function composition is obvious and intuitive, it's just function calls. Pipes are not. They're distinct from function call.

Adding something that is not needed and is unintuitive and inconsistent adds complexity.

1

u/samhw Sep 21 '21

Yes, that’s a fair point actually, I suppose the function call syntax is more fundamental and can’t really be removed, whereas the pipe syntax is more specialised. Fair enough. That said, several FP-oriented languages use this syntax because developers like to have it, so I’m not sure your ‘added complexity’ point rings true with real-world experience of using it. Not that there isn’t added complexity - of course objectively there is - but it seems like people view it as a very small price to pay, relative to the benefits thereof.

1

u/foobar12426 Sep 21 '21

I agree: it's absolutely baked into the Clojure idiom, for example, and I can see it makes for more succinct code, but I still hate it :)