Tuesday, May 14, 2024

C++ standardization, a huge blunder

 In 1996, the standardization committee for C++ adopted a weak implementation as a standard. They simply accepted everything the implementer suggested. Ever since, for almost 30 years now, they have been adding minor, rather useless fixes. Here I will mention some of the issues that most likely will never be fixed, due to the implantation weaknesses.

I assume the reader has already read: invariant , resumption , template and namespace

The concept of exception was formalized long before C++. So, why did the committee even consider the so-called object-oriented exception mechanism. They soon realized there was no need to throw exception objects and did a minor fix, allowing numbers to be thrown as exception. That was all they could do for what they had accepted as standard.

What is the use of throwing exceptions when all you can do is to terminate, or just ignore the exception? The only defense for use of C++ exception is that it is better than using return codes! Now do a search on "C++ Exception" and you will find a lot of reasons to avoid using it.

The mechanism is so rudimentary that the compiler cannot throw exceptions that can be caught, for instance as needed for invariant among other things. Indeed, C++ exception is repugnant to the very notion of exception.

So, what are the advantages of C++ over C? One would say: overloading, namespace, templates and exceptions.

Now, overloading can easily be added to C. But that would result in a disaster when linking with previously compiled C programs. So, we leave it as a C++ advantage. The remaining advantages are all rudimentary and even useless, as discussed in the links provided above.

The committee did not even bother to discuss casting. They simply accepted an array of casting like const-cast instead of requiring one single cast for all cases, as is done in Z++ .

The blunder of C++ reminds me of "King's new clothes". The King is naked yet everyone is intimidated to declare that he is wearing fine clothes.

In my opinion, the committee should provide a new standard that requires the missing functionalities. Most, if not all, of the changes will be in the implementation rather than the syntax. The longer this blunder lingers on the harder to recover.

I would like to mention that C++ is only an object-oriented extension of C. For instance, for a function returning a numeric value, one cannot do "f()++", as is done in Z++. Z++ is an object-oriented language that links with previously compiled programs in C and C++. In other words, Z++ is not an extension of C++, rather C++ is just a ragtag rudimentary implementation of a subset of Z++

When building in debug mode, Z++ Compiler reports all unhandled exceptions. When the execution of a program ends in debug-mode, all memory leaks are reported. Furthermore, Z++ threads are platform-independent.

Dr. Z. May 2024.

Labels: , , , ,