August 21, 2019

C++ is a great language, but heavy complicated to program


An experiment with programming a mathematical subroutine has shown, that in theory C++ is a great programming language which can be used in exchange over the Python language. C++ provides classes, lists, high level functions and the resulting binary file is ultrafast. On my computer the C++ version of the program was around 40x faster.
The disadvantage is, that programming a simple routine was very complicated. At least at the beginning, lots of compilation errors are visible. If somebody comes with a background of Python to C++ he will need some time to become familiar with the language. After a while the situation is more relaxed, because the programmer understands, that the auto keyword can't be used in reality, that floating variables need a “.f” at the end, and to end each statement with a semicolon. Sure, it's possible to learn the new syntax, but in contrast to Python it's take much longer to write a new program.
Sometimes, it make sense to convert a given program from Python into C++. The speed advantage is great. But there are reasons to avoid C++ in most cases. Using C++ on a daily basis doesn't make much sense. It takes simply to much time to test out new programming routines, Python is the more elaborated way in programming code. On the other hand, Python can't be executed efficient on modern hardware. So there is a need to convert existing Python code into the C++ language. I would guess, that in a practical project it make sense to manage two respositories at the same time. Python for prototyping the application and C++ for creating super fast routines.
Writing C++ code is a bit different from writing Python code. C++ can be seen as a classical programming language. The programmer has to convert a problem into a machine readable format. He has to decide which datatypes are needed, for example string or float. He has also manage pointers and has to figure out why a compilation error is there. Because C++ is a mature language, all problems can be solved. That means, any problem can be handled within the C++ universe. There is no problem which can't be realized in the language.
On the other hand, coding a program in C++ can become a bit exhausting. The advantage of Python is, that the programmer doesn't have to specify the details. Python doesn't know a datatype and if the programmer sees a pointer adress in the console, he has made a serious error. Python has the self-understanding, that the programmer has to focus on the problem and the algorithm, but not on the machine level. Python can be compared with matlab. It's a very high language which hides all the implementation details.
Somebody would argue, that C++ isn't a low level machine. Similar to Python it provides an abstraction layer to the programmer. He can get the maximum control over the machine by using the assembly language. This allows to code programs which are more efficient over C/C++.

No comments:

Post a Comment