When to use the C++ language

There are several opinions about the application field of the C++ language.

Some people (for example Linus Torvalds) consider it a useless complication over C language, and a possible and probable source of inefficiency. They think that if you need utmost performance, you should use C language or FORTRAN language; if you need high level abstractions and higher programmer productivity, you should use a higher level programming language, like Java, C#, Python, Ruby, or even shell scripts. And if you need both you should use both, i.e. some modules in C language, where you need performance, and some modules in a higher level language, where you need flexibility or productivity.

Other people consider C++ a beautiful language, potentially appropriate for every kind of software. It just lacks the same standard libraries and tools available in higher level languages. They would use C++ even for server-side Web programming, if there were a Web programming framework as good as the the ones available for higher level languages. Therefore these people often ask to the C++ standard committee to add higher-level features to the language standard.

I am in a middle position. I think that the C++ language does have a role in software programming, and that it is going to gradually replace the role of the C language, but that overall it is and it should lose ground as application programming language, in favor of higher level programming languages.

C language still has and will have a role for small systems, i.e. software with less than 20,000 uncommented source lines of code, like (some) device drivers, (some) operating system modules, and embedded application software on 8-bit or 16-bit systems. Now and also in the near future, it would be unreasonable to program the controller of a washing machine in C++, because C is more appropriate for such a simple system, but I think that C++ is quite appropriate to program the device driver of a printer or of a graphics adapters for a 32-bit or 64-bit operating system. C language would be inappropriate, as they are rather complex to quite complex systems, that should take advantage of C++ abstraction features. And Java or C# would be inappropriate too, because device drivers need to interface well with the operating system and the application software written in machine language, and because these device drivers need to be quite efficient in some spots.

For any kind of middle to large software product is unreasonable to restrict to the C language the allowed set of programming languages. This is because as long as the software package grows bigger, more and more parts of it look similar to each other. They differ only in details, that can be abstracted away using the abstraction features of C++, i.e. classes and templates. Instead, using C language the programmer is forced to duplicate the feature, so producing a bigger source. Therefore, I think that the primary reason to use C++ instead of C is software reuse. Such reason comes into play only when the software system is big enough. With a 2,000 lines system is hardly perceivable, with 20,000, if properly designed, it is quite evident, and it is a huge advantage in a system that, if written in C language, has more than 200,000 lines of uncommented source code.

But even C++ powerful abstractions don’t make it a very high-level language. It still has low-level features that must be known and handled by the programmers. It is still slow to compile, and the future standard will make it even slower, it is somewhat harder to test and debug. And actually it lacks really high-level features, frameworks and libraries.

Actually C++ is a systems programming language, not an applications programming language, and it is going to remain so. Even the new standard is going to add low-level features, but almost no high level features. Few high level frameworks are in development for C++ programmers. Therefore, don’t think to use it for your next application software.

An additional aspect of C++ language is that it is quite difficult to understand well and use properly. Actually I think it is by far the most complex programming language. Therefore, it is not appropriate for people that has just one or two years of formal education in computing. I think it is a language for programming teams where everyone has studied computer science or computer technology for at least three years, and at least one of the team members has studied computing for at least five years.

Some applications require anyway the the team of developers is highly skilled. For example, no government would accept that a band of high schoolers would be in charge of its rocket program; and no enterprise would give to accountant-programmers the task of developing its strategic information system. For large business-critical systems, at least the project leader should be an experienced software engineer. If the team is anyway composed by people that can manage C++ well, then C++ is a good choice. Otherwise, it is better to stick to C (for systems programming) and to higher-level languages (for application software).


About Carlo Milanesi

I am a software developer in Italy. I have develop financial, engineering and commercial software using many programming languages, mainly C, C++, Visual Basic, Java, and C#. Now I am interested in Rust and TypeScript.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s