In the past, I’ve written an article in which the comparison was decided against Python. To be fair, this time I want to select a different winner, namely Python. For doing so, we must go into the details. From a technical point of view, the C++ programming language is superior. The resulting binary file is at least 10x times faster, than a Python program. Another feature of C++ is, that the language is standardized. That means, the current C++ compiler can compile everything which was programmed a long time ago. But if C++ is so great, why are the people using Python? According to Stackoverflow, they are using more often than C++. The reason are the following:
– at first, Python sourcecode is easier to read. It looks equal to pseudocode and can be written down in academic papers without executing the code itself.
– secondly, Python GUI apps can be faster developed than C++ apps. There are huge amount of tutorials available for Linux and Windows which allows a newbie to create his first point&click app in Python in under an hour
– third, Python sourcecode needs less space. Around 30% can be saved compared to C++
It seems, that Python and C++ are very strong programming languages. The problem is, that it is hard to combine both. But which language should be preferred for new projects? C++ or Python? To answer this question we have to focus on the bottleneck in software projects. The goal of any project manager is, to let many developers work on the same issue. This will increase the overall speed very much. If one programmer can create 10 lines of code per day, 100 programmers can create 1000 lines of code per day. And if a team is available which is able to produce such kind of new codelines, it is a huge asset. So the question is, in which language it is easier for working together?
The first hint is maybe C++. Because this language was developed with the aim of creating libraries. Most operating system libraries are written in C++. It is possible to compile each module separately and use these C++ library with any other programming language. C++ is a great library development language. But there are major weakness. First point is, that not all programmers are familiar with C++. There are many programmers out there how are fluent in Python or Java but not in C++. Forcing them to use C++ is a bit problematic. And secondly, the ability of using precompiled library is for most projects not important. This has to be explained in detail.
C++ was invented as a classical programming language. The idea is, that the programmer writes sourcecode, converting this into a binary file and use this together with other code. For a well defined task this is even today the most efficient way of programming. The problem with modern software projects is, that in most cases no specification is available. That means, it is unclear which algorithm is right or which GUI interface is needed. Most work done by developers is not the programming task itself, which means to convert requirements into sourcecode, but to create the requirements. That means, modern programming can be described as prototyping. It is a prestep before the coding itself will start. Part of the prototyping step is, to send pdf documents back and forth, to discuss the progress in online forums, to create GUI mock ups and to play around with new algorithms. All these task can be done great with Python. Python is the quasi standard for everything which has nothing to do with programming. Most Python programs are not written to run on a production server but with the purpose to create prototypes.
The idea behind a python app is, that write a quick&dirty prototype and only convert it later to a C++ application, if the software works great. Not programming is the bottleneck but prototyping is the real problem which needs most of the energy. What is prototyping? Prototyping is everything before the application is programmed. That means, there is no binary version which has to be delivered and which has to fulfill realtime criteria, instead the project consists of sketches, pseudocode and non-working algorithms.
In the classical C++ world, the prototyping step was ignored. That means, C++ doesn’t support such kind of programming. C++ was created with the compiler in mind, the precondition of writing C++ sourcecode is, that the developer knows what the correct algorithm is, and that he has discussed the GUI issue with other team members last month.That means, C++ is a great language, if the prototype is there and the final application has to be created. In most software projects this assumption is wrong. That means, the projects starts and no working prototype is there, instead nothing is available and creating the prototype is the first step.
Using C++ as a prototype language is from a technical point of view possible. The new C++11 standard allows to use high level GUI libraries, provides lists and object oriented programming. But C++ can’t compete with the real prototyping language which is python. Because Python is used in algorithm discussions, for matplotlib like drawing tasks and for GUI development. To understand better what the bottleneck in modern software projects is, let us assume a prototype is already there. That means, a Python application is available which contains of working algorithm, a gui and a backend. How complicated is the task to convert such a Python prototype into a ready-to-deliver C++ application? It is surprisingly easy. Such a migration can be done by a single programmer or a very small team of 1-3 developers in a short amount of time. Their only responsibility is to reprogram the existing application in C++. That means, to create software which works exactly like the prototype and can be installed with a package manager.
This programming step can be called the core of programming, because it has to do with typing in sourcecode in the C++ language. The funny thing is, that such kind of Python to C++ migration will never fail. It is simply not possible that the developer will recognize a major problem, because C++ is the most powerful language available. The software will run faster and needs less memory than the prototype. Additionally, the project will need only a little time and little amount of manyears.
If core programming is so easy, why is software development overall so hard? Right, the answer is that prototyping needs 90% of the project time and core programming needs less than 10%. If it’s possible to optimize the prototyping step much energy can be saved. How much is the percentage of C++ in the prototyping step? Right, very few. And that is the reason, why Python is superior to C++. It is enough to improve only the prototyping step and ignore the programming task itself. That means, if the Python prototype is ready, the overall project is also ready.
It is hard to recommend Python as a language for the binary application. The disadvantages of low performance are known, and it is also not possible to create Linux packages out of Python sourcecode. If somebody is doing so it looks not professional. A real application / game has to be programmed always in C++. But it is important to delay this C++ programming step as much as possible. That means, the C++ programming step can wait until everything important is over. In the meantime Python is the better choice. It allows to communicate about the project progress, it allows to test out new ideas easily and it helps to create GUI designs. Using Python as a programming language is a bad choice, because Python is compared to C++ a weak language. But using Python as a case-tool is a great choice. It is a very flexible tool and helps a lot in creating mockups.
It doesn’t make much sense to compare Python with C++. C++ is a language for creating executable programs for example a game which has to be run as fast as possible, while Python is a language for playing around with different concepts. Python can be compared with other case tools (Computer-aided software engineering) for example Matlab, Microsoft Access, UML drawing software and GIMP for drawing GUI buttons on the screen.