This is a review of an old blog post. I actually changed it quite a bit, turning the meaning 180 degrees.
C++ was (and still is) my bread and butter for many year. I know it pretty well, wrote tons of code in C++, and have seen even more of it. My main conclusion from over a decade of experience is, that C++ is a great tool for those who know to program. It’s a great tool to create spaghetti code though, for those who knows the language, but don’t know really how to program. By programming I mean building piece of software that works and is maintainable, and doesn’t require unreasonable amount of resources in the process.
Linus Torvalds believes C++ sucks, saying: It’s made more horrible by the fact that a lot of substandard programmers use it, to the point where it’s much much easier to generate total and utter crap with it.
I respectfully disagree with the Maestro. It’s not C++ which sucks. It’s not violin’s fault that there are so many bad violinists around.
C++ is the most flexible programming language, it gives one the ability to control your object memory layout to the level of bytes and bits, and yet to use such high-level mechanisms as polymorphism, exceptions, and meta-programming. In a sense, it’s allowing you to work on high-level design and yet to be able to super-optimize, when necessary. (What a potential for screwing things up! ) I love this language, and I personally wrote quite complicated pieces of software in it.
Another point of criticism might come from totally different direction: why the heck it took so long to C++ committee to introduce the range-based for loop? This one:
for (int i : vec) cout << i;
It’s because C++ lacked “syntactic sugar” for bunch of standard idioms, it was becoming obsolete in this new rapidly changing world.
I would take one step further, and would put a “blame” on the very foundation of C language which is:
- Very simple syntax
- The rest can be found in libraries
Modern programming languages (C#, Python, Ruby, even not-so-modern Perl) rarely follow this pattern (not to mention the fact they all are VM-based). Their standard libraries change more often, and you would be lucky if they are always backward compatible. Their syntax and built-in data structures are more complicated than ones found in C or C++. Bigger learning curve is the price that programmers pay, but after that the development time is significantly reduced. Moreover, most employers nowadays prefer to hire people proficient with specific platform or framework (or even specific combination of the latter), rather than just a language.
Given all this, C++ seems to be in decline. Basically, it’s becoming a niche language for applications requiring good performance, like high-frequency trading, real time, etc… But even then some projects willingly sacrifice performance by moving to C#, for the sake of maintainability.
In some fields, however, people are so determined to optimize their performance, that C++ is not only becoming the only option, but they even try to write their code in pure C, for the sake of “not messing up” and, well, speed of compilation. All that made me really think about the differences between C and C++, which I will probably cover in the next blog.