Python vs. C++

In the past, I’ve written an article in which the comparison was decided against Python. To be fair, this time I want to select a different winner, namely Python. For doing so, we must go into the details. From a technical point of view, the C++ programming language is superior. The resulting binary file is at least 10x times faster, than a Python program. Another feature of C++ is, that the language is standardized. That means, the current C++ compiler can compile everything which was programmed a long time ago. But if C++ is so great, why are the people using Python? According to Stackoverflow, they are using more often than C++. The reason are the following:

– at first, Python sourcecode is easier to read. It looks equal to pseudocode and can be written down in academic papers without executing the code itself.

– secondly, Python GUI apps can be faster developed than C++ apps. There are huge amount of tutorials available for Linux and Windows which allows a newbie to create his first point&click app in Python in under an hour

– third, Python sourcecode needs less space. Around 30% can be saved compared to C++

It seems, that Python and C++ are very strong programming languages. The problem is, that it is hard to combine both. But which language should be preferred for new projects? C++ or Python? To answer this question we have to focus on the bottleneck in software projects. The goal of any project manager is, to let many developers work on the same issue. This will increase the overall speed very much. If one programmer can create 10 lines of code per day, 100 programmers can create 1000 lines of code per day. And if a team is available which is able to produce such kind of new codelines, it is a huge asset. So the question is, in which language it is easier for working together?

The first hint is maybe C++. Because this language was developed with the aim of creating libraries. Most operating system libraries are written in C++. It is possible to compile each module separately and use these C++ library with any other programming language. C++ is a great library development language. But there are major weakness. First point is, that not all programmers are familiar with C++. There are many programmers out there how are fluent in Python or Java but not in C++. Forcing them to use C++ is a bit problematic. And secondly, the ability of using precompiled library is for most projects not important. This has to be explained in detail.

C++ was invented as a classical programming language. The idea is, that the programmer writes sourcecode, converting this into a binary file and use this together with other code. For a well defined task this is even today the most efficient way of programming. The problem with modern software projects is, that in most cases no specification is available. That means, it is unclear which algorithm is right or which GUI interface is needed. Most work done by developers is not the programming task itself, which means to convert requirements into sourcecode, but to create the requirements. That means, modern programming can be described as prototyping. It is a prestep before the coding itself will start. Part of the prototyping step is, to send pdf documents back and forth, to discuss the progress in online forums, to create GUI mock ups and to play around with new algorithms. All these task can be done great with Python. Python is the quasi standard for everything which has nothing to do with programming. Most Python programs are not written to run on a production server but with the purpose to create prototypes.

The idea behind a python app is, that write a quick&dirty prototype and only convert it later to a C++ application, if the software works great. Not programming is the bottleneck but prototyping is the real problem which needs most of the energy. What is prototyping? Prototyping is everything before the application is programmed. That means, there is no binary version which has to be delivered and which has to fulfill realtime criteria, instead the project consists of sketches, pseudocode and non-working algorithms.

In the classical C++ world, the prototyping step was ignored. That means, C++ doesn’t support such kind of programming. C++ was created with the compiler in mind, the precondition of writing C++ sourcecode is, that the developer knows what the correct algorithm is, and that he has discussed the GUI issue with other team members last month.That means, C++ is a great language, if the prototype is there and the final application has to be created. In most software projects this assumption is wrong. That means, the projects starts and no working prototype is there, instead nothing is available and creating the prototype is the first step.

Using C++ as a prototype language is from a technical point of view possible. The new C++11 standard allows to use high level GUI libraries, provides lists and object oriented programming. But C++ can’t compete with the real prototyping language which is python. Because Python is used in algorithm discussions, for matplotlib like drawing tasks and for GUI development. To understand better what the bottleneck in modern software projects is, let us assume a prototype is already there. That means, a Python application is available which contains of working algorithm, a gui and a backend. How complicated is the task to convert such a Python prototype into a ready-to-deliver C++ application? It is surprisingly easy. Such a migration can be done by a single programmer or a very small team of 1-3 developers in a short amount of time. Their only responsibility is to reprogram the existing application in C++. That means, to create software which works exactly like the prototype and can be installed with a package manager.

This programming step can be called the core of programming, because it has to do with typing in sourcecode in the C++ language. The funny thing is, that such kind of Python to C++ migration will never fail. It is simply not possible that the developer will recognize a major problem, because C++ is the most powerful language available. The software will run faster and needs less memory than the prototype. Additionally, the project will need only a little time and little amount of manyears.

If core programming is so easy, why is software development overall so hard? Right, the answer is that prototyping needs 90% of the project time and core programming needs less than 10%. If it’s possible to optimize the prototyping step much energy can be saved. How much is the percentage of C++ in the prototyping step? Right, very few. And that is the reason, why Python is superior to C++. It is enough to improve only the prototyping step and ignore the programming task itself. That means, if the Python prototype is ready, the overall project is also ready.

It is hard to recommend Python as a language for the binary application. The disadvantages of low performance are known, and it is also not possible to create Linux packages out of Python sourcecode. If somebody is doing so it looks not professional. A real application / game has to be programmed always in C++. But it is important to delay this C++ programming step as much as possible. That means, the C++ programming step can wait until everything important is over. In the meantime Python is the better choice. It allows to communicate about the project progress, it allows to test out new ideas easily and it helps to create GUI designs. Using Python as a programming language is a bad choice, because Python is compared to C++ a weak language. But using Python as a case-tool is a great choice. It is a very flexible tool and helps a lot in creating mockups.

It doesn’t make much sense to compare Python with C++. C++ is a language for creating executable programs for example a game which has to be run as fast as possible, while Python is a language for playing around with different concepts. Python can be compared with other case tools (Computer-aided software engineering) for example Matlab, Microsoft Access, UML drawing software and GIMP for drawing GUI buttons on the screen.


Why Linux is great

There are many reasons available why Linux is used so often as a desktop operating system. One of them is the ability to download files with command line tools. A famous example is the new ISO image of the Fedora Operating system. The filesize is 1.9 GB which is huge, even for modern broadband connections. how Windows users are downloading files is unclear, perhaps never or they are clicking on the Windows Explorer on the file and are getting upset if something happens during the download. A Linux user can take advantage of the following command:

wget --continue --limit-rate=20k

There are three interesting features combined. At first, a textual command is used, which can be run in background without any GUI webbrowser. Secondly the downrate is limited to occupy only a small fraction of the possible connection, which means that the total download will need 26 hours. And third, the “continue” parameter is used for resuming a canceled download. That means, the user can download for one hour a bit of the file and stop the process. And two days later he can resume the downloading, this give him the maximum control over the process.

Isn’t it very slow to download a iso file in such a way? No, it isn’t because it is using the given resources in the optimal way. That means, if the user only wants to provide a small amount of his internet connection for that task he can do so. The download task is put to the background and it can be delayed for many days.

The last AI Winter was right

The last big AI winter was there from the beginning of the 1990s. It was a counter-movement to the AI revolution in the 1980s, notably the upraising of LISP machines and Prolog. The AI Winter since the early 1990s can be summarized with that Artificial Intelligence didn’t worked, that LISP machines are broken and that AI has to be ignored. From today’s perspective this was the best decision ever. Let us take a look, what AI experts of the 1980s wanted to sell to the customer.

The AI prophets of the 1980s wanted to make clear, that the future contains of expert system, neural networks and machine learning. With newly developed programming systems like Prolog it will become possible to create a new type of software which is able to do intelligent things. This is the general idea behind the publication of the late 1980s in which LISP machines were marketed to the customer. The only sense-making reaction to the effort to promoting AI was the AI Winter. That means, that the customer declares everything what has to do with AI as not wanted and try out something which is less developed.

The interesting decision since the early 1990s was, that the mainstream computing business made a step backward. That means, not LISP machines and Prolog compilers was bought by the customer, but more traditional tools like 32bit CPUs, GUI tools in C++ and computergames without any Artificial Intelligence inside. That means, the technology in the early 1990s was much higher developed, but the customer decided that he is not interested.

Let us observer what outdated technology from the 4th computer generation can do. With unix servers it is possible to host websites, with C++ GUI it is possible to program business applications and with Turbo pascal it is possible to educate people in structured programming. Nothing of these techniques have to do with neural networks and Artificial Intelligence. It wasn’t the 5th generation but only the 4th generation. But in summary it was a powerful toolset which started the internet-revolution and the expansion of the homecomputer market. So called non-AI technolgy is mainstream today, that means, a standard PC which can do everything except thinking is accepted widely as a useful tool. The upraising of computer technology in the 1990s and 2000s was the result of ignoring Artificial Intelligence. That means, the customer and large tech-companies have focussed on less advanced but useful standard computers. The problem which were solved had nothing to do with expert systems and Prolog but with normal computer programming, for example how to connect a printer to an operating system, how to program a small computer game and how to use MS-Word for writing a letter.

Since the 1990s, Artificial Intelligence is the elephant in the room. That means, everybody know of him, but he is ignored. If we are taking a look in recent published books and take a look what companies are doing all the day, we will find that it has to do with computer hardware, software and programming languages but not with Artificial Intelligence. That means, mankind ignored collectively that Artificial Intelligence thing, they set different priorities.

Since the 1990s, the AI topic was put on the last place and other topics like normal databases, internet connectivity, GUI applications get the most attention.They were discussed in universities, they were asked by the customer and the economy was build around it. From today’s perspective it was a great decision because it allows to develop computing in general forward. AI would need to much energy. In the 1990s it was not possible to bring normal computing forward and Robotics at the same time. If resources are limited, a decision has to be made which is more important. and prioritize Artificial Intelligence on the last rank was a great decision.

How to infiltrate agile organizations?

Classical companies 50 years ago are working topdown. On top of the company is a the central manager which is called the CEO. He knows everything and he decides everything. To infiltrate such kind of structure it is important that the spy gets very close to this key figure, for example to become his secretary and then the spy is able to control the system from the inside.

What modern organizations are doing is to avoid such centralized management culture and establish an open culture. In the literature this is discussed under the term total customer orientation and lean management and means, that the responsibility of the top management is low and most decisions are taken direct by the employees in cooperation with the customers. Sometimes, this management style is called agile leadership or market-driven management because it works from the bottom up. If a spy want’s to infiltrate such decentralized organization it is not enough to come close to the top management. Because the upper management is the last position in the company who will decide something. The only way to take over silently such a company is by manipulating the customer. That means, the customer decides the strategy for the next 5 years, and the customer knows more about the company than the normal employees.

Let us make an example. Suppose we want to infiltrate and take over the Linux kernel. The Linux kernel is without any doubt an agile organization, that means it is customer driven and has no topdown management. To inject a weakness into the kernel, a so called backdoor, it is important to become the customer of the Linux kernel. That means, a large customer has to ask for such a feature and then it will become part of the project. The funny thing is, that the management doesn’t even have to know about such a customer request. All the decisions are done from the bottom up. That means, it has to be negotiated between a customer and a low employee of the LInux development team.

How to create a Forth standard

Update 2018-11-18
Poll is over, “How to create a Forth standard” has won with one vote. Here comes the text.

The official Forth-200x standard is out there and is a 300 pages pdf documents which contains some basic words. The problem is, that nobody in the Forth community accept this standards, and attempts to pushing it in the world will fail. On the other hand it would make sense to support Forth but how can this be done without a standard?

The answer to the problem is not the technology itself, but the ecosystem of programmers around it. Let us go into the details. The MenuetOS project is a good example for a working gui which is not Linux. MenuetOS was programmed in assembly which is similar to Forth, but not so powerful. The more important question is not the MenuetOS kernel itself, but the number of people who are writing software for it. What would happen if somebody is reprogramming MenuetOS in Forth? At first, it is a great idea because the same code will run on other architectures than only x86. But this newly developed project will fail if the number of people who are contributing code is too low.

The main advantage of Linux and the C programming language is, that many thousands (or millions) programmers are there who are familiar with the ecosystem. In case of Forth this is not the case. That means, on the first hand we have a stackbased programming language which is great for software development and uses existing hardware efficient and on the other side nobody is interested in Forth. To bridge this gap modern tutorials are needed. The problem with Forth is, that nobody is able to explain it to the masses. The tutorials about Forth are bad written and most are outdated. And if nobody is teached in programming Forth he is not able to write sourcecode from scratch.

The first step in establishing a Forth Standard and a Forth operating system is to write a book about Forth which is easy to read and explain the basics to the newbies. Animating somebody to write Forth code is equal to teach him the Forth language. The easiest way in do doing so is to explain Forth as an advanced assembly language. An appropriate book title would be “From x86 assembly to Forth”. That means, the requirements in learning Forth are average assembly skills and with that background knowledge it is possible to explain how to use this skills in a Forth environment.

Let us take a closer lock to Assembly language. The main advantage of assembly language is, that it is a minimal language. An assembly program can be executed without an operating system. It communicates on the hardware level with the cpu. One of the reasons, why Forth was used in the 1980s more often but since the 2000s seldom has to do with the changed status of Asembly programming. In the 1980s it was common to program in Assembly. For the Commodore 64 it was the mainstream language, but many MS-DOS programs in that days were created as well in machine code. Another similarity between Forth and Assembly is, that both languages are compact. That means a typical program has not more than 2 kb in size. Such a program can be called a huge project which takes many weeks to program it.

If somebody wants to bring Forth forward, he has to connect to this programming style. If somebody doesn’t want to learn assembly or someone argues, that a hello world program needs 2 MB in size, he is not ready for Forth.

Forth tutorials

The demand for better Forth tutorials is easy to formulate but how exactly would such a book look like? The problem in modern computing environment is, that even the Assembly language is hard to teach. The current standard book about AMD64 assembly programming is not a single volume but a series of 6 books with each 700 pages. And that is only the reference manual for the opcodes, if somebody needs more detailed explanation how to code a hello world example and assemble it into binary code he needs additional material. Even our fictional user has read all the information, he is only able to write assembly language but he has not written a single line in Forth. Then he will need more books.

The Forth community itself has recognized this problem and as a counter reaction they have invented new cpu chipsets with a smaller amount of commands. The novix cpu is a famous example but also the modern GA144 chipset is compared to the AMD64 a small device. The problem is, that these architectures are more complicated to understand than the AMD64 chipset, because they are more advanced. If somebody is trying to describe them, he will need the double amount of books and they will much more complicated to read. It seems, that especially a programming language which is simply and especially a cpu with has a low amount of instructions is harder to describe than current one.

Unfortunately, nobody knows how to overcome the problem. What we see in reality is, that 99% of the programmers ignore Forth and write their hello World application in Python, because they don’t want to read so much information and they have no need for a lightweight cpu. That means, the number of Forth programmers today is smaller than in the 1980s and the prediction is negative.

Let us take a look how complexity is handled in the C programming ecosystem. There we have many layers which are put on top of each other. The layers are called microcode, firmware, bootlooder, operating system, GUI, system library, device drivers, compilers, programming langauges and more programming languages which are using languages below them (Python is an example for that). That means, it is a mess. And Forth programmers are right if they are calling the C / Linux ecosystem outdated.

The problem is not Forth itself, the problem is, that the average programmers would not renounce on a single layer. For example, suppose somebody programs software in Python. And we want to convince him, that Python is inefficient and that C is the better language. That means, he can write the same code direct in C and it would compile to much faster code. He could save one layer in his workflow. The answer is, that he doesn’t like C. That means, he wants to use Python and he will ignore the additional layer. Now suppose we want to teach the programmer not only to avoid Python, but also C, also the operating system. What would he say? He will not love it. That means, the programmer is trained in a certain style which has to do with additional layers, but not with slim programming.

What Forth wants from the programmer is to forget all the layers. And not using Python, not using C, not using Linux, not using x86, not using GCC, not using register machine and instead rethink programming at all. How many people like this? Not very much.

Forth on Brainf***

The most simple Computer isn’t the MOS 6502 CPU but a turing machine, better known as Brainf*** computing model. It contains of a tape, a read/write head and simple left/right commands. The commands are the assembly language of the computer. They fit on a single DIN A4 paper which makes things more easier to grasp. But from a certain point of view, a Brainf*** computer is much harder to program than an AMD64 chipset. Because sometimes small is more complicated.

With Forth the programming can be improved. All what we need is an Forth interpreter on top of the Brainf**** computer, and now we can enter a Forth For loop and this gets executed on the Brainf*** cpu. Without any compiler in between. Sure, the Forth Interpreter works as an interpreter, but he needs not much space.

This flexibility of Forth is the reason, why the language is so fascinating. Any device which is turing ready can run Forth. And there is no such thing than something below Forth.

But if Forth is so great, why are using only a few people this powerful language? Doesn’t they know what the advantage is? Oh they know Forth, but they can’t handle it. They find it easier to design chips with many registers, and they like it more to program in C++ but not in Forth. The funny thing is, that they even prefer to write a software which has 1 million lines of code instead the same software in Forth which needs only 2000 lines of code. A possible explanation was given in the previous chapter. It is the same reason why people are prefering Python over plain C, even a compiler generates better code. What mainstream programmers want is as much layer they can get. They do not want to program on bare metal they want to write in a python like style.

Python is a good example for what is wrong with modern computing. According most benchmarks, Python is 20x slower than C. Their object-oriented features are not better than C++, and the Python virtual machine is compared to Java not very well. That means, from a technical point of view, Python is bad programming language. But the people love it. All the beginner worldwide are learning Python, but not c, not C++ and not Java. Are these guys wrong? Yes they are. Python programmers didn’t have understand what a C++ compiler is about. And they are proud of it. Instead of arguing with C++ guys about the better programming langauge, the Python fanboys have build their own world. And it is likely that the Python community will grow in the future. That means, the Python programmers are different from C++ programmers.

And the same game is played with Forth. The opposite is, that Forth is ignored by much more people. Java programmers hate Forth, Python programmers hate Forth, C++ programmers hate Forth, even Assembly experts hate Forth. If somebody want’s to stay alone in front of a computer, than Forth is the gold standard. He can be sure, that nobody else want to see his code, especially if the code was written for a special Forth dialect created from scratch, like Colorforth.

This brings us to the question: what is the advantage of programming alone and without a huge community? It’s the same question like why somebody walks alone through the snow and climbs a mountain. The hope is to explore something new. And Forth is something which is new. Colorforth for example was the first minimalistic Forth ever invented. It should be put in a museum and teached to future generations.

About which kind of technology the Forth community is talking?

For the newbies it is very hard to understand what Forth is about. They see only a programming language which is hard to master but they don’t recognize the advantage. So what is Forth, if we want to define it in colloquial terms?

The software side is comparable to projects like MenuetOS and ContikiOS. Both are example for small scale operating system which needs less then 2 MB on the harddrive but provide a full featured TCP/IP stack, a webbrowser and a GUI. MenuetOS was programmed in Assembly language while Contiki was programmed in C. But it is possible to reprogram the software in Forth. The result is a very tiny fast booting operating system which is able to do everything what a Linux OS provides.

The second aspect of Forth is the hardware. Running Forth software on normal x86 cpus doesn’t make much sense. The idea is to create a different kind of processor which needs less gates, consumes less energy and is cheaper. Now we have a basic understanding what Forth is: we are taking a cheap CPU, put a small operating system on top of it and get a computer which is superior to today’s mainstream computers.

That is the general idea behind Forth. And most discussions and Forth related talks are about certain aspects of this vision. A more mainstream compatible but not Forth related approach would be to stay within well known c programming language and create an operating system which takes less memory. The ContikiOS was mentioned above, it is so small that it can run even on the Commodore 64. The idea is to minimize the footprint of the software. That means, everything which goes into the direction of creating an operating system in under 100 kb is great, while normal Linux compatible operating systems which takes 500 MB RAM only for booting the terminal is the wrong way.

With the C programming language it is possible to program small kind of software. But if the idea is to reduce the footprint further a switch to the Forth language is necessary. The reason is, that a C compiler is a huge piece of software and it won’t run for example not on the Commodore 64. That means, the ContikiOS needs a crosscompiler. Forth can help to bypass this problem.

It remains the question open if its make sense to create ultra efficient hardware / software. Why do we need an operating system which takes only 100 kb? This is indeed a bottleneck, because this kind of software is hard to program. It is additional work which has to be done. And it is possible to argue against such kind of projects. This is the reason why Contiki, Forth and similar projects are called a niche project. They have not encouraged a large group of programmers.

If nobody press the vote button, a Python random generator gets started.

import random
class Randomgenerator:
  def __init__(self):
    print random.randint(0, 2)

main = Randomgenerator()

Programming with Turtle graphics

Update 2018-11-15

Nobody has pressed the vote button. The Python random generator prints “0” to the screen. The article “Programming with turtle graphics” was selected. Have a nice day.

Suppose, somebody has never programmed before and want’s to learn it in 60 minutes. At first we have to decide for a programming language, which is Python. It is the most widely used beginner language and contains everything like object-oriented programming, graphics output and string handling. The second ingredients is a small task, which can be handled in a low amount of codelines. The aim is to control a turtle on a graphics screen. Python comes with a pre-installed library to support this feature. An example program is given in the screenshot.

The newbie has to type in the program, press the run button, and he will see that the turtle is moving on the screen. The most important thing is, that no complicated things like functions or classes are used. Instead the program is equal to a macro. That means, the commands are ordered in linear fashion, and the turtle will do exactly what the user wants.

According to the picture, the turtle has drawn a line to the screen. Very nice, but we can do it better. The reason why programming is so powerful has to do with so called loops. A “for loop” is a magical thing, which allows to do the same thing more often. Using a for loop means from a technical point of view to repeat something, but from the programming perspective a loop is equal to write more powerful programs.

In this example, the previously introduced for-loop was used. A more complicated example is to increase the number of iterations to 100:

Very easy, isn’t it? The reason why this setup is so powerful has to do with the combination of an operating system which is already there, a programming idea, the python interpreter and the turtle package. All these combined together results into a programming environment which is understandable for everyone. It’s like drawing with a pencil on a paper, only with a random generator.

What else can we do with the turtle graphics? Very much, even without introducing new Python commands it is possible to re-arrange the given statements in a new order. That means, we can use the sourcecode and write a new program. Which has perhaps a longer “for loop”, a different random generator or a new kind of step size.

Most expert programmer would argue against the claim that drawing a turtle graphic in Python has anything to do with programming. Because this task doesn’t contain pointers, compiled languages, threaded code or GTK+ programming. And yes, the official term for drawing turtle graphics is not programming but “ingame scripting”. Which means, that the program is already there, namely Python, the operating system and everything else and we’re only modify existing content like selecting the color in a game. The idea isn’t to create any useful program but to playing around with a game. The learning is more important than creating the sourcecode itself. If we are done with the graphics we can delete the sourcecode, there is no need to check out the Python code into a git repository or using a bugtracker.

In the case, that nobody press the vote button, I’ve updated the random generator. Instead of programming it in C++, the new language would be Python. It’s not the best choice, because Python is known as insecure and slow but it’s easy to write the code. And Stackoverflow loves the language. They have many thousands of threads about the language, and if something is wrong with the code, i can copy&paste it in a question and get help in under a day.

import random
class Randomgenerator:
  def __init__(self):
    print random.randint(0, 2)

main = Randomgenerator()

Subjective list of most innovative companies

Update 2018-11-10
1. Google for the search engine, Youtube and for Google Scholar

2. Red Hat for bringing open source forward

3. for revolutionizing Open Science

4. Wikipedia, for bringing high quality content free to the world

5. Springer publishing, for driving the science community forward

6. Apple because they have invented the iphone

7. OpenAI for putting Artificial Intelligence into the mainstream

8. Opencog foundation, bringing AGI forward

9. Pixar, because they have programmed the animation software “Menv”

10. Forth Inc has developed a stackbased programming language

11. Raspberry PI Foundation for marketing a cheap beginner friendly Mini-PC

12. github for promoting opensource software

13. Stackoverflow for connecting programmers

14. Python Software Foundation a nonprofit organization to accelerate programming

15. Association for Computing Machinery (ACM) which publishes a lot of journals and is the sponsor of the SIGGRAPH conference series

Here is the of the C++ random generator which gets started if no one press the vote button:

#include <iostream>
#include <random>
class Randomgenerator {
  Randomgenerator() {
    auto number=rand()%3; // between 0 and 2
int main() { 
  Randomgenerator mygenerator;