Developers love to argue over the relevance of coding languages, probably as much as everyone loves talking about Donald Trump in 2015. C++ gets the brunt of this developer languagism as newer, sexier languages emerge, but does poor C++ deserve this? Is C++ marked for death? Probably not. We’re going Green Party on this one — C++ has it’s pros and cons, but it’s still relevant today. As for Donald Trump, we’re not so sure.
Why People Hate on C++
At one time, C++ was the hot new language on the scene, and in that time C++ dominated the market. That bubble didn’t quite burst, but it did deflate over time as new languages popped up and gained popularity. Use of C++ still grows, but the market is growing so quickly around it that C++ looks as if it’s diminishing relatively. As we mentioned, use of C++ is largely based on personal opinion, but let’s look at some of the reasons people have for ignoring C++ in lieu of other languages:
C++ can be Unforgiving
When computing resources were limited, C++ was top of the list. However, there are so many other choices, and sometimes the speed of C++ is overlooked for other, ‘fast enough’ languages. Sometimes there’s just more going on in C++ than a developer knows what to do with, because faster languages do not mean faster programmer minds. So many developers will sacrifice speed for more padding in other areas. A quote by Bjarne Stroustrup sums up the ‘unforgiving’ sentiment:
“C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.”
C++ is a General Specialist
You can do pretty much any programming task under the (dim light of the basement) sun in C++. Opinion on this tends to support the idea that you would reasonably use C++ for something like writing an operating system, but would you actually use it to write a line on a website? It’s sort of like using a butcher knife to cut butter: it can be done, but it makes the task more dangerous and complicated. In comparison to other languages, C++ ranges from high level to low level programming tasks, where another language may attack a specific problem. C++ is the Costco of languages, and apparently not everyone loves a one-stop-shop.
Again with the generalism — the large number of features that C++ is capable of makes it more difficult to create a roadmap. C++ can handle templating, macros, overloading, and so on. C++ veterans usually choose which features they will use beforehand, and which can be left out. For inexperienced and unorganized teams, working in C++ can become an unwieldy maintenance nightmare. People dislike the bloating.
When building on top of old code written in C, C++ is compatible backwards. Therefore, a complex object model is built atop C, which is generally known to be simple and elegant. People dislike the ‘muddying’ of elegance, and many dislike the object-oriented programming of C++. Purists feel that C++’s aim to maintain C’s low level performance and be a high level performance is the wrong approach.
Why C++ is Still Relevant
C++ is still around and many of the applications that run on Windows and Linux are written in it. The entire AAA games industry, with a few multimillion dollar titles, depends on C++. We doubt any other language will ever be a good fit in that domain.
Despite the haters that feel C++ is quickly becoming legacy, C++ is a key in the evolution of programming languages, and there will always be a place for it. It’s still one of the most efficient languages when used appropriately, and it pretty much dominates the gaming world.
C++ is fast, the reason being C++’s explicit control over allocations and compiling to native code. While Python is close on C++’s heels, it will never be as fast because Python is an interpreted language. It may be a pain to learn, and to use at times, but you have the ability to squeeze out every last drop of performance power. There are a combination of reasons why C++ is faster, but mainly it has to do with memory layout, which you can control ostensibly in C++. Memory layout is important for CPU cache, and CPU cache boosts performance.
Game design, server applications, and most mobile apps rely on speed, so compromising performance isn’t an option. Virtual reality, which must use sixty frames per second to create the illusion of reality, does and will likely continue to make use of C++. Even Photoshop and Google searches still run on C++. It’s still everywhere because it has yet to be matched in speed.
Functionality & Safety
You may not write everything in C++, but it’s still the best (and sort of only) option for operating systems and drivers. Obviously the speed implications apply here to the OS & device drivers, but another factor to consider is that C++ allows users to write less code with more safety. You end up with less code because you can fix a bug in one place and reuse it many times. Express an algorithm once, and you’ll express yourself in far less code than most languages. Needless to say, this only works when C++ is used correctly.
Using the templates feature, developers are able to minimize the code by reusing common parts. With no ugly hacks here, a strict type system enables the compiler to check writing at all times. Best of all, there’s no runtime impact when using C++ features. Generally when C++ is done right, it is less prone to errors and requires less effort to maintain.
C++ supports and enforces object-oriented patterns. When you’re able to implement object oriented code, it is easier to get right and easier to read. As we mentioned earlier, Stroustrup says C++ makes it harder to shoot yourself in the foot than with C. This is because you can’t accidentally call a routine from another module with the wrong type/number of arguments. Even with a file out of date, you won’t accidentally call a routine.
C++ also provides a rich library which can be made exceptionally easy to use, and when designing a data type, you’re able to specify which operations functions are provided.
C++ is everywhere — many of the applications that run on Windows and Linux are written in it, not to mention that most of the gaming industry depends on C++. It;s doubtful that any other languages will be a perfect fit for that entire industry any time soon. Open source uses C++, mostly by way of the Microsoft C++ compiler. Many similar programs won’t match the performance of C++, but in specific cases they are ‘good enough’ and generally easier to learn. No language is the be-all-end-all, but we think we can rest easy knowing that C++ will always be around, despite the newer, sleeker languages emerging. Developers will continue to hate on it because it’s bloated, and difficult to learn, but in reality, it’s functional and fast.