Am I evil for this?

H. S. Teoh hsteoh at qfbox.info
Fri Oct 14 02:44:32 UTC 2022


On Fri, Oct 14, 2022 at 02:13:34AM +0000, Mike Parker via Digitalmars-d wrote:
> On Thursday, 13 October 2022 at 21:01:08 UTC, Araq wrote:
> 
> > Before C came along x << y already meant "x is much smaller than
> > y" and x || y sometimes meant "run x and y in parallel".
> > "Nonstandard purposes" hardly means anything. Use the operators as
> > you see fit.
> 
> "nonstandard purposes" were the OP's words, not Walter's. Walter's was
> talking about overloading for nonarithmetic purposes. This is not an
> uncommon criticism.

Generally, I agree with Walter.  Operator overloading should not be
taken as a free license to bend arithmetic operators to do things alien
to their basic arithmetic meaning.  That's just a big code smell, and
leads to hard-to-read code with poor maintainability.


> He cited the C++ iostreams library as many who make this criticism do,

Yeah, using << and >> for I/O is a total eyesore. The precedence doesn't
make sense for I/O, if you don't parenthesize, the expression could mean
something completely different from what you expect.  IMO, this a total
code smell, and a symptom of C++'s typical overly-clever-yet-still-
incomplete style of addressing language design issues.


> and also a project he saw in the past that overloaded C++ operators to
> make a regex DSL.
[...]

That would be Boost.Xpressive, I think.  Makes me cringe every time I
look at it.  In typical C++ hammer-a-nail-with-a-chainsaw fashion,
compile-time regexes take operator overloading abuse to a whole new
level and the result looks nothing like a regex, introducing a
maintenance nightmare (the same regex gets written in two *completely*
different ways depending on whether it's runtime or compile-time -- and
good like trying to read the compile-time one).

Now that constexpr is a thing, here's to hoping that this horrendous
operator overload abuse will soon be relegated to the dustbin of
history.


T

-- 
Caffeine underflow. Brain dumped.


More information about the Digitalmars-d mailing list