←back to thread

In Defense of C++

(dayvster.com)
185 points todsacerdoti | 2 comments | | HN request time: 0s | source
Show context
loeg ◴[] No.45268662[source]
> in C++, you can write perfectly fine code without ever needing to worry about the more complex features of the language. You can write simple, readable, and maintainable code in C++ without ever needing to use templates, operator overloading, or any of the other more advanced features of the language.

This... doesn't really hold water. You have to learn about what the insane move semantics are (and the syntax for move ctors/operators) to do fairly basic things with the language. Overloaded operators like operator*() and operator<<() are widely used in the standard library so you're forced to understand what craziness they're doing under the hood. Basic standard library datatypes like std::vector use templates, so you're debugging template instantiation issues whether you write your own templated code or not.

replies(7): >>45268759 #>>45268766 #>>45269024 #>>45272274 #>>45272736 #>>45274243 #>>45274785 #
butterisgood ◴[] No.45268759[source]
Overloaded operators were a terrible mistake in every programming language I've encountered them in. (Yes, sorry Haskell, you too!)

I don't think move semantics are really that bad personally, and some languages move by default (isn't that Rust's whole thing?).

What I don't like is the implicit ambiguous nature of "What does this line of code mean out of context" in C++. Good luck!

I have hope for C++front/Cpp2. https://github.com/hsutter/cppfront

(oh and I think you can write a whole book on the different ways to initialize variables in C++).

The result is you might be able to use C++ to write something new, and stick to a style that's readable... to you! But it might not make everyone else who "knows C++" instantly able to work on your code.

replies(5): >>45268857 #>>45268992 #>>45269102 #>>45271097 #>>45275305 #
wvenable ◴[] No.45269102[source]
Overloaded operators are great. But overloaded operators that do something entirely different than their intended purpose is bad. So a + operator that does an add in your custom numeric data type is good. But using << for output is bad.
replies(6): >>45270528 #>>45270621 #>>45272783 #>>45274942 #>>45279942 #>>45297713 #
1. jcelerier ◴[] No.45272783[source]
If you've done any university-level maths you should have seen the + sign used in many other contexts than adding numbers, why should that be a problem when programming?
replies(1): >>45273784 #
2. account42 ◴[] No.45273784[source]
There is usually another operator used for concatenation in math though: | or || or ⊕

The first two are already used for bitwise and logical or and the third isn't available in ASCII so I still think overloading + was a reasonable choice and doesn't cause any actual problems IME.