3 ms·
The first one looks like you're chaining functions together, while the second one looks like you're taking multiple bitwise or operations over the result of eac
by jschwartzi 12y ago
The first one looks like you're chaining functions together, while the second one looks like you're taking multiple bitwise or operations over the result of each function.
I think it's fascinating to see how the language can be extended. On the other hand I would not want to be the poor bastard stuck maintaining either construct after discovering some compiler edge case. If I've learned anything it's that just because you can do something doesn't mean you should.
The issue with extending operators in this fashion is that you're violating the principle of least surprise. | is an operator that should only really do exactly what it always does--bitwise or. If composition of functions is fundamentally analogous to taking the bitwise or of two values then I would concede that your second syntax is a bit clearer.
Personally I feel that this is not the case.
- pfultz2 12y ago> The issue with extending operators in this fashion is that you're violating the principle of least surprise. It is really common for the `|` operator to be used for piping functions together. There are several libraries that support it: [Boost.Range](http://www.boost.org/doc/libs/1_56_0/libs/range/doc/html/index.html http://www.boost.org/doc/libs/1_56_0/libs/range/doc/html/ind...), [PStade Oven](http://p-stade.sourceforge.net/oven/doc/html/index.html http://p-stade.sourceforge.net/oven/doc/html/index.html), [Linq](http://pfultz2.github.io/Linq/ http://pfultz2.github.io/Linq/), and [Streams](http://jscheiny.github.io/Streams/ http://jscheiny.github.io/Streams/). Plus, its even being proposed as part of the ranges library in future C++: https://github.com/ericniebler/range-v3/blob/master/doc/D4128.md https://github.com/ericniebler/range-v3/blob/master/doc/D412... So just as the bit shift operators in C++ also have the meaning of streaming in and out, the bitwise or also has the meaning of pipe, so this is should not at all be a suprise.
- jschwartzi 12y agoInteresting. I was not aware of this, so thank you.