August 25, 2019

Using many programming languages at the same time is a mess


The reason why Python is so popular is because it's a prototyping language. The programmer is no longer forced to use a complicated syntax or adapt to the needs of the machine, but he can type in pseudo code and focus on the application itself. But Python has a major disadvantage which makes it unusable for productive code: it's slow and won't run on different platforms.
The more elegant languages over Python are C#, Java, Go or C++. They are compiled or semicompiled languages. Especially C++ is recognized as a very efficient programming language. The problem is how to connect existing Python Code with a C++ application? I have tried out some techniques like Boost.Python, embedded Python, ctypes and SWIG but none of them can be recommended. The problem is, that even the programmer is able to write an interface for using Python together with C++, the technique can't be used for other purposes. In most cases the problem is not only to communicate between Python and C++, but perhaps the user likes to send data from a Java application to a C# application.
A more recent approach is RESTful which is a network communicating standard. On the first look it sounds not very attractive to send json data over the localhost interface of the network card, because we want to communicate between two applications. On the other hand, the RESTful idea is a very general approach which fits for all programming languages.
In theory, it's possible to start the Python app and also the C++ app and both are communicating to each other over a socket. I didn't have tried it out in reality, but the promise is, that this allows the programmer to use more than a single programming language in a project.
Is there a need for doing so? Yes it is, because it make sense to use the strength of each programming language instead of arguing which one is the better choice. For example, Python is by far the most efficient way in creating a prototype. The sourcecode can be written in Python faster than in C++, Java or C#. On the other hand, the Python sourcecode has the tendency to can't be used again. It's an antipattern to write a library with Python, because the performance is not fast enough.
One possible answer to the problem is to invent yet another programming language which is able to combine the strength of C++, Python and Java. Such a language can be learned easily, runs very fast and allows to write a prototype with low amount of code. But the prediction is, that such a magical language isn't available in the near future. Instead the C++ language will always be a compiled language, while Python will be always a scripting language. And Java will be always a system independent language while Javascript will be useful for internet scripting. I don't think, that's possible to replace all the language by a single one. Even C++ is not powerful enough to become a legitimate replacement for Python, Javascript and C#.
No, the answer to the problem of communicating between existing apps is located above the ABI (binary API). It has nothing to do with executing compiled code and it has nothing to do with virtual machines. It has to do with sending data back and forth, similar to the UNIX pipes. Perhaps this comparison is a good introduction into RESTful. A unix pipe allows to connect two different program which were created in different languages. It's possible to pipe the output of a perl script into the input of a C binary file. The question is not, if perl or C is the better language, the problem is located on the transit between both programs.