The C language is the big elephant in the room. Everybody is writing C code but nobody is talking about. Let us change the rules of the game and try to overcome outdated C syntax and use a different kind of programming language for writing operating systems kernel, programming embedded applications, create graphics library and write object oriented applications.
Possible candidates for replacing C code are Java, C# and especially C++. A short look into a Linux distribution have shown that the C++ language isn't used very often https://dwheeler.com/sloc/redhat71-v1/redhat71sloc.1.00.html Only 15% were written in C++. And the assumption is high, that especially programcode which is not installed on real computers, for example KDE was written in C++, so that on running machines the ratio is worse for C++. But why exactly was C++ never able to replace C? The first version of C++ was published in the mid 1980s. Since then there was enough time to rewrite and recompile all the code. But this project was never started. All the newly written code is using the normal C language with minor modifications for example C99 instead of C89.
The paradox situation is, that C++ has replaced C in one category: the amount of books written about Object oriented programming in C++ is much higher than for C. The only book ever written about OOP in C was published in 1993 “Axel-Tobias Schreiner: Object-Oriented Programming With ANSI-C, 1993”. Apart from the book, there are two! (not more) Dr.Dobbs articles in the 1990s which are explaining how to program classes in C, and in some stackoverflow postings the topic is also discussed.
In contrast, the amount of papers, journals and books who are explaining how to program Object-oriented in the C++ language is larger than 20k overall. Additionally, nearly all university in the world is teaching how to program in C++ object oriented software. It seems, that the problem has to do with the difference between written code in the wild (mostly C) and computer classes in the university which are focussed on C++.
From a technical perspective it's not very complicated to create object oriented code in C. All what is needed are some function pointers, some structs and a bit discpline of the programmer. A look into existing software project at github will show, that most C programmers are experts for object oriented code. They are managing complexity in the written code by combining structs with functions in the same module. And they have no need for other programming languages like C++, Java or C#.
The only user group who is using dedicated OOP languages like Python or Java are newbies who are not familar with computer programming. They are reading all the C++ books in the hope to learn how to write object oriented code. This paradox situation can be overcome easily. What is needed are books with the title “OOP in C”. SImilar to to the mentioned book from AT Schreiner but published in the year 2020. Such books aren't available yet. And exactly of this reason, the newbies won't learn C at all. The typical newbie has understood that object oriented programming is a here to stay. Because it simplifies the programming of GUI Applications and games very well. And because the newbie has never programmed in any language at all, he decides for a typical OOP language in the hope this is the future. For example he is learning Java or C++.
The consequence is, that the newbie will waste his time. Because C++ won't never replace C code. The C language is way to powerful and provides too much object oriented features that expert programmer will switch to a different kind of language in the future. Basically spoken the existing software projects written in C for example the Linux kernel, the Windows kernel or a larger game can be translated with an UML generator into a nice looking object-oriented diagram. That means, there are objects (aka structs) and functions which have access to these objects. It's not possible to reprogram the Linux kernel in C++ because it is using object-orientation already.
March 22, 2020
The biggest strength of Python is it's slowness
If a newbie tries out the Python interpreter for the first time, he will notice that the code runs horrible slow. Compared to the compiled C language a python program is around 20x slower which makes the language unusable for practical application. And exactly for this reason Python is a great language. Because it draws a line between teaching and productive scenario.
From a technical point of view, it's not very hard to make Python faster. One option is to optimize the python interpreter or develop a just in time compiler. The resulting language would have much in common with node.js, java and C++. It will become a language which is used for teaching programming and for programming real systems at the same time.
The good news is, that this is not the goal of Python. It's a teaching language. It allows to learn programming and create prototypes but the Python ecosystem prevents that Python code gets executed in real operating systems. Let us compare Python with other object oriented languages:
Java, C++, C#, node.js and ruby have in common that they are used for teaching programming to the newbies. Java for example is widely used in an academic context. It explains very well what object oriented programming is. The fast executation speed is that main difference of Java to Python. A fast execution speed implies that the language can be used outside a learning environment as an alternative to C.
Is Java able to replace C programs? No it doesn't. C is the number one language in the wild. It's used for creating operating systems, libraries, AAA game and object-oriented desktop application. The only problem with C is, that it's not used for teaching programming, because it has no explicit classes. And exactly this gap was filled by Python. Python is the missing part to train the newbies. If somebody has understand who to write Python programs he can try to use C structs and C pointers for doing the same for writing production ready code.
Python -> C -> Forth
Python is the number one language for creating prototypes and learn to program. The entry barrier for creating python scripts is very low. Even non programmer can create a hello world application within minutes. The C language is the number language for creating software in the wild. Most (>80%) softwareprojects in the reality are realized in C and it's superior to C++, Java and C#. C is the dominant language for the x86 PC architecture and any sort of application can be created. The Forth language is a special case, it's a language for programmers who are already with C and who are searching for a faster alternative. The main difference is that Forth will run on non-x86 systems which can be designed in FPGAs from scratch. Rewritting existing C code into Forth is good startin point to get familiar with stack-based computing.
Educational programming languages
Recent object oriented languages like Java and C# are teached very often in computer courses as an example for object oriented programming. The audience are newbies and non-programmers who are interested in learning the language from scratch. Python can be teached also in such courses. The main difference between Python and Java is, that Python programmers are aware that their language can't be used for practical applications. If they are writing a small prime number generator with a for loop they will recognize very soon, that the language is way to slow for practical applications. Python is an educational only language. That menas, if somebody like to program software in the wild he won't use Python.
In contrast the educational situation for Java is different. Java is used in introduction courses and the same Java language has become popular in writing real applications. Similar to C++, Java is used in an academic context and for practical applications at the same time. The problem is that programming experts are using C since 30 years and they are not planning to rewrite the code in any other language. That means, all the newly written Java, C++, Python and Ruby libraries are useless. Real operating systems are equipped with normal C libraries which are providing the maximum performance and are maintained by experts and any other language is critized as a toy language. In the case of Python, the Python community won't argue against it. They know, that Python can't replace a C library.
The situation in the programming world is, that there is the expert language C on the one hand which is used for creating important software, productive software and for large scale projects, and all the other languages were developed for niche problems, for academic purposes or as an alternative to C. A relative new understanding of computer programming is, that the C language is especially recommended for object oriented programming. This is a bit surprising, because C++, Java and C# were developed as a dedicated OOP language, but they have failed to replace C in this domain.
What the alternative languages over C have in common is, that they are widespread used in an educational setting. Many books were written about it and they are used in computer courses at the university. In contrast, the C language is never teached anyware and modern literature isn't available. The assumption of the newbies is, that the C language is outdated and is replaced by Java, C++ and other languages. This thesis isn't backuped by the percpetion in the reality. If software projects becomes larger, and are realzed with modern OOP technique it's in all cases a C only programming project. This is not wishful thinking but can be determined by take a look into the sourcecode of the software.
Why is C so popular? The reason is, that software engineering can't be separated from low level programming. If somebody likes to write a high level application he will need an operating system and existing libraries for doing so. To get access to the existing sourcecode, an API is needed and every API is working with pointers. Even higher languages like C++ and Java are using pointers all the time, and before the newbie is able to program in Java he has to know what pointers are. That means, it's not possible to ignore the topic at all.
And if C supports pointers, structs and modules out of the box, the programmer has no need to use a different langauge than the existing one. That means, especially newly written code is created in C. The prediction is, that this will be the same in 10 years from now, except somebody invents a language which can replace C.
The only area in which C can be ignored is for academic reasons and for software prototyping. If the idea is to explain in general what object oriented programming is, how an algorithm is working in theory and how to create an UML diagram, the C language isn't the best choice in doing so. A java based UML Generator is the prefered choice for software engineering teaching, while algorithm can be explained with Python very well. It makes no sense to print a screenshot of C sourcecode in a textbook because the syntax is hard to understand. C is way to low level and provides too much details of the underlying CPU.
From a technical point of view, it's not very hard to make Python faster. One option is to optimize the python interpreter or develop a just in time compiler. The resulting language would have much in common with node.js, java and C++. It will become a language which is used for teaching programming and for programming real systems at the same time.
The good news is, that this is not the goal of Python. It's a teaching language. It allows to learn programming and create prototypes but the Python ecosystem prevents that Python code gets executed in real operating systems. Let us compare Python with other object oriented languages:
Java, C++, C#, node.js and ruby have in common that they are used for teaching programming to the newbies. Java for example is widely used in an academic context. It explains very well what object oriented programming is. The fast executation speed is that main difference of Java to Python. A fast execution speed implies that the language can be used outside a learning environment as an alternative to C.
Is Java able to replace C programs? No it doesn't. C is the number one language in the wild. It's used for creating operating systems, libraries, AAA game and object-oriented desktop application. The only problem with C is, that it's not used for teaching programming, because it has no explicit classes. And exactly this gap was filled by Python. Python is the missing part to train the newbies. If somebody has understand who to write Python programs he can try to use C structs and C pointers for doing the same for writing production ready code.
Python -> C -> Forth
Python is the number one language for creating prototypes and learn to program. The entry barrier for creating python scripts is very low. Even non programmer can create a hello world application within minutes. The C language is the number language for creating software in the wild. Most (>80%) softwareprojects in the reality are realized in C and it's superior to C++, Java and C#. C is the dominant language for the x86 PC architecture and any sort of application can be created. The Forth language is a special case, it's a language for programmers who are already with C and who are searching for a faster alternative. The main difference is that Forth will run on non-x86 systems which can be designed in FPGAs from scratch. Rewritting existing C code into Forth is good startin point to get familiar with stack-based computing.
Educational programming languages
Recent object oriented languages like Java and C# are teached very often in computer courses as an example for object oriented programming. The audience are newbies and non-programmers who are interested in learning the language from scratch. Python can be teached also in such courses. The main difference between Python and Java is, that Python programmers are aware that their language can't be used for practical applications. If they are writing a small prime number generator with a for loop they will recognize very soon, that the language is way to slow for practical applications. Python is an educational only language. That menas, if somebody like to program software in the wild he won't use Python.
In contrast the educational situation for Java is different. Java is used in introduction courses and the same Java language has become popular in writing real applications. Similar to C++, Java is used in an academic context and for practical applications at the same time. The problem is that programming experts are using C since 30 years and they are not planning to rewrite the code in any other language. That means, all the newly written Java, C++, Python and Ruby libraries are useless. Real operating systems are equipped with normal C libraries which are providing the maximum performance and are maintained by experts and any other language is critized as a toy language. In the case of Python, the Python community won't argue against it. They know, that Python can't replace a C library.
The situation in the programming world is, that there is the expert language C on the one hand which is used for creating important software, productive software and for large scale projects, and all the other languages were developed for niche problems, for academic purposes or as an alternative to C. A relative new understanding of computer programming is, that the C language is especially recommended for object oriented programming. This is a bit surprising, because C++, Java and C# were developed as a dedicated OOP language, but they have failed to replace C in this domain.
What the alternative languages over C have in common is, that they are widespread used in an educational setting. Many books were written about it and they are used in computer courses at the university. In contrast, the C language is never teached anyware and modern literature isn't available. The assumption of the newbies is, that the C language is outdated and is replaced by Java, C++ and other languages. This thesis isn't backuped by the percpetion in the reality. If software projects becomes larger, and are realzed with modern OOP technique it's in all cases a C only programming project. This is not wishful thinking but can be determined by take a look into the sourcecode of the software.
Why is C so popular? The reason is, that software engineering can't be separated from low level programming. If somebody likes to write a high level application he will need an operating system and existing libraries for doing so. To get access to the existing sourcecode, an API is needed and every API is working with pointers. Even higher languages like C++ and Java are using pointers all the time, and before the newbie is able to program in Java he has to know what pointers are. That means, it's not possible to ignore the topic at all.
And if C supports pointers, structs and modules out of the box, the programmer has no need to use a different langauge than the existing one. That means, especially newly written code is created in C. The prediction is, that this will be the same in 10 years from now, except somebody invents a language which can replace C.
The only area in which C can be ignored is for academic reasons and for software prototyping. If the idea is to explain in general what object oriented programming is, how an algorithm is working in theory and how to create an UML diagram, the C language isn't the best choice in doing so. A java based UML Generator is the prefered choice for software engineering teaching, while algorithm can be explained with Python very well. It makes no sense to print a screenshot of C sourcecode in a textbook because the syntax is hard to understand. C is way to low level and provides too much details of the underlying CPU.
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.
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.
The upraising of the C++ language
The C++ language is a widely discussed subject among computer programmers. Thousands of books and lots of stackoverflow entries are written about the language. At the same time, C++ is quite difficult to learn for newbies and they are preferring more clean designed languages like C# or Java. The reason why C++ is perceived as complicated has to do with a certain sort of tutorials how to program. In case of C/C++ there is a gap what programmers in the reality are doing and how they have documented their sourcecode. To understand the gap we must go back into the early 1990s.
In the early 1990s there was a big transition from older C compilers to modern C++ compilers. Or to be more specific, the books and published literature about C++ has increased while the reports about C programming has declined. Let us analyze the typical C programming book. What is written in the book are the C language standards and what is missing is a tutorial how to use the C language for creating object oriented code. The interesting is, that programmers in the reality are knowing very well how to create OOP with C. I have searched a bit in the sourcecode at github. Most of the C projects, especially games and C libraries are using a certain C programming style which was described briefly by https://softwareengineering.stackexchange.com/questions/308640/is-it-bad-to-write-object-oriented-c
The idea is to put a struct plus the function into the same file and call it from the outside, very similar of creating classes in C++. This programming style is seldom described in the manuals because it combines the classical C language with modern OOP design. But it's used in real github projects and perhaps most commercial C projects are working with the same style. That means, in the reality all the programmers are familiar with creating OOP software in C, but they haven't it documented in books.
What is described in the book is Object oriented programming with C++. This is described everywhere. The paradox situation is, that in reality nobody is using C++, especially not for serious projects. The amount of videogames written in academic C++ is low, the same is true for library of operating systems or serious applications created by experts. And exactly this mismatch explains why newbies struggle in learning C++ at all. They are reading the C++ tutorials in the hope to learn how to program modern C++. But they can't use this knowledge in real projects, because they are using the wrong programming language.
The reason why C++ was invented is to replace the C language. In reality C++ has failed in doing so. If the normal C language provides enough features to program semi-object oriented code with the help of structs, modules and pointers why should somebody switch to C++? Right, and because of this question around 65% of the code in the Debian Linux distribution was written in C and the prediction is, that the ratio wlll be constant for the next 20 years. Basically spoken, if a newbie wants to learn a modern objected oriented language which is used in the reality he should learn C and search for tutorials which are explaining how to combine C with object oriented programming style.
The gap between C programs in reality and manuals about how to create C programs is obvious. The average C programmer knows very well what Object oriented programing is. The C sourcecode is formatted like a C++ program which includes classes. So the assumption is, that the programmer has a deep knowledge of object oriented design. At the same time this knowledge isn't made explicit in the literature. The amount of tutorials who are explaining who to program OOP in C is very small. It's some kind of implicit knowledge how to combine the C language with object oriented features.
It's easy to predict what the future will bring. Instead of inventing better C++ programming language, in the future better tutorials were written how to use the well working C language for creating object oriented code. This will allow newbies to reproduce the existing C codebase and copy the programming style of existing C programmers.
Game engines
According to an often repeated story, the C++ language has become the standard language for game development. All the major game engines are written in C++. At least, this is told to the newbies. But let us take a deeper look into the problem. At first, the sourcecode of all the proprietary game engines is not available. In thoery it can be written in plain C and what is told to the public is the opposite. Some of the game engines have published the sourcecode, and indeed it's written in C++ syntax. A normal gcc compiler can't convert the code into a binary file. But is the code really written in C++?
All the so called C++ sourcecode contains of cpp files plus header files. It's interesting that all the code contains of pointers to structs. The reason is, that pointers combined with header files are the only option to realize object oriented paradigm in C++. Let us make a small thought experiment. What will happen if an expert programmer takes the existing C++ code and rewrites it in plain C code? That means, he replaces the class keyword with the struct keyword and adjusts some minor formatting issues. The resulting plain C sourcecode will look nearly the same like the original C++ code.
This thought experiment shows, that the so called C++ sourcecode is in reality normal C code. It contains of header files, is using pointers in every function and can be realized with a normal C compiler easily. So why it is called a C++ project? The funny thing is, that the programmers doesn't call it a C++ project. They know that the difference between C and C++ is small. They are calling it a C/C++ program and they are using the C++ syntax without a purpose.
In the early 1990s there was a big transition from older C compilers to modern C++ compilers. Or to be more specific, the books and published literature about C++ has increased while the reports about C programming has declined. Let us analyze the typical C programming book. What is written in the book are the C language standards and what is missing is a tutorial how to use the C language for creating object oriented code. The interesting is, that programmers in the reality are knowing very well how to create OOP with C. I have searched a bit in the sourcecode at github. Most of the C projects, especially games and C libraries are using a certain C programming style which was described briefly by https://softwareengineering.stackexchange.com/questions/308640/is-it-bad-to-write-object-oriented-c
The idea is to put a struct plus the function into the same file and call it from the outside, very similar of creating classes in C++. This programming style is seldom described in the manuals because it combines the classical C language with modern OOP design. But it's used in real github projects and perhaps most commercial C projects are working with the same style. That means, in the reality all the programmers are familiar with creating OOP software in C, but they haven't it documented in books.
What is described in the book is Object oriented programming with C++. This is described everywhere. The paradox situation is, that in reality nobody is using C++, especially not for serious projects. The amount of videogames written in academic C++ is low, the same is true for library of operating systems or serious applications created by experts. And exactly this mismatch explains why newbies struggle in learning C++ at all. They are reading the C++ tutorials in the hope to learn how to program modern C++. But they can't use this knowledge in real projects, because they are using the wrong programming language.
The reason why C++ was invented is to replace the C language. In reality C++ has failed in doing so. If the normal C language provides enough features to program semi-object oriented code with the help of structs, modules and pointers why should somebody switch to C++? Right, and because of this question around 65% of the code in the Debian Linux distribution was written in C and the prediction is, that the ratio wlll be constant for the next 20 years. Basically spoken, if a newbie wants to learn a modern objected oriented language which is used in the reality he should learn C and search for tutorials which are explaining how to combine C with object oriented programming style.
The gap between C programs in reality and manuals about how to create C programs is obvious. The average C programmer knows very well what Object oriented programing is. The C sourcecode is formatted like a C++ program which includes classes. So the assumption is, that the programmer has a deep knowledge of object oriented design. At the same time this knowledge isn't made explicit in the literature. The amount of tutorials who are explaining who to program OOP in C is very small. It's some kind of implicit knowledge how to combine the C language with object oriented features.
It's easy to predict what the future will bring. Instead of inventing better C++ programming language, in the future better tutorials were written how to use the well working C language for creating object oriented code. This will allow newbies to reproduce the existing C codebase and copy the programming style of existing C programmers.
Game engines
According to an often repeated story, the C++ language has become the standard language for game development. All the major game engines are written in C++. At least, this is told to the newbies. But let us take a deeper look into the problem. At first, the sourcecode of all the proprietary game engines is not available. In thoery it can be written in plain C and what is told to the public is the opposite. Some of the game engines have published the sourcecode, and indeed it's written in C++ syntax. A normal gcc compiler can't convert the code into a binary file. But is the code really written in C++?
All the so called C++ sourcecode contains of cpp files plus header files. It's interesting that all the code contains of pointers to structs. The reason is, that pointers combined with header files are the only option to realize object oriented paradigm in C++. Let us make a small thought experiment. What will happen if an expert programmer takes the existing C++ code and rewrites it in plain C code? That means, he replaces the class keyword with the struct keyword and adjusts some minor formatting issues. The resulting plain C sourcecode will look nearly the same like the original C++ code.
This thought experiment shows, that the so called C++ sourcecode is in reality normal C code. It contains of header files, is using pointers in every function and can be realized with a normal C compiler easily. So why it is called a C++ project? The funny thing is, that the programmers doesn't call it a C++ project. They know that the difference between C and C++ is small. They are calling it a C/C++ program and they are using the C++ syntax without a purpose.
March 11, 2020
C++ is obsolete
The major problem with the C++ language is the complicated pointer syntax. In contrast to modern OOP languages like Java and C#, C++ requires pointers at many situations. A look into existing larger C++ programs shows, that pointers are used together with classes very often. Not because the programmer doesn't know how to do it better, but he is using the fast programming technique available. That means, it's not possible to program in C++ in a different way. Even the latest iteration C++20 requires that the programmer prefers “point->x” over “point.x”.
The good news is, that the pointers in C++ are making more sense, if the same technique is realized in plain C. A hello world program which is using OOP plus pointers in the C language is given next:
It looks very similar to a C++ program except that no dedicated class statement was needed. At the same time, the programmer is storing the sourcecode in different files and splits the overall project into smaller programs which makes it easy to maintain the code.
A look into existing C repositories at github will show, that this sort of style is used by most programmers. Sometimes not in this direct clean form because the file length is longer, and more than a single struct is given in the text. But, if the programmer likes he can program in C similar to Python.
The assumption is, that we the C language everything is fine, it's not possible to replace the provided sourcecode with something which has more performance or can be written more elegant. Even if somebody rewrites the code in C# or Python it will look the same. The core idea of Python is:
- put every class in a new file which is less than 100 lines of code
- aggregate classes to more complex classes
- comment the code, create a documentation for the API
This is in short the best practice method to create modern object oriented code. The paradox is, that the old-school C language supports this idea very well. The syntax is a bit different from normal object languages. Because the function is available globally and a method needs a pointer to a struct before the class variable can be edited. But this is only a syntax decision.
What i want to explain is, that modern languages like C++, C#, and Java have struggled in replacing C code with something which can be maintained better. That means, all the projects from the past which were created in plain C but not in C++ are future ready. Nobody will rewrite C code with something which is easier to maintain, because C is the king already.
One important reason to prefer C over C++ is because the pointers in C are making sense. In the sourcecode, the pointer is the only option to copy the struct into a function. The result is, that all the C routines will look the same. It's not possible to write the code different. This is important for newbies which need a clear advice how to create a program.
Sourcecode browser

In the screenshot the geany IDE is shown together with the sourcecode. The frame on the left is very interesting. Geany has parsed all the structs and the functions from the file. If a single file is smaller than 100 lines of code, and if geany shows very well which datatypes and functions are defined in the file, the programmer has everything he needs. It's the same sort of overview provided in object oriented languages like Python or Java.
What exactly was the problem with C, why it's not used anymore? It is used, many thousands of games at github are using the tool. The only thing what is wrong are the programming books about C++, Java and C#. They are explaining to the user, that C is outdated and the user beliefs so.
The good news is, that the pointers in C++ are making more sense, if the same technique is realized in plain C. A hello world program which is using OOP plus pointers in the C language is given next:
// main.c
//------------------------
#include "stdio.h" // wrong brackets
#include "point.c"
int main()
{
printf("main\n");
point_run();
}
// point.c
//------------------------
typedef struct {
int x;
int y;
} Point;
void set(Point* p, int x, int y) {
printf("set\n");
p->x=x;
p->y=y;
};
void show(Point* p) {
printf("show %d %d\n",p->x,p->y);
};
void point_run() {
Point p;
set(&p,10,5);
show(&p);
}
It looks very similar to a C++ program except that no dedicated class statement was needed. At the same time, the programmer is storing the sourcecode in different files and splits the overall project into smaller programs which makes it easy to maintain the code.
A look into existing C repositories at github will show, that this sort of style is used by most programmers. Sometimes not in this direct clean form because the file length is longer, and more than a single struct is given in the text. But, if the programmer likes he can program in C similar to Python.
The assumption is, that we the C language everything is fine, it's not possible to replace the provided sourcecode with something which has more performance or can be written more elegant. Even if somebody rewrites the code in C# or Python it will look the same. The core idea of Python is:
- put every class in a new file which is less than 100 lines of code
- aggregate classes to more complex classes
- comment the code, create a documentation for the API
This is in short the best practice method to create modern object oriented code. The paradox is, that the old-school C language supports this idea very well. The syntax is a bit different from normal object languages. Because the function is available globally and a method needs a pointer to a struct before the class variable can be edited. But this is only a syntax decision.
What i want to explain is, that modern languages like C++, C#, and Java have struggled in replacing C code with something which can be maintained better. That means, all the projects from the past which were created in plain C but not in C++ are future ready. Nobody will rewrite C code with something which is easier to maintain, because C is the king already.
One important reason to prefer C over C++ is because the pointers in C are making sense. In the sourcecode, the pointer is the only option to copy the struct into a function. The result is, that all the C routines will look the same. It's not possible to write the code different. This is important for newbies which need a clear advice how to create a program.
Sourcecode browser

In the screenshot the geany IDE is shown together with the sourcecode. The frame on the left is very interesting. Geany has parsed all the structs and the functions from the file. If a single file is smaller than 100 lines of code, and if geany shows very well which datatypes and functions are defined in the file, the programmer has everything he needs. It's the same sort of overview provided in object oriented languages like Python or Java.
What exactly was the problem with C, why it's not used anymore? It is used, many thousands of games at github are using the tool. The only thing what is wrong are the programming books about C++, Java and C#. They are explaining to the user, that C is outdated and the user beliefs so.
Object oriented programming in C
Instead of using a dedicated OOP language like Python or Java, it's possible to create even in C an object oriented project. Some features are missing but in general it's possible for doing so. The only difference is, that the fucntion call doesn't need the full path to the module, but it can be called direct.
The interesting question is, if such a programming style works for practical application. In the github archive there are many examples for games written not in C++ but in normal C. Many of them are using this style. The subparts of the game are stored in dedicated files which contains of a struct definition for the data and a list of functions for the C code. What these modules are doing is to to call their own functions, similar to the concept of classes in other programming languages.
Understanding the inner working is a bit harder than mastering Python OOP, because in a C project, pointers are needed for everything. But suppose the idea is not to use Python, C++, C# and Java, then this kind of programming style is a here to stay. It allows to write semi-object oriented software which scales very well. It's not a coincidence that most of real programs which are available out of the box in Unix and Linux operating systems were written in the C language but not in Java and not in C++. The reason is, that the advantage of dedicated OOP languages over C is small.
Let us take a closer look into the sourcecode. In the main file, only a simple call to a module is available. All the details of the Point module are hidden in the external file. In the point.c file, the datastructure is stored together with the functions in the same file. If the programmer takes care, that the maximum length of the file remains under 100 lines of code, it's not very complicated to maintain and bugfix the code. If the C code is rewritten in Python or C++ it will look nearly the same. That means, the overall project is divided into classes which are responsible for subparts of the project.
The assumption is, that writing larger projects in C can be realized with the same productivity like in Java or Python. That means, the C programmer won't miss OOP features, because most of them can be replicated with the C language. This makes it hard to convince a C programmer to convert the existing code into a different language. Basically spoken, the C language has a bright future and will be used very often.
Programming language statistics
The well known Tiobe index doesn't reflect programming languages in reality. There is a gap available that in computer education, Java and C++ is very important but in reality nobody is using these languages. A more realistic picture is counting the lines of code, https://www.openhub.net/languages?query=&sort=code
According to the Openhub directory the most used languages in the wild are:
1. C with 9.4 billion Lines of code
2. Javascript 4 billion LoC
3. XML 2.9
4. C++ 2.6
5. Java 2.4
6. HTML 1.4
7. PHP 0.9 billion
8. Go 0.6 billion loc
9. Python 0.7 billion
10. CSS 0.5 billion
In another older statistics, the C language outperforms also C++ easily in amount of written codelines. The sourcecode of the Debian operating system was measured in the year 2005 which contains of 105 million lines of code overall. 65% of them were written in C and only 12% were written in C++.[1]
There are some points against the C language. Most AAA videogames are not writtein pure C but the normal C++ language is used. And many developers are explaining that C is dead and they are prefereing C++ because videogames need object-oriented features. But, a closer look into the C++ sourcecode will show, that nearly all the game engines and the games written on top of the engines are using pointers in the C++ classes. It's not possible to avoid pointers in C++ because this ensures the maximum performance. What the programmers are writing in the code is not C++ but they are programming in C with pointers and using only the class statement and sometimes the templates of the C++ compiler.
Let us make a thought experiment. What will happen, if a larger computergame is reprogrammed in C? THe sourcecode will look nearly the same. That means, lots of pointers are needed to draw the sprites and call foreign modules. The difference between C a program which is using static functions to get access to structs and a C++ program which is using dedicated classes is low.
[1] Amor, Juan José, Gregorio Robles, and Jesus Gonzalez-Barahona. "Measuring woody: The size of debian 3.0." arXiv preprint cs/0506067 (2005).
// file: main.c
// -------------------------------
#include "stdio.h"
#include "point.c"
int main()
{
printf("main\n");
point_show();
}
// file: point.c
// -------------------------------
typedef struct {
int x;
int y;
} Point;
void set(Point* p, int x, int y) {
printf("set\n");
p->x=x;
p->y=y;
};
void show(Point* p) {
printf("show %d %d\n",p->x,p->y);
};
void point_show() {
Point p;
set(&p,10,5);
show(&p);
}
The interesting question is, if such a programming style works for practical application. In the github archive there are many examples for games written not in C++ but in normal C. Many of them are using this style. The subparts of the game are stored in dedicated files which contains of a struct definition for the data and a list of functions for the C code. What these modules are doing is to to call their own functions, similar to the concept of classes in other programming languages.
Understanding the inner working is a bit harder than mastering Python OOP, because in a C project, pointers are needed for everything. But suppose the idea is not to use Python, C++, C# and Java, then this kind of programming style is a here to stay. It allows to write semi-object oriented software which scales very well. It's not a coincidence that most of real programs which are available out of the box in Unix and Linux operating systems were written in the C language but not in Java and not in C++. The reason is, that the advantage of dedicated OOP languages over C is small.
Let us take a closer look into the sourcecode. In the main file, only a simple call to a module is available. All the details of the Point module are hidden in the external file. In the point.c file, the datastructure is stored together with the functions in the same file. If the programmer takes care, that the maximum length of the file remains under 100 lines of code, it's not very complicated to maintain and bugfix the code. If the C code is rewritten in Python or C++ it will look nearly the same. That means, the overall project is divided into classes which are responsible for subparts of the project.
The assumption is, that writing larger projects in C can be realized with the same productivity like in Java or Python. That means, the C programmer won't miss OOP features, because most of them can be replicated with the C language. This makes it hard to convince a C programmer to convert the existing code into a different language. Basically spoken, the C language has a bright future and will be used very often.
Programming language statistics
The well known Tiobe index doesn't reflect programming languages in reality. There is a gap available that in computer education, Java and C++ is very important but in reality nobody is using these languages. A more realistic picture is counting the lines of code, https://www.openhub.net/languages?query=&sort=code
According to the Openhub directory the most used languages in the wild are:
1. C with 9.4 billion Lines of code
2. Javascript 4 billion LoC
3. XML 2.9
4. C++ 2.6
5. Java 2.4
6. HTML 1.4
7. PHP 0.9 billion
8. Go 0.6 billion loc
9. Python 0.7 billion
10. CSS 0.5 billion
In another older statistics, the C language outperforms also C++ easily in amount of written codelines. The sourcecode of the Debian operating system was measured in the year 2005 which contains of 105 million lines of code overall. 65% of them were written in C and only 12% were written in C++.[1]
There are some points against the C language. Most AAA videogames are not writtein pure C but the normal C++ language is used. And many developers are explaining that C is dead and they are prefereing C++ because videogames need object-oriented features. But, a closer look into the C++ sourcecode will show, that nearly all the game engines and the games written on top of the engines are using pointers in the C++ classes. It's not possible to avoid pointers in C++ because this ensures the maximum performance. What the programmers are writing in the code is not C++ but they are programming in C with pointers and using only the class statement and sometimes the templates of the C++ compiler.
Let us make a thought experiment. What will happen, if a larger computergame is reprogrammed in C? THe sourcecode will look nearly the same. That means, lots of pointers are needed to draw the sprites and call foreign modules. The difference between C a program which is using static functions to get access to structs and a C++ program which is using dedicated classes is low.
[1] Amor, Juan José, Gregorio Robles, and Jesus Gonzalez-Barahona. "Measuring woody: The size of debian 3.0." arXiv preprint cs/0506067 (2005).
Understanding pointers and references in C++
The C++ programming language is hard to understand. In contrast to modern OOP languages like Java, C++ knows many difference variables like normal variables, pointers, references and many more. Even the official manual isn't able to explain the details. The good news is, that a simple look into a C manual will help a lot to get the details.
But let us go a step backward: there are two different programming languages available: C and C++. Most software written in a Linux distribution wasn't created in C++ but in the normal C language. C++ is only teached in the books but seldom used in reality. The obvious difference has to do with object oriented programming. A while a go a stackoverflow users has asked how to realize classes in C:
https://stackoverflow.com/questions/1403890/how-do-you-implement-a-class-in-c
The answer was, that in a struct function pointers needs to be created. And yes, this explanation makes sense. And it explains why C++ is hard to grasp. Because C++ is doing the same but struggles in explaining the reason why. Suppose, somebody likes to program a state of the art program for the console or for the GUI, then the plain C language is the optimal choice. The funny thing is, that even the programmer is asked to declare function pointers the sourcecode is easy to read. If the plan is to not using pointers at all, the python language is a good attempt for software prototyping. It provides classes without pointers and is documented very well.
Instead of arguing against C++ we should ask why the language isn't used in reality more frequently.
But let us go back to the stackoverflow post with the function. A struct is a standard datatype in the C language. It allows to combine different variables into a new one. Extending a struct with functions is the logical next step towards advanced software. The work hypothesis is, that this kind of OOP technique is not an example for bad programming style, but it's the recommended way in programming modern software. The next interesting aspect is, that 95% of C++ programs have the same syntax. That means, pointers are used everywhere. The difference is that a C program which contains of structs and function pointers makes sense while the C++ doesn't makes sense for the newbie.
In the basic version, no function pointers are used, but the struct is provided as a pointer to a normal function:
In another stackoverflow post it was explained how to improve the struct with a function pointer. https://stackoverflow.com/questions/17052443/c-function-inside-struct But the answer says, that this is seldom used in reality. That means, the standard way of emulating OOP features in C is to define the function outside the struct but in the same .c file and call the function with a pointer of the struct instance.
But let us go a step backward: there are two different programming languages available: C and C++. Most software written in a Linux distribution wasn't created in C++ but in the normal C language. C++ is only teached in the books but seldom used in reality. The obvious difference has to do with object oriented programming. A while a go a stackoverflow users has asked how to realize classes in C:
https://stackoverflow.com/questions/1403890/how-do-you-implement-a-class-in-c
The answer was, that in a struct function pointers needs to be created. And yes, this explanation makes sense. And it explains why C++ is hard to grasp. Because C++ is doing the same but struggles in explaining the reason why. Suppose, somebody likes to program a state of the art program for the console or for the GUI, then the plain C language is the optimal choice. The funny thing is, that even the programmer is asked to declare function pointers the sourcecode is easy to read. If the plan is to not using pointers at all, the python language is a good attempt for software prototyping. It provides classes without pointers and is documented very well.
Instead of arguing against C++ we should ask why the language isn't used in reality more frequently.
But let us go back to the stackoverflow post with the function. A struct is a standard datatype in the C language. It allows to combine different variables into a new one. Extending a struct with functions is the logical next step towards advanced software. The work hypothesis is, that this kind of OOP technique is not an example for bad programming style, but it's the recommended way in programming modern software. The next interesting aspect is, that 95% of C++ programs have the same syntax. That means, pointers are used everywhere. The difference is that a C program which contains of structs and function pointers makes sense while the C++ doesn't makes sense for the newbie.
In the basic version, no function pointers are used, but the struct is provided as a pointer to a normal function:
#include "stdio.h"
typedef struct {
int x;
int y;
} Point;
void set(Point* p, int x, int y) {
printf("set\n");
p->x=x;
p->y=y;
};
void show(Point* p) {
printf("show %d %d\n",p->x,p->y);
};
int main()
{
Point p;
set(&p,10,5);
show(&p);
}
In another stackoverflow post it was explained how to improve the struct with a function pointer. https://stackoverflow.com/questions/17052443/c-function-inside-struct But the answer says, that this is seldom used in reality. That means, the standard way of emulating OOP features in C is to define the function outside the struct but in the same .c file and call the function with a pointer of the struct instance.
March 09, 2020
How Linux will take over the business world
Microsoft is in the comfortable position, that 99% of all business oriented PCs are running under this operating system. From a technical point of view, these machines can be replaced with Linux software. And here is the road ahead. The first thing to do is to replace existing Microsoft SQL Servers with Linux systems. For applications like webserver, fileserver, printserver and user directory the Open Source systems are working stable. The next step is convert former desktop PC client into Linux stations. This can be realized with a terminal server. A terminal server has the idea to put all the database into the server, which includes the sql database itself, the middleware and also the frontend.
The citrix terminal server was mentioned already. The idea is, that the multi-user database is programmed on deployed on the server and the normal users are connecting with the Citirx server.
In an Linux environment a state of the art terminal server is the Gnome boxes software for the client. This software allows the user to connect to a remote desktop with the spice protocoll. On the server side the qemu/kvm software is installed which runs a desktop application. In the screenshot the Debian operating system was installed in a virtual machine and the Libreoffice calc program was started to enter a table. The user has to connect with the gnome boxes software to the remote qemu system.

This allows to convert an existing local table into a multi-user network ready table which can be used by many users at the same time. The idea is, that apart from the gnome boxes software, the user has no additional programs installed. He can use a normal Windows 10 PC and the Libreoffice suite is installed on the at the server in the virtual machine. Apart from Libreoffice calc any sort of database frontend can be run on the server. For example Java program or a python tkinter software.
The citrix terminal server was mentioned already. The idea is, that the multi-user database is programmed on deployed on the server and the normal users are connecting with the Citirx server.
In an Linux environment a state of the art terminal server is the Gnome boxes software for the client. This software allows the user to connect to a remote desktop with the spice protocoll. On the server side the qemu/kvm software is installed which runs a desktop application. In the screenshot the Debian operating system was installed in a virtual machine and the Libreoffice calc program was started to enter a table. The user has to connect with the gnome boxes software to the remote qemu system.

This allows to convert an existing local table into a multi-user network ready table which can be used by many users at the same time. The idea is, that apart from the gnome boxes software, the user has no additional programs installed. He can use a normal Windows 10 PC and the Libreoffice suite is installed on the at the server in the virtual machine. Apart from Libreoffice calc any sort of database frontend can be run on the server. For example Java program or a python tkinter software.
Subscribe to:
Posts (Atom)