Published on: 15.02.2018
I would not recommend learning C/C++ as your first programing language just for learning to programme, better go with Python.
Also, if you do not know why you want to learn C/C++, better do not spend time on it.
Most of my professional programming career, around 10 years I have spent writing C/C++ programs.
By professional programming career, I mean that other people have paid me to write code.
I have spent more time in C/C++, altho I would say that I know Python better than C/C++.
My knowledge of Python is better because Python has fewer features than C/C++ and you do not need to do memory management.
IMHO C/C++ is hard due to many features and memory management.
By the time you understand memory management, you can learn 80% of Python.
Just look at this image of code that is concentrating 2 strings in C vs. Python.
Yes, there can be less C code (error checking, free, few const less) and the code would still work.
But then I would be showing bad C production code and not be demonstrating how real-world C code should be written.
It is not fun to debug segmentation fault and that is what you get if there is no proper error checking in C.
Python code could, and in real life should also have if __name__ == "__main__":
, but I have removed it to because it is not necessary like in C.
Point is that higher level programing language (Python in this example) is doing a lot of low-level things automatically.
So, you need fewer lines of code, what means fewer possible bugs, resulting in increased developer productivity.
The tradeoff is more CPU and memory for faster time to market.
Here I am using a language construct C/C++.
Because most of the code bases (at least that I have seen in a corporate environment) are some hybrid of C and C++.
My theory is that the older code was written in C and then later they added object-oriented programming (C++).
But C and C++ are not the same programming languages, mental programming models are quite different.
C code is about structure, functions, and pointers.
In C++ you have object-oriented programming and lot of other features.
In the real world, you need to know C and C++, so that is why I use C/C++.
The only positive thing that I can see that person will learn from learning C/C++ is manual memory management and pointers.
Basically better understanding how the computer (on software level) is working.
If your only reason is to have a better understanding how the computer (on software level) is working, better learn C programing language.
C has fewer features than C++.
It is easier to learn C++ if you know C because then you should know manual memory management and pointers.
But for anything else than few niches (system, embedded, banking, game engines, etc), I do not see a much practical use of C/C++ in the year 2018.
I am not saying C/C++ is not in use anywhere in 2018.
I personally (almost every month) get some interview requests for C/C++ positions.
Usually, they are either for embedded software © or banking industries (C++).
I am just arguing that beginners (persons that do not know any programing language) should not start with C/C++.
The only exception is if you are planning to get a job (or start your business) in C/C++ environment.
If it is not for the job/business, I do not see why you should learn C/C++, except for hobby.
But even then, get a better hobby 🙂.
P.S. If you, dear reader, think that I am missing some point, please add it in comments.
Originally published at buklijas.info on February 15, 2018.