July 12, 2019

Is Python really the fastest language on earth?


Technically spoken, Python is a slow language. Compared to a modern C++ program, a Python program is running around 10x slower. If the C++ code was highly optimized and is using many threads, the difference is much greater. For performance critical applications Python is some kind of antipattern.
But there is a domain in which Python is the preferred choice. To identify such a domain we have to talk about the advantages of the programming language invented by Guido van Rossum. Python has a simple syntax, doesn't have pointers, comes with libraries for string manipulation and file access, and last but not least thanks to GTK binding and TK interface, it is easy to create a GUI with python. This makes Python the number one language for educational purposes and for prototyping.
Prototyping means, that the written code is thrown away or is converted into a a different programming language. If the aim is to write from scratch a small GUI application, which is using a newly developed algorithm then Python is the excellent choice for realizing such project. The reason why is, that Python abstracts very well from the computer itself. The programmer doesn't care about the underlying CPU, doesn't care about the operating system and ignores even C datatypes. Python simplifies programming because the programmer doesn't have define a datatype. He can create an empty list, pushes some value to the list and traverse it with a for loop. No other programming language including Turbo Pascal, Lisp or Java makes programming so easy.
Somebody may ask how to improve the performance of a python program. The answer is easy: within Python it is not possible to speed up the code. If the code should run faster, somebody has to create a C/C++ project which takes advantage of the existing compiler infrastructure. The prediction is that future iteration of the Python interpreter will become slower, but not faster. At the same time, it will become easier to write a short program from scratch with ignoring everything what C/C++ programmers are trained.
Python can be compared with MS-Excel. It is a standard tool for testing out pseudocode in a runtime environment. Sometimes, Matlab is seen as the strongest competitor to Python. It adresses the same purpose. But matlab isn't a universal programming language and is not available under Linux operating system. The reason, why Python was able to replace former scripting languages like Perl has to do with it's object oriented extensions. In Python it's possible to create classes which can be seen as subprograms in a main program. Classes makes it easy to divide a problem into smaller chunks.

No comments:

Post a Comment