March 22, 2020

What happens since the 1990s with the C language?`

Around the year 1990 was a major milestone in computer programming. Because in this year, two important programming languages were available at the same time. The well known C language plus the newly developed C++ language. In the year 1990 both larger compiler suites from Borland and Microsoft has declared C++ as the new major language.

From today's perspective it's hard to explain why this event took place. Since the year 1990, the well known C Language is no longer relevant for computer education but was replaced with C++, Java and C#. The interesting fact is, that around the year 1990 some tutorials were published how to combine object oriented programming with a c compiler. Some libraries were written to extend the C standard with classes, but in the tutorials it was also explained how to combine normal C structs with c functions into objects.

The attempt of combining the well known C language with object oriented design technique was never very popular in the literature. In the reality, which means in the written code, it was very popular. Nearly all serious C libraries are using object oriented methods in combination with an ANSI C coding style. But let us listen what the advocates of C++ and Java are explaining in their books. The main idea was, that object oriented programming makes only sense if an object oriented language is used. The C language doesn't contains of objects and inheritance, so it's logical to invent a new programming language, which was C++ in the year 1990 and Java in the late 1990s.

The interesting situation is, that C++ never was popular for expert programmers. Linus Torvalds doesn't like C++, and he is not the only one. C++ was only popular for newbies who doesn't know anything about programming. They dreamed of writing larger projects with the object oriented C++ style. Some attempts were made, but such projects are not very popular for productive machines.

The reason is simple: The c language can be used by expert programmers similar to the C++ language for realizing larger projects. The programmer is dividing the task into modules, uses structs and pointers everywhere and doesn't miss C++ classes. The advantage of C is, that the program can be compiled for embedded systems and the C compiler is easier to maintain than a C++ compiler.

The question is not why the Linux kernel, systemd and the gtk+ system was written in C, the question is why is C++ teached in the university and has become so popular at Stackoverflow? The main problem which is solved by Stackoverflow and acedemic programming courses is not write production ready code, but the objective is to explain to the newbies what programming is about. C++ and other OOP language can be interpreted as a learning language. They were designed for educational purposes. The idea is, that the student can understand with C++ easier what a class is. The unsolved question is, what the student should do with his C++ knowledge if real projects are written entirely in ANSI C and will do for the next 30 years?

Somebody may argue, that knowledge about object oriented programming can be utilized for programming in any language. But can the C++ knowledge be used to create ANSI C programs as well? No it can't, because this is not described in the literature. I have found only a single book which explains how to program in C with the OOP technique, plus some smaller discussion threads in Stackoverflow. That means, according to the literature a programmer has to stay either in the C++ / Java language family, or he has to program with a procedural technique in C which makes it impossible to create larger projects.

But, if no book is available how to use OOP knowledge for writing C code, the normal student isn't able to do so in reality. That means, C++ knowledge isn't teached to use it for writing better C programs, but the literature doesn't make sense at all.

It's some kind of paradox situation, that C programmers who are familiar with object oriented programmer never write a book about the topic, while teachers who are familiar with OOP programming are writing books about Java, but not about the C language. The result is a gap, between theoretical education and practical software development. C programmers and C++ programmers doesn't talk to each other.

The exact year can be traced back in time. It was in the year 1990. In this time only the c language was available, and C++ was not used in mainstream computing. Since the 1990 it was discussed in the literature how to create larger software projects with the help of Object oriented programming. Newly languages like Borland delphi were developed for this purpose. And even today, the question is open which programming language is the best.

The rosettacode website collects programming problems. There is a section available in which the different programming languages should create a class. The interesting point is, that even non OOP languages like C and Forth are asked in doing so. https://rosettacode.org/wiki/Classes#C The example code for C shows very well how expert C programmers are creating a class in their language. At first a struct is created. Instead of putting the struct to the stack, a pointer to the struct is created and the malloc command is used. Then a constructor and a destructor function allows to create and destroy the class. What is interesting to is the naming convention. The function have the class name in the beginning and then follows the method name: MyClass_delete.

Creating single inheritance with the c syntax is possible but a bit more complicated.