January 25, 2020

Node.js for Python programmers



The main reason, why Python has a large amount of users is because it combines a prototyping language with object oriented programming. Similar to C++ and Java the user can create objects and classes which allows to realize more advanced projects compared to purely procedural programs. On the other hand, Python is more easily to learn than C++ because the syntax is a high level one. The combination of both feature explains most of today's widespread usage of the Python language.

What many people doesn't know is, that node.js and Javascript is the better Python. Similar to Python it can be used as a prototyping language. An easy example is the canvas element in HTML which allows to program graphics and even graphics animation. At the same time, Javascript is capable of object-oriented programming which allows to create large scale apps. It's main advantage over Python is, that the underlying virtual machine is really fast. It outperforms Python easily.

It's not very hard to predict, that Javascript will become the most successful language which will get used by more users than Python, PHP and Java combined. The only language which can't replaced by Javascript is Forth. Forth is a different language which is more powerful than Javascript but more complicated to learn. The reason is, that Forth can be realized on different machine architecture and provides it's own operating system. This is not possible with Javascript.

The reason why Python but not Javascript is widespread used in the year 2020 has historical reasons. Javascript and especially node.js are very young projects. The 1.0 version of node.js was released in 2010 and most programmers have decided to ignore it because they are familiar with classical back end language like C++, Java or Ruby. The comparison between classical language was focused on the question if compiled or modern scripting languages are the prefered choice. C++ programmers are convinced that only compiled languages are providing the maximum performance, while Python developers emphasize the advantages of an interpreted easy to learn language. The discussion about the pros and cons was easily because both paradigm had clear features. Python is a slow language, but can be written fast. While C++ is complicated to learn but can be executed fast.

The node.js framework is something which outperforms both languages. It's easier to program than C++ and it's faster then Python. This makes node.js the perfect choice for all applications. Additionally it runs under all operating systems, can be used for backend and frontend development, supports object oriented programming and has a large amount of libraries. The only thing what is missing in the node.js ecosystem is a long history and reference handbook which are introducing the subject to a larger audience. What we see today are some quickly created examples of Javascript code distributed over the internet. The result is, that the average user thinks, that Javascript isn't a real programming language but something which can be ignored.

From a birds eye perspective, node.js is the successor to Python 3. The virtual machine was programmed more efficient and it runs on different operating systems. The main feature is, that Javascript is used for creating productive code. That means, it's a prototyping language and a practical language at the same time. There is no need to rewrite existing Python code in C++, but the same Javascript code is used at the production server. This simplifies the programming workflow.

From the technical perspective it's pretty easy to write a hello world program in node.js. All what the user has to do is to type in the sourcecode into the normal programing IDE and configure the execute button with the nodejs interpreter. A click on run will work similar to execute a python program. That means, no webbrowser is needed, and if an error is there is will be shown in the console log. The difference between Python sourcecode and Javascript is minimal. The user has the choice if he likes to introduce functions or complete classes into his project. He can create a GUI application in html javascript or he can decide to write a GTK+ application for the normal desktop environment. That means, nodejs can be used outside the context of web-programming very well for normal desktop applications. If the user likes he can create additionally complex LAMP applications which are utilizing an SQL server and multithreading. But newbies can start with a normal logo graphics project as well.

The good news is, that in the past it was tested by different user how nodejs performs in comparison to Python 3. The answer is, that nodejs is 20x faster than a Python 3 program, https://stackoverflow.com/questions/49925322/significant-node-js-vs-python-3-execution-time-difference-for-the-same-code That means, nodejs is at the same speed like C or even a bit faster. And the examples measures only the cpu performance not the performance of a webserver which is working with parallel threads. The advantage of nodejs is here much more visible.