January 28, 2020

bug nodejs is slow

For testing out the performance of node.js a simple prime number generator was programmed in Javascript and in C as well. The node.js version has reached the half of the speed of the C version. During runtime, the cpu was utilized by 100%. The problem is, that node.js is not a native compiler but was written in C++ which is interpreting the Javascript code during runtime. The result is, that node.js is not able to reach the same performance like C++. For high performance applications the language is not fast enough.

/*
gcc -O2 prime.c
time ./a.out > out.txt
real 0m14.145s
user 0m14.120s
sys 0m0.006s

*/

#include stdio.h
int min=2, max=500000;
int main() {
  int flag;
  for (int i=min;i
    flag=0;
    for (int a=2;a<=i/2;a++) {
      if (i%a==0) { 
        flag=1;
        break;
      }
    }
    if (flag==0) printf("%d\n",i);
  }
  return 0;
}
/*
time node prime.js > out.txt
real 0m26.749s
user 0m26.641s
sys 0m0.127s
*/

var min=2, max=500000
for(var i=min;i
  var flag=0
  for(var a=2;a<=Math.trunc(i/2);a++) {
    if (i%a==0) { 
      flag=1
      break
    }
  }
  if(flag==0) { 
    console.log(i)
  }
}

January 27, 2020

Understanding how Wikipedia works

Instead describing the website from it's own perspective the better idea is to take a birds eye perspective and observe what the role of Wikipedia in a capitalist context is. The education sector which includes universities, private owned libraries and book publishers is operating as a for profit business. That means, a book publishers likes to earn money and a university takes the money from the students to pay the rent of the building. If the management of a book publisher is doing everything right, the company generates revenue and is able to pay all the bills. This is equal to run a successful business.

Some companies, which are less then 10%, are not managed good enough. The financial situation looks bad, and in the past some wrong decision were made by the top management. That means, the company doesn't generate a profit but a loss. And here comes Wikipedia into the game. What Wikipedia is doing is to meet universities and unprofitable book publishers to explain them the benefit of free knowledge. For example, if an academic book publisher goes into bankruptcy, the content which was generated by the employees has no value anymore and can be transferred to the Open educational resources platform. And if a university with a long tradition is no longer able to pay the bills, the former professors and students are angry against their institution and they are invited to contribute to the Wikipedia website with their knowledge.

Basically spoken, Wikipedia is not a successful company but it's some kind of failed project which is feed with negative information. Between a well running academic publisher and Wikipedia there is a large gap and this gap is a good idea, because the book publisher has understand what capitalism is about. The idea of capitalism is to make profit, to earn money and to grow. It's about become rich and famous and be competitive on the market.

To understand what the difference between success and failure is, we have to describe the mechanism of the value chain. A normal company for example a university, gets money from the students and pays the money to the professors. That means that the professor is paid for his work. If the professor is doing a good job and the university is attractive to the students, the company is able to increase it's profit. In contrast, WIkipedia and Open Science in general isn't operating under such constraint. Basically spoken, WIkipedia is an anti-cooperation.

Let us listen, what the Commercial Manager of Swets has to say about the future of academic publishing. Swets was a dutch content broker for libraries which runs into bankruptcy in 2014:

quote: “The pressure is high. We expect more and more from them. Nobody likes to change really. But if you bring change in a positive way, that's important.”, source “Swets Enjoys Change: Changing the view”, https://www.youtube.com/watch?v=M9BgD0FcSCY

Why Wikipedia is wrong

The main problem with Wikipedia is, that the project is not focussed on getting famous and earning money. In contrast to established universities like Stanford and respected academic publishers like Elsevier the primary concern is not to increase the monetary value but to provide information for nothing. That means, Wikipedia isn't a success machine but it's the opposite. It's a community of loosers.

The reason why the Elsevier company aren't contributing free medical content to Wikipedia is because Elsevier has understood how capitalism works. It has to do with earning money, become rich and famous and stay on top of the wave. Wikipedia is doing the opposite. They are doing everything wrong and as a result it is respected by no one. Ask authors to write an article for free and putting high quality content under a CC-BY license is some kind of anti-pattern in academic excellence.

The only way to interact with WIkipedia is to boycott the project. Or at least to stay away from it. If a university is announcing an intensive partnership with Wikipedia this is equal that this university is in trouble. They have no future in the education business and have lost the competition with other universities.

January 26, 2020

Building a simple webserver with node.js



The node.js virtual machine is a practical tool for creating server applications. A simple hello world example is given in the screenshot. To make things more interesting a for loop is used to generate a list which is redirected to the webbrowser. The most advanced feature of nodejs over normal Javascript is, that the program can be tested and improved in the IDE. It's possible to bugfix the function until it works great, and then the webbrowser can show the output from the user perspective.

The workflow for creating sourcecode is very similar to Python, that means, node.js is able to replace the Python language. The only disadvantage is, that the amount of Python tutorials is higher and they have a better quality than the few node.js tutorials. That means, the nodejs community isn't available but it has to built from scratch. To shorten the explanation a bit we can say, that the programming language in 2020, in 2021 and in 2022 as well is node.js/Javascript. That means, the advantages over normal Python is so overwhelming that every Python user will migrate to Javascript in the future. The same is true for C++ programmers, Java programmers and of course all the C# programmers.

To understand the node.js ecosystem we have to focus on failed classical programming languages. The Python language was an early to attempt to build a scripting language which supports object oriented programming. Before Python was there, object oriented programming was the same as compiled programming with C++. The perl language was known, but it wasn't supporting classes. Python has replaced Perl entirely.

But Python struggles in the performance. The Python virtual machine was always too slow. It was not able to compete with Java or C++. So the community was divided into users how are preferring Python and other who not. We can say, that node.js has solved a lot of problems. It contains of the following features:

- the performance is very fast

- it is a scripting language with fast edit-run-cycles, no need for compilation

- it runs under different operating systems with the same code

Basically spoken, nodejs combines the advantages of Python, Java, C++ and PHP into a single language. Similar to Python it can be mastered by beginners. Similar to Java it runs everywhere, similar to PHP it is very good in creating websites and similar to C++ it is very fast. The prediction is, that nodejs will replace all these languages. Or let me explain it the other way around. It's not possible that a node.js programmer will switch back to PHP if he is familar with Node.js already. That means, there is only one option towards node.js but not the other way around.

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.

A personal tiobe index

The original tiobe index with the most famous programming languages is given here https://www.tiobe.com/tiobe-index/ My personal ranking looks different:

1. AutoIt. A macro language used for Windows scripting. The Autoit community is building aiming bots for the purpose of leveling and harvesting videogames.

2. Forth (the most powerful programming language ever invented, it's widely used by expert programmers and difficult to learn)

3. Javascript (the nodejs runtime engine has introduced Javascript to a wider audience and can replace outdated languages like PHP and Java)

4. PDDL, a planning language for building advanced robots

The Commodore 64 lives forever

Sometimes it was argued, that the Commodore 64 homecomputer wasn't a big innovation at this time. Other computers for example the Apple II was more impressive, and the Unix system V operating system was superior over the Commodore 64. But can we compare the C-64 only by it's technical specification? It's important to mentioned the complete picture. Most users are not interested in the machine itself, but they are were fascinated by the additional equipment.

In the basic form this is equal to some games, a device for making punches into the floppy disc and a joystick. But the most interesting equipment for a Commodore 64 was the books published in that time. If we are taking a look into the journals and printed books of the 1980s we will perceive a surprisingly powerful community. There were books available how to program text adventures in Basic, how to use the Geos software, how to make music with the SID chip and even graphics programming in Assembly language was explained in the books.

What is often ignored is, that it's possible to read such books without using a real commodore 64. That means, the books but not the 6510 cpu was the most fascinating part of the Commodore 64 legend. These books wasn't available before the Commodore 64 was realized. They are discussing subjects like a database, game programming and mathematics from a certain standpoint which was the beginning of the home computer revolution.

Another interesting fact was, the books about the Commodore 64 were available in normal bookshops and even in public libraries. The 1980s was the first decade in which such literature was produced.

The future of Open Source licenses

There are two major Open Sources licenses available, the MIT License and the GPL license. The advantage of both licenses is, that the user get access to the sourcecode. He can read the code and he can compile the binary file from scratch. The disadvantage is that problems are upraising if the end user forks an existing software project. Let us go into the details.

In the easiest case, the enduser is interested to download, read and execute existing sourecode. This is possible with the MIT License and the GPL license very well. Both licenses are written for exactly this purpose. The created code can spread freely over the internet and the costs for the end user is low.

The bottleneck is visible if the end user tries to do more with the sourcecode than only execute it on his computer. This is called forking. Forking means, to build on top of the sourcecode a new program. In the domain of software engineering, a library is linked into the own program and then the new software is distributed. If the end users is planning to do such things, he will run into a lot of trouble.

This is the case of the MIT License and the GPL license as well. The reason is, that every piece of code was written by a person, and the person holds the copyright on this code. Suppose, the idea is to use the libc library in the own project. The libc library is copyright protected. That means, a person in the world holds the copyright. And what is allowed and what is forbidden with the code is defined by this person. In case of the libc, the LGPLv2.1 license is valid https://en.wikipedia.org/wiki/GNU_C_Library Other library are available under a MIT license. What will happen in any case is, that after the library was used in a new project, the original author will check if the new project is fulfilling the license. That means, the enduser is not really free, but he has to negotiate with the license holder.

Suppose, the enduser is not interested in doing so. Suppose the idea is to fork an existing project and do not talk to the original author. Unfurtunately, such a software license is not available. No matter if the project was licensed under MIT, GPL or anything else, in all the cases, the copyright is reserved for the original author. The reason is, that it is a demanding task to write software. If the sourcecode contains of 100k lines of code, many manhour were invested in the past. And the copyright is protecting this invested time.

The only option for the end user to become independent from the original author and the Open Source license is to reinvent the code from scratch. That means, the user has to program it's own libc library from scratch which doesn't use the original sourcecode. That's the reason why the SCO vs. Linux case was openend a long time ago. Reprogramming software from scratch is the only option if somebody needs completely freedom from the original author.

The problem is, that even with modern software development tools like compilers and well documented sourcecode it's a demanding task to reprogram a software project from scratch. In a science fiction movie, the programmer would start a code generator which will produce it's own version of the Linux kernel. That means, the code generator gers some constraints as input and it will produce software from scratch. The software is different from existing sourcecode, so it's not copyright protected. This gives a hint how the future of Open Source will look like.

Today's licenses like the GPL license are protecting fixed code stored in files. The more advanced technique is to develop code generators who are able to produce unlimited amount of code. The generated code is new and it's not protected by the copyright law at all. This can be imagined as an advanced level generator in the Mario AI challenge. A level generator is able to produce a meaningful map from scratch which is different from any level created before. This newly generated game-map isn't protected by a software license. The problem with the Linux kernel, the glib library and most other Open Source projects is, that tha code wasn't generated automatically but it was typed in manually, and therefore it's possible for the original author to protect the code with a software license.