When and Why You Should Use C++

Now in its 25th year, C++ sits a little awkwardly in the modern world. It grew enormously in the late 80s and early 90s, even overcoming the Department of Defense’s 1987 “Only Ada code to be used” mandate in 1997. But with the arrival of Java in the last years of the century, things became less certain and C++ looked to be becoming a legacy language like Delphi or Visual Basic.

Since .NET appeared in 2000, Microsoft has pushed two enhanced versions of C++ onto it but neither version fared well. First was Managed C++, which was replaced by C++/CLI.

Bjarne StroustrupSince C++ 11 was standardized and Windows 8 has C++ as one of its four development languages, things are maybe looking a bit brighter, but who actually uses it?

Bjarne Stroustrup, the creator of C++, keeps a large list of applications written in it. Big names there include Adobe and Microsoft with most of their products, large chunks of Mac OS/X, the Gnu Compiler Collection GCC, MySQL and MongoDB databases, and many many games.

What about Linux?

Linus Torvalds is a C programmer and not overly fond of C++, to put it mildly. “C++ is a horrible language,” starts a reply of his to someone who asked why Git is written in C not C++. Many well-known Linux programs are written in C — not C++ — such as Apache and Nginx webservers.

Some projects are developed in both C++ and C and often other programming languages as well. An interesting paper was published looking at how the choice of programming language impacts software quality and developer productivity. It used four projects (Firefox, Blender, VLC and MySQL) that were made up of both C and C++. The conclusions are unequivocal: “Our analyses demonstrate that applications that start with C as the primary language are shifting their code base to C++, and that C++ code is less complex, less prone to errors and requires less effort to maintain.”

The decision to use C or C++ depends on many factors, of which age is probably the most important. For very low level or embedded programs, C comes with less overhead. But for any program that does major text processing or has a more complex data model, the benefits of C++ should not be ignored.

What About games?

In the game engines listed on GpWiki, it’s fair to say that the bulk — about 90 percent, use C++. Though C was favored in the past for game development — until the mid-1990s, C++ offers greater advantages for the complexities of 3D games, resource management and sophisticated multiplayer for networking.

aaa game

High energy physics uses C++. ROOT, a framework for data processing that was created at CERN, is employed in applications that are used by thousands of physicists each day. ROOT simplifies the tasks of storing large amounts of data, retrieving, processing and then visualizing it. It includes 1,200 classes organized in 60 frameworks.

But What about C++ in Windows 8?

It’s been over a year since Microsoft released any videos on its Channel 9 website showing how to develop Windows Store (aka Metro Style) apps with C++, and searching on the Web doesn’t show that much interest in it. My guess is if you want to program in C++ on Windows 8, you’ll most likely be creating desktop apps, just like you did in Windows XP, Vista and 7.

Apart from Metro not being all that popular with users, to develop for it you need to know XAML, the declarative language developed by Microsoft for use in WPF and Silverlight, based on XML. XAML has quite a learning curve in C#. For most C++ developers, I think it is too much to learn, unless your employer is happy to fund your attendance at week-long training courses.

At times I really do wonder about Microsoft’s long term development strategy with regard to C++. It was just 20 years ago, in February 1993, when Visual C++ 1.0 (16-bit) was released. The Visual Studio IDE is highly regarded by developers and yet Microsoft sometimes seems a bit embarrassed by C++ still being on the scene.

Microsoft isn’t the only C++ compiler provider for Windows. The free GNU Compiler Collection (GCC) and the more modern open source Clang and LLVM are also available on Windows, as well as Mac and Linux.

Tablets and Smartphones

One area that lacks C++ is mobile computing. iPhone is coded in Objective-C, Android in Java and Windows Phone in C#. You could use C++ for iOS development, or even Objective-C++, but you still have to use Objective-C for interacting with iOS. There have been attempts to develop for iOS in C++ — DragonFire SDK springs to mind — but they’re the exceptions.

Conclusion

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++. I doubt any other language will ever be a good fit in that domain.

The world of open source uses C++ extensively and thanks to the free Microsoft C++ Compiler, Windows is considered a viable platform. But while languages such as Python don’t match it for performance, but they are good enough and far easier to learn.

Comments

  1. BY mark says:

    “C++ code is less complex” [than C]. I guess it depends how you define ‘complex’. I am not convinced that their metrics correctly rate the essential complexity of a program. In any case I am encouraged that research is finally being done on language productivity and quality. The better language should also be more readable and maintainable. But is C++ better than Java?
    Now if English could be less complex: “But while languages such as Python don’t match it for performance, but they are good enough and far easier to learn.” I haven’t seen a sentence with two ‘but’s before. Not sure what that was supposed to mean exactly.

  2. BY D-Coder says:

    C sucks, but C++ sucks++.

Post a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>