Showing posts with label C++. Show all posts
Showing posts with label C++. Show all posts

September 16, 2025

Wie man eine Linux Distribution auswählt

 Neueinsteiger sehen sich mit einer Unmenge unterschiedlicher Linux Distributionen konfrontiert, die untereinander vollständig inkompatibel sind. Ferner ist es selbst für Computer Experten nahezu unmöglich, sich selbst eine Linux Distribution zu erstellen. Daraus ergibt sich das Problem sich entscheiden zu müssen was mit einem hohen Lernaufwand verbunden ist.

Die wohl einsteigerfreundlichste Methode sich der Welt von Open Source und Linux zu nähern besteht darin, ein aktuelles Debian Live image auf einen USB Stick zu kopieren, damit einen älteren Rechner zu starten und auf der Festplatte dann Linux zu installieren. Sollte der potentielle User auf technische Schwierigkeiten stoßen beim erstellen des Debian Live images, so sollte die Linux Migration an sich hinterfragt werden. Wenn selbst Debian Live zu hohe Anforderungen an einen User stellt, wird er mit anderen Distributionen auf noch viel tiefer gehende Probleme stoßen und dann ist möglicherweise Linux das falsche Betriebssystem für den User.

Angenommen das Booten eines PC mit der live iso datei und das anschließénde installieren auf der Festplatte funktioniert, so wird der User feststellen, dass Linux grundsätzlich anders aufgebaut ist, als das gewohnte Windows oder MacOS. Es gibt andere Programme, andere Online Foren und die Kommandozeile spielt eine viel wichtigere Rolle. Der wichtigste Unterschied bei Linux ist die Abwesenheit von komerzieller Software und die Abwesenheit von Computerspielen. Rein technisch kann man in Linux durchaus mittels der Steam Software Spiele installieren und einige User machen das tatsächlich, doch die Mehrzahl der 80 Mio Linux User dürfte selten Computerspiele spielen. Jedenfalls ist das den Zahlen zu entnehmen, bezüglich angemeldeter Clients in Online Rollenspielen.

Linux ist klassischerweise ein Betriebssystem für Programmierer. Es kann durchaus auch von Nicht Programmierern verwendet werden, doch ist dieser Anwendungsfall eher die Ausnahme. Es gab in der Vergangenheit zahlreiche Versuche, Linux für die große Masse zugänglicher zu machen, ähnlich wie Android bei Smartphones, doch all diese Versuche sind gescheitert. Projekte wie Ubuntu Linux, Linux Mint oder Videotutorials im Internet die schritt für schritt erklären wie man eine ext4 Partition verkleinert kommen ihrem Ziel Linux für Jedermann zu erklären nicht nach. Nutzer die sich nicht technisch mit einem Betriebssystem auseinandersetzen wollen bleiben seit Jahren dem etablierten Windows und MacOS Ökosystem treu und fühlen sich von Linux eher abgeschreckt. Mag sein, dass Linux bei Supercomputern, bei Servern und auf Smartphones das dominerende Betriebssystem weltweit ist, bei Desktop PC ist es Nischensystem was sich an einer sehr kleine Zielgruppe von Programmierern wendet. Wer noch nie in der Sprache C programmniert hat und in LaTeX keinen Sinn erkennen zu vermag, der ist definitiv falsch bei Linux, ganz egal ob er Debian, Arch Linux oder Suse preferiert.

Zum Abschluss noch ein kleiner Selbsttest für die Programmiersprache C. Nur wenn man 6 von 6 Antworten korrekt geben konnte, sollte man den Versuch unternehmen auf Linux umzusteigen. Andernfalls wird das Projekt sehr wahrscheinlich scheitern.

Quiz: Die Programmiersprache C für Anfänger

1.  Was ist das grundlegende Element, das ein C-Programm benötigt, um zu starten?
    a) Eine `#include`-Anweisung.
    b) Die `main()`-Funktion.
    c) Eine Variable mit dem Namen `start`.
    d) Eine Bibliothek namens `begin.h`.

2.  Welche Header-Datei wird typischerweise benötigt, um die Funktion `printf()` zu verwenden?
    a) `stdlib.h`
    b) `string.h`
    c) `stdio.h`
    d) `math.h`

3.  Wofür wird ein Semikolon (`;`) in C hauptsächlich verwendet?
    a) Um das Ende einer Code-Zeile zu markieren.
    b) Um eine Variable zu deklarieren.
    c) Um das Ende einer Anweisung zu markieren.
    d) Um Kommentare zu schreiben.

4.  Wie wird in C eine einfache Ganzzahl-Variable namens `zahl` deklariert, die den Wert 10 enthält?
    a) `int zahl = 10;`
    b) `number zahl = 10;`
    c) `integer zahl = "10";`
    d) `zahl = 10;`

5.  Welches ist der korrekte Datentyp für ein einzelnes Zeichen in C?
    a) `string`
    b) `char`
    c) `text`
    d) `byte`

6.  Was ist die Aufgabe eines Compilers?
    a) Er wandelt den C-Code direkt in Text um.
    b) Er führt das Programm aus.
    c) Er übersetzt den C-Quellcode in maschinenlesbaren Code.
    d) Er sucht nach Viren im Programm.

---
Richtige Antworten

1.  b) Die `main()`-Funktion. Sie ist der Einstiegspunkt, an dem das Programm beginnt.
2.  c) `stdio.h` (Standard Input/Output). Diese Bibliothek enthält grundlegende Ein- und Ausgabefunktionen wie `printf()` und `scanf()`.
3.  c) Um das Ende einer Anweisung zu markieren. Jede Anweisung muss mit einem Semikolon abgeschlossen werden.
4.  a) `int zahl = 10;`. `int` steht für Integer (Ganzzahl).
5.  b) `char`. Dies ist der Standard-Datentyp für Zeichen.
6.  c) Er übersetzt den C-Quellcode in maschinenlesbaren Code. Der Compiler ist das Werkzeug, das den Code in ein ausführbares Programm umwandelt.

November 15, 2023

Homecomputers until the 1990s

 Before the advent of today's PC technology which is dominated by Windows and Linux operating system there was a much smaller community available of computer enthusiasts. From 1980-1990 most of todays computer hardware and software was invented in the first place and the magazines which were introducing the subject to a readership were sometimes very well informed. In that period two dominant computer systems were available which was the Commodore 64 and the MS DOS PC.

At first it should be mentioned that on IBM PC hardware until the year 1990 the well known Windows operating won't be running fast enough. The only available operating system for early DOS Computers was DOS itself which is a single user, single tasking operating system. In comparison to the Commodore 64 advantage was that it was much easier to write software for MS DOS than for the C64. 8bit homecomputers with 64kb and less main memory and without any harddrive are not capable in running compiled C programs. The only sense making programming technique is the Assembly language. In contrast, early MS DOS PC until 1990s are working fine with c compilers. These large scale programs including the build in libraries can be installed on the small hard drive (less than 100 MB) and it is possible to write and debug software direct on a MS DOS PC.

The reason why this workflow is described in detail is because its working the same like modern programming workflow in the 2020s. That means, in the last decades the programming itself hasn't changed that much. Typing in C code on a 286 PC and compile it into machine code or typing in java code into a mto a more recent 4 core PC is based on the same abstraction mechanism. The human programmer has a set of libraries and combines existing functions into a new software.

Somebody may argue, that the difference between Assembly language and Turbo C is small because both programming language were invented decades ago. This assumption is wrong. Learning assembly from scratch and write larger software is very complicated while the same task in C can be handled easily. The difference is that the C language is a problem oriented language while assembly is hardware oriented. The typical assembly program is written for a certain CPU and a certain adress space in the main memory, while c program are written around a certain domain like a game or a word processing applications.

The only negative point of the C language are the hardware requirement. C assumes that an entry level 286 MS DOS PC is available which has 600 kb of RAM and a harddisc of 10 MB and more. Its not possible to run  a compiler with less RAM and without a harddrive. Even if some C compilers are available for the C64, it can't be used in reality for writing programs. The cause is that a compiled C program is much slower and will need more RAM than a hand coded assembly program.

The main difference between the C64 and the MS DOS PC Is, that C64 programmers claim that Assembly language is a here to stay. This assumption is the result of the lower hardware of the C64 which prevents to use any other programming language than Assembly. Even if its possible to write Assembly program on the MS DOS PC most programmers prefer a c compiler because the language allows to increase the productivity. Especially if a graphics library is available and the programmer is familiar with the computer its possible to write simple games in a short amount of time, very similar to what today's programmer can archive. in other words the existence of a c compiler is the single cause why MS DOS PC have replaced 8bit homecomputers.

October 01, 2022

Programming languages in a cluster diagram




The amount of programming languages is endless. One suboptimal option to categorize them is by their history. The more elaborated attempt in building clusters is by a two variable model which contains of interpreted vs compiled and procedural vs. objectoriented. The interesting situation is, that all the existing languages can be located at a certain position in the 2d chart.

And secondly it is possible to name only the languages located on the four corner which are: Basic, Python, C++ and C. Each of these languages has in one variable the maximum value. For example, the Basic language is an interpreted language which is working with the procedural paradigm.

Let us determine the best programming languages for professional purposes. The interesting situation is, that even more than 200 different programming languages were invented, most of them are only used in an academic context. At the university lots of languages are taught, e.g. Pascal, Python and of course Prolog. But, most of these languages are not used for writing operating systems which includes applications for operating systems. The concern of expert prorammers against these academic languages is, that they are objectoriented which is equal to rreject them or they are interpreted which also implies to reject them. The only language which is not object oriented and not interpreted is C.

A closer look into the debian repository and into the anecdotal description of what is used for creating MS-Dos and Win16 bit application will show, that 100% of the software in the past was written in Ansi-C. This is especially the case for the early 1990s. According to the programming books of this time, the future is about object oriented programming namely C++, Delphi and Java, But at the same time, these languages were not used to write production ready sourcecode. But the programmers are prefering Ansi-C.

According to the picture it is very easy to explain the reason why. Professional programmers are prefering a language which is compiled and procedural at the same time. The only language available in this category is C. All the other languages like C++, Basic, Prolog, Lua and so on have a different self understanding.

The question which remains open is, why exactly professional software is written with compiled&procedural languages. It seems that only this combination ensures the maximum performance and the ability to maintain a larger amount of codelines. What the Linux sourcecode and the Windows sourcecode have in common is, that the project has over 1 million lines of code and that the binary file is executed very efficient.

October 24, 2021

What is wrong with C?

 

Over the years, many programming languages have been invented. But which one is the best one? To answer the question the existing languages have to be ordered in categories. There are the following groups available: interpreted vs compiled languages, procedural vs object oriented languages, mainstream vs. uncommon languages. The idea is that a certain combination of these categories will result into a very well language.
Let us start with the famous Python language. Python is fore sure one of the most languages ever. In contrast to the earlier visual basic, python is accepted by everyone. No matter if the programmer preferes Linux or Windows, no matter if he is a beginner or an expert, python is loved by everyone. Python is located in the interpreted group and has object oriented features. This combination makes it very easy to create programs. Possible alternatives over Python is groovy, which has the same syntax but is less popular.
The main problem of python is that the performance is poor. It is not possible to write operating systems libraries or production ready code in this language. So possible second language is needed.
An interesting language to python is C++. C++ was used in the 1990s before scripted object oriented language were available. The main idea is to combine OOP features with a compiler. The problem with C++ is that the user has to use pointers all the time. Possible alternatives over C++ like D are promising to solve this issue but real programs written in D are using pointers also. A typical situation in these languages is that the user has to initialize an object on the heap, and then he has to send the pointer to this object to other objects. This programming style is very complicated to master, so C++ isn't the best language on earth.
From a more abstract perspective the question is how OOP features are related to compiled languages. It seems that OOP works fine for scripted language. In case of compiled language OOP is harder to realize. So a working hypothesis is, that compiled language should use OOP features at all. And this will lead to the very interesting old and new language C. C is a compiled language which has pointers but not OOP features. Writing code in C is different from writing code in Python. C is located on the low level and the user has to fulfill the needs of the machine. In exchange C provides a fast binary code which works great in a library.
The open question is if OOP features can be combined with a compiled language. Let us try to convince existing Python programmers to switch to the C++ language. Unfurtunately, this is impossible. Python programmers have no advantage if the code is compiled but it will make the edit compile run cycle slower. Also python programmer doesn't need to use user pointers so the C++ language doesn't make sense for him. The prediction is that C++ will struggle in replacing python. And that means, C++ struggles in become the number one high level language used for prototyping purposes.
In the second step the idea is to convince existing low level C programmers to use C++. The advantage of C++ over plain C is that C++ has olasses. Unfortunately, C programmers have no need for classes. The reason is that C programmers doesn't implement prototypes or writing hello world scripts, but c programmers are writing low level libraries and operating systems. That means C++ will fail to become the number one low level language. And this means, C++ can't become the number one in any category.
The logical consequence is that the attempt of combining a compiled language language with object oriented feature have failed. It is a dead end in programming language design in trying so. In general the categories are:
1. low level procedural languages which are compiled and very fast
2 high level object oriented language which are interpreted and slow
It is not possible to invent a language which fulfills both needs. Instead separate languages are needed for each purpose. Bascially spoken the following programming languages are outdated: Java (but groovy not), C++ (but C not), C#,
From a positive standpoint, C programmers will never switch to C++ and Python programmers will never switch to C++ as well. A simple look in the existing programs written in C and python as well will show that both programming styles are too powerful that any language in the world can provide an alternative.

August 17, 2021

Is Assembly language more efficient over C?

 

Some Linux newbies are often surprise why after an installation the system will need so much discpace on the hard drive and will occupy 2 GB of RAM. Even minimalist Window manager like LXDE will need 700 MB of RAM without starting a single application. The answer to this problem is not located in Linux itself but is has to with the C programming language.
In contrast to a common myth, the c language is not the fastest and most efficient programming language in the world but it is only a language used everywhere. C compilers are optimized for compatibility reasons and will in a direct comparison with handcrafted assembly language. To understand how big the gap is we have to focus on some operating systems which were written entirely in Assembly. These systems for example MenuetOS will need only 70 MB of RAM and are providing network functionality and a GUI. In contrast, the Debian system will need 10x more RAM.
With improved programming techniques for example storing Assembly instructions as bytecode it is possible to reduce the RAM consumption further. So it is possible to compress an entire operating system into 20 MB of RAM. It will use the latest graphics modes and is ultrafast.
The only problem is, that the sourcecode is difficult to maintain. At least for c programmers. Only Forth programmers and assembly specialist find it easy to maintain such a minimalist operating system. Bascially spoken, technically it is possible to program a linux like OS which needs only 10% of the RAM of a normal Linux system, the problem is, that somebody has to write the sourcecode first and this is the bottleneck.
The reason why the C language is used so much in the reality is, because it has simplified the programming. Even larger programs which contains of many modules can be created in C easily. The additional advantage is, that the same code can be compiled for different hardware architecture. The disadvantage of this flexciblity is, that the RAM Conspumption is high, the and the runtime speed low. But in the reality this is not a big problem, because modern computers have large amount of RAM. So we can say, that programming in the now works different from programming in the 1980s in which every byte of the RAM was expensive. In the 1980s most programmers have tried to reduce the amount of occupied RAM to a minimum. It was common to write programs which were running with 200 kb RAM and less. For today's ears this sounds like overengineering. Because a single PNG image which is rendered in Firefox will occupy this amount of RAM easily. It simply makes no sense to reduce the needed amount of RAM For executable binary files.
Perhaps it makes sense to explain what programming in general is. Let us investigate the similarity of some larger apps which are gnuplot and lyx. The shared feature is, that both applications are containing a large amount of codelines. In these codelines all the features are implemented. Each submenu in Lyx was realized with complicated C functions. So we can say, that the reason why these programs are big is not because of the programming style itself, but it has to do with the requirements how the application is working. That means, if somebody writes a gnuplot program from scratch which has all the same features and all the fancy graphics and buttons, he will need the same amount of codelines like the original gnuplot needs today. The only choice for creating smaller programs is to reduce the amount of features. For example if the idea is to program a simple command line based texteditor which has no features at all it is possible to compress the binary file in less than 50 kb of RAM. The problem is that modern normal users have such high expectations in the software. They wouldn't be satisfied by a simple 50kb large texteditor but they have a need for a lyx-like all in one system.

June 23, 2021

Is C the optimal language for programming the C64?

 The good news is, that the problem of identifying the ideal programming language can be reduced to only two: Assembly vs. C. It is pretty easy to show, that C code will run slower and needs more RAM than the manual created assembly code. A typical example would be a prime number generator.

The more interesting question is, how much exactly C code will run slower. Somewhere in the internet it was written that without using cc65 optimization techniques the C code will run 5 times slower. On the first look this speaks for replacing C code with assembly. But a closer look will show, that slowdown by the factor 5 is not very much. Suppose there is an algorithm which needs 60 seconds. If the same algorithm was rewritten in Assembly it will need only 12 seconds. In both cases, the algorithm won't run in realtime but the user has to wait in front of the machine.

The main concern with assembly language is, that the sourcecode isn't readable. Even if the programmer is using lots of comments, the code will look messy. This is perhaps one of the reasons, why C has replaced former assembly coding.

Suppose the hardware is a bit faster than the original 6502, suppose some optimizatinon techniqfues in the compiler were activated, then the chance is high, that the C code will be only 2 times slower than the assembly language counter part. This slow down is acceptable because the code is way much easier to read.

Let us make the situation more practical. A naive prime number generator works with two nested loops. Such an algorithm will run in assembly around 5 times faster then the C counterpart. But, a more advanced sieve algorithm will run much faster, no matter in which programming language it was implemented. That means, the sieve prime number generator written in C will outperform the nested loop algorithm written in Assembly language easily.

The problem with coding assembly language is, that it is difficult to write longer and more complex algorithm. Implementing a sieve algorithm in Assembly is an advanced project. That means, even an experience programmer will need many hours in doing so.

It is a known fact that during the 1980s the c language was not very popular for the Commodore 64. All of the demos were written in pure assembly code. This fact is known, because the sourcecode of the demos is available and it is normal 6502 assembly code. But what if the demo competation has the contraints, that the code has to be written in C?

since a while the C64 community has discovered the cc65 cross compiler again. They are trying to use this environment to write games from scratch. The resulting games are look not impressive as the Assembly demos, but they are easier to read and it takes less effort to code them.

A list of some games written in cc65 are available at https://wiki.cc65.org/doku.php?id=cc65:cc65-apps The quality of these games is low. They are looking like the early c64 games from the 1984 year.

An interesting side question which remains unanswered in this blog post is, if Forth can outperform the C language on the C-64. the problem with Forth is, that most existing Forth systems are only interpreters, they are not converting the code into assembly instructions so the resulting program will run slow. What is known from the MS-DOS PC is, that compiled Forth code can reach the same speed like compiled c code.[1] That means, compiled forth code will run slower than hand coded assembly code.

[1] Almy, Thomas. "Compiling Forth for performance." Journal of Forth Application and Research 4.3 (1986): 379-388.

March 22, 2020

Small rant against the C language

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 11, 2020

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.

// 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).

June 20, 2019

Object orientation for C programmers


Creating a normal program can be done with C like languages. The user defines some functions which have input parameters and in the main loop the functions are called in a sequence. The surprising information is, that object oriented programming is the same but it is more powerful. The first thing which has to be introduced are so called structs. A struct is C variable which contains more than a single item. A struct is for example a pixel which can have an x value and also an y value at the same time.
In the classical C programming context, variables and structs are defined at a certain position in the program code. Usually inside the function. In the object oriented paradigm, global variables are used. That means, the struct defintion doesn't belongs to a certain function but is defined globally on top of the program. All functions have access to the struct. And now comes the best part, if the struct keyword is replaced by the class keyword in C++ we have written the first true object oriented program.
What i want to explain is, that the transition from classical structured programming in C to modern object oriented programming in C++ is a continuous process.
1. normal c program
2. structs
3. global structs
4. object oriented classes
If somebody doesn't have understood object oriented programming at all, he can simply take a step backward. Instead of using the class keyword, he can stay in the struct paradigm. That means, he is not defining classes and doesn't inherit from super classes, but he only aggregates variables to a table. Object orientated programming was never planned as a revolution in software engineering but it's a small improvement over normal structured programming.