What is the worst programming language?

What is the worst programming language?

C++. For a very simple reason. I’ve been using it for 25 years, I’ve taught it, I enjoy it and I’ve done my most significant projects with it. Yet even today, it is impossible for me, and it is impossible even for an expert, to write a large project without encountering a memory segmentation error.

That says it all.

To understand the ins and outs in more detail, a few explanations:

C++ is a weak typing language. Anything can be typed into anything. The specification is full of implicit transtyping rules inherited from C that make it possible to miss the type actually stored and manipulated under the hood when reading the code. More generally, the compiler offers no guarantee on the actual type of what is being manipulated because of all this permissiveness. It’s the same thing in Assembler, but at least that’s its role and it’s not a language disguised as a high level language.

Even with a thorough knowledge of pointers, reference semantics, and even with maximum use of the STL rather than your own manual memory allocation system, and even though you are aware of this trap, you will definitely make pointer invalidation errors, keeping a pointer to an STL entry and doing push_back on your vector for example. This is human. It follows intrinsically from this low-level/high-level potpourri. The compiler and the language specification do nothing for you. Each of these errors will eat up an average of one day of debugging (or more) and each time you will curse the absurdity of working on a language that silently leaves you with your nose in this kind of stupidity. There are only external tools like Valgrind to save you from these traps. Besides, it is impossible to do a proper project in C++ without using a memchecker.

I still feel that a significant part of the language specification escapes me even after 25 years, and for good reason. The C++ specification is plethoric and sprawling, and recent developments have only exacerbated this fact. There are 120 ways to do the same thing. Template metaprogramming. Variadic templates. Move constructors. Multiple inheritance. All these concepts take several years to understand and really master for a real benefit only on very specific types of projects but are unlikely to be profitable in the lifetime of an average programmer. They only add to the general insecurity that will lead you to low-level errors. Worse, to maximize your chances of writing usable and correct code, you are even better off sticking to a tagged subset of the specification, which is what people actually do in practice. You know there is a language definition problem when you have to rely on the programmer’s self-discipline to voluntarily ignore a whole part of the specification.

If the question was: is C++ useful? I would have answered yes, for specific projects that are close to the machine and the system, or that require very fast operations on irregular data structures, not vectorizable in a more advanced language. I continue to use it in these cases where the benefit of having a higher level layer on a low level base is well identified and makes it profitable despite its weaknesses.

But from a formal computer science point of view, and from the desirable characteristics of a language, rigor, parsimony, clarity of specification, verifiability, C++ is one of the worst languages out there, especially for undertaking a large general purpose project. It is a low-level optimization language that people have mistakenly hijacked for general-purpose projects because of some of its high-level language mimicking characteristics – and because it was the best choice at the time. Today there are many languages that do it better, just as fast or almost as fast, in fewer lines of code and with much less development time and cost.