September 24, 2019

Which alternatives over Python are available?

The quick and easy answer is, that plain C is well suited for creating productive applications. But let us slow down the problem a bit and describe first what is wrong with python.

Suppose, a GUI prototype was created in Python. Everything works fine, because Python is a great choice for creating runnable scripts. The only problem is, that the resulting code is slow, won't run on different architecture and is not recommneded for a productive environment. The first trial is to redefine the problem and claim, that Python is a great language for creating efficient applications. But even Python advocates are realistic and are aware that Python has some limits. The best example is a game written in Python. It looks nice for a prototype but for daily usage the application will consume to much cpu-ressources.

So, what is the next better alternative? The good news is, that an existing software written in Python can be converted easily in any other language. The conversion has to be done manual, but it's not very complicated. So it's up to the programmer to choice on of the existing 400 programming language and rewrite the app. Rewriting the software in a different language is not a mistake, but it's the fastest way in software development because it postpone the less important steps.

Which target language is the right one? According to the TIOBE index, and the Stackoverflow website, large universal languages are C++, Java and C#. All of them are supporting object oriented programming. The problem with these languages is, that they are complex to master, because they are supporting OOP features. The more elegant way in programming an application is plain C. Plain C is some kind of standard language which is supported with the top priority by the GNU Compiler collection. But if compiled C is a good choice, what speaks against the C++ language?

To understand the issue we have to make clear what the shared principle of all compiled languages is. Java, C++, and even C are static typed languages. That means, the user has to define the datatypes in advance. For example, he defines an array, an integer variable and so on. The reason, why programming in Python is so much easier is because in Python there is no need to define datatypes. Only compiled languages have a need for static types.

If we made the decision to rewrite a software into a professional language, this is equal to rewrite the code in a static typed language. Which means, the programmer is forced to negotiate with the compiler on a lower level. He has to think about pointers, heap, main memory and so on. There is a simple decision. Either the programmer is working on a high level which is equal to Python. In this case he can figure out the best algorithm and ignore the underlying operating system. Or he rewrites the software in a fast language, which is compiled, then he thinks about system level implementations.

It's obvious why languages like Java, C# and C++ are a bad choice for creating productive code. In case of Java the programmer has no access to pointers, and in case of C++ he is forced in using classes. If the programmer is trying to write lowlevel code the only choice is plain C. And yes, writing an application in C is more complicated than doing it in Python. But C is more easier to master than Assembly language and for most tasks there is a library available. In most cases, a C program will use a dynamic datastructure which is a linked list. The advantage is, that such a list is superfast and allows to create efficient programs.

The main reason why C is recommended for productive code is, because the amount of features is reduced. In contrast to Java or C#, C code supports only a limited amount of programming techniques. Apart from c files which are put together by the compiler no other features are available. It's not allowed to use object oriented programming, it's not allowed to use a predefined dictionary, but the programmer has to manipulate the main memory directly and needs to know what the external libraries are doing. This results into a programming style which is more efficient than Java code or C++ code. Not because a Java compiler is slow but because the programmer limits himself to writing C code.

Object oriented programming is a great idea in prototyping of software. In a short time, larger applications can be created. Using the same principle for creating productive code is a bad idea. The reason is, that the main memory of a computer doesn't understand what objects are. And compilers or virtual machines who are translating object oriented code into binary code are too complex for practical usage. The better idea is to divide the programming task into two subproblems. Creating the application prototype with Python and building the productive code in C.

If the c code was written the application is build for the future. The same code will compile in 10 years from now. The reason is, that plain C is the common standard in programming. If the C# language is forgotten, if Python scripts won't run and if the operating system is different, one thing remains stable. C code can be compiled always into binary code. The funny aspect in C code is, that apart from a bit pointer juggling there are no other complicated things which can be made wrong. The c language contains only of for loops, if statements, pointers and external libraries. It's easy to debug existing C code, and it make sense to write new one.