Ditto @paxdiablo. The early programming languages were written by mathematicians--actually all of them were. In mathematics, by her own principle--reading left to right-- it makes sense in the way it works.
x = 2y - 4.
In mathematics, you would say this: Let x be equal to 2y -4.
Also, even in algebra you do this. When you solve an equation for a variable, you isolate the variable you are solving for to the left side. i.e. y = mx + b;
Furthermore, once an entire family of languages-- such as the C family-- has a certain syntax, it is more costly to change.
You aren't using it now, but the next time you leak memory or get a double delete, you'll be begging to come back to std::vector<T>
, std::unique_ptr<T, Del>
and std::shared_ptr<T>
, which can solve those problems easily- almost trivially. That's what happens to everyone who uses C over C++, eventually, and the smarter ones just don't wait for the bugs to pop up before moving over.
Code that uses new
and delete
directly doesn't really belong in C++, it belongs in that kind of half house that we refer to as "C with Classes". That's where the language was circa 1985. It's not particularly similar to C++, circa 2011. In all likelihood, wherever you learned C++ simply didn't teach it very well- something that is unfortunately rather common- and with a better education, you would find use of these features.
Specifically, as I listed above, C++'s generic data structures and the resource-managing classes simply are fundamentally massively superior to anything C has to offer. If you want a dynamically allocated array, then use std::vector<T>
. That's a pretty common use case. If you aren't using them, then your code is at huge risk of error unnecessarily- especially resource management related. C++ can guarantee safety and re-use code in a way that C can never touch.
However, I think that you also might be expecting too much. Writing templates and operator overloads is not common for library consumers. If your code uses std::vector<T>
, you don't need to write a template to make that happen. If your code uses std::string
, nobody is forcing you to overload your operators. You only have to do those things to write std::vector<T>
and std::string
- but you can still take full advantage of them.
Polymorphism/inheritance also only has a specific use case. If your code happens to not require you to write any templates or use virtual functions, then it doesn't, and there are programs or segments of programs where you don't need to write your own templates.
Also, there's no gain in performance in C over C++.
Best Answer
In the old days of C, there was no boolean type. People used the
int
for storing boolean data, and it worked mostly. Zero was false and everything else was true.This meant if you took an
int flag = 0;
and later didflag++
the value would be true. This would work no matter what the value of flag was (unless you did it a lot, it rolled over and you got back to zero, but lets ignore that) - incrementing the flag when its value was 1 would give 2, which was still true.Some people used this for unconditionally setting a boolean value to true. I'm not sure it ever became idiomatic, but its in some code.
This never worked for
--
, because if the value was anything other than 1 (which it could be), the value would still not be false. And if it was already false (0
) and you did a decrement operator on it, it wouldn't remain false.When moving code from C to C++ in the early days, it was very important that C code included in C++ was still able to work. And so in the specification for C++ (section 5.2.6 (its on page 71)) it reads:
This is again mentioned in section 5.3.2 (for the prefix operator - 5.2.6 was on postfix)
As you can see, this is deprecated (Annex D in the document, page 709) and shouldn't be used.
But thats why. And sometimes you may see the code. But don't do it.