Step up your game – Upgrade from C to C++

When writing complex programs in C, one will be confronted with the topic of code redundancy and accessibility control issues. C++ was first introduced in 1983, called “C with classes”, and solves a bunch of hurdles stumpling upon programming in C.

The advantages of object-oriented programming languages

Defining complex data structures in C remembers of defining records in a functional programming language. When defining methods over several similar structures, the code redundancy gets clear – every struct needs its own implementation. For all functions or calls.

In OOP (object-oriented programming languages), classes get introduced. Those classes serve as a template, a mold for every object created when a program is compiled. Classes can also be derived from abstract super-classes, giving a smoothly working structure in a program. This will enable to define contextual similar classes with similar implementations – once.

Take an abstract class “Vehicle”. From this, we will be able to define the subclasses “Car”, “Bike”, “Motorcycle”, “E-Scooter” and so on. They all have similar properties (they all have a person driving the vehicle, and this person has a name, for instance). They all can have a boolean, if the vehicle is in motion or parking. You can imagine a bunch of other properties to define.

One other big advantage is, that it is easily implementable that the name of any driver of any vehicle is hidden for the outside world.

These are just a few advantages – for more information, I invite you to read the following article . There are many more in the internet, feel free and explore.

C vs. C++

C is a machine-oriented language. The binary that is produced by compiling with GCC is made for the respective machine and the respective machine only. Among others, architecture and OS play a big role for the binary. But, this binary is fast. Super-fast.

It is a big process to upgrade C. It started in the 80s with “C with classes”, in the 90s, C++ was the new name and standards were introduced. Current industry standard: Cpp17.

Small example project

I wrote a small C++ project, availiable on GitHub.

Enter the following command to clone the repository in the respective workspace. One works with SSH authentication (standard case), one works with https (encrypted “only”).

git clone git@github.com:CobbieCobbie/small-cpp-project.git //with SSH

git clone https://github.com/CobbieCobbie/small-cpp-project.git //with HTTPS

Please, have a look in every file in the master branch. Almost all files are commented adequately.

Prequisites

References