July 15, 2021

What is object oriented programming?

It seems, that object oriented programming has so many advantages and it is used so frequently that it has become hard to explain what the idea is. Especially non programmers find it difficult to get the advantages of the C++ language over existing paradigm which is structured programming.
In a single sentence, object oriented programming allows to use of global variables.
A global variable is a memory adress used by more than a single function. The same variable can be accessed from different subroutines of the program without sending the variable as a parameter to the function. A typical example consists of one or two struct variables which are accessed by three upto four different methods. The combination of the variables and the methods is creating a program within the program called class.
So the logical next question is, what should somebody need a global variable? In the classical structured programming technique global variables are not recommended. They are perceived as a wrong idea. The more likely paradigm is to provide the variable as a parameter to the function header. So the function can only manipulate objects they were provided in the heading.

July 12, 2021

Will Microsoft take over Debian?

From time to time it is interesting to observe what the Debian community is doing. The upcoming Debian 11 distribution has found many fans and some of the users have installed the .iso file already even it wasn't released as a stable version yet. This behavior is common, because Debian is by far the most reliable Linux distribution and it makes sense that Linux enthusiasts are trying out new versions.
But one thing is new. It seems, that especially since the announcement of the Debian 11 distribution many new users have discovered the Debian ecosystems which were used in the past the Windows operating system. in addition, Microsoft plays a more active role in promoting Free and Open Source software. Similar to google they are explaining on their own website how to download and install a .deb file which contains the latest version of the Visual studio software Visual studio is the most important IDE for creating software under the Windows operating system.
We can only speculate in which direction this development will go in the future. What we say for sure that the former conflict between Linux and Windows has lowered a bit. That means, that at least some users are switching back and forth between Windows and Debian and recent versions of the package managers are making such attempt very easy.
To understand the importance better it makes sense to give some background information about the Debian ecosystem. in contrast to the Windows world, Debian is missing of third party applications. The amount of software (games, applications and edutainment programs) for the Debian operating system is low and even very very low. Debian has not something which is comparable to the Windows store or the Android store. The only thing what Debian users can install on their machine is a small amount of flagship software which is mostly gimp, gcc, apache and libreoffice. If somebody needs more applications he has to leave the Linux ecosystem and has to boot the Windows OS.
This missing software for Linux is the main reason why the market share on the desktop is around 1% worldwide. inventing a software store for Linux which provides thousands of games and desktop applications is equal to make Linux great again.

July 11, 2021

Dictionary in C++ and in Python in comparison

The C++ version is faster, of course.

map.py
#########
d={
  "A":{"one":0, "two":0, "three": 0,},
  "B":{"one":0, "two":0, "three": 0,},
}
for i in range(20000000):
  d["A"]["two"]=5
  a=d["A"]["two"]
  #print(a)

map.cpp
###########
#include <iostream>
#include <map>
#include <string>
#include <string_view>
// g++ -O3 -std=c++2a map.cpp
 
int main()
{
    std::map<std::string, std::map<std::string, int>> d;
    d["A"]["one"]=0;
    d["A"]["two"]=0;
    d["A"]["three"]=0;
    d["B"]["one"]=0;
    d["B"]["two"]=0;
    d["B"]["three"]=0;

    for (int i=0;i<20000000;i++) {
      d["A"]["two"]=5;
      int a=d["A"]["two"];
      //std::cout<<a<<"\n";
    }
}

July 10, 2021

Simpler programming with groovy and python

The programming community consists of two opposing group. The first one are old school programmer who have learned programming in the 1980. This group is familiar with Assembly language, C and sometimes the C++ language is used for creating modern desktop applications. This approach to writing software can be called a professional one because it garantees the maximum performance and is used to create large scale productive programs.

On the other hand, there are programmers who are not calling themself developers because they have never learnt to write code in C or Assembly language. The difference between both groups can be made visible by the different understanding of a pointer. Only the real programmers can explain what a pointer is, and they have used them all the time. Pointers are used for creating faster games and handle lot of data in a program.

The interesting situation is, that it is not possible to learn C/C++ or assembly without understanding pointers. They are a fundamental part of these language. To write anyhow a program a different sort of programming language is used. Typical examples for recent programming languages are groovy, python, matlab, javascript and Autoit. What these languages have in common the user has to enter only a little amount of code, and the written code reads easier.

A typical example is to compare a swing gui written in java, with a GTK+ gui written in C. The c code needs 4x more lines of code, and ofcourse the pointer operator * is used everwhere. In contrast, Groovy and especially python are much easier to read.

There is a reason why the scripting languages haven't replace real programming languages. Because a scripting language is using a lot overhead to reach the same goal. They are not a minimalist language like Assembly, but before groovy can be executed lots of programs have to installed first. And all of the underlying programs like operating systems, Virtual machines are written not in groovy but in powerful languages like C, C++ and Java.

July 08, 2021

Describing LaTeX from the workflow perspective

Instead of explaining what the LaTeX software itself is, it shoud be mentioned that without third party programs, the user can't create anything. Before the latex command line tool can be started, the text has to be created in a text editor. There are not a single but a lot of external text editors available:

- emacs with latex plugin, vim with latex plugin, texnic center, overleaf, Lyx, texmaker and many more
It is interesting to know, that latex users are not starting latex itself, but they are using both. The text editor and the latex backend. It is possible to find similarities between the mentioned editors. What they have in common is, that they can be classified as advanced outline editors. The reason is, that all of them are providing on the left pane a hierarchy tree with the document structure. In the right window the sections are shown and sometimes the latex preview is shown in a third pane.
So what is the idea? The idea is, that the user creates notes in a plain text format. Then the notes are structured into chapters, and then the text is rendered into a scholarly paper.
From an abstract point of view the idea behind texnic center, lyx and overleaf is, that the user types in structured plain text and doesn't care about the formatting. If the text file has reached a certain size for example 200 kb, the user can render the file into a pdf file.
The latex community describes this workflow as seperation between content and layout. Before they are formatting the document into a pdf file, they are taking care of the content. LaTeX allows much better than other typesetting systems to divide the article creation process into these two sub tasks.

How to avoid pointers in programming

 

Pointers are everywhere. They are used for creating C code, C++ has them and even the assembly language needs pointers. The reason why pointers are there is because of technical reasons. They are mapping variables in the sourcecode to a physical memory address.
It is some sort of inside joke if C++ programmers are told to avoid pointers. This recommendation can't be realized. What programmers are doing instead is to create variables on the stack (which is not recommended). They are using shared pointeres (no obvious advantage over the classical raw pointers) and they are using the well known * and & operators which produces core dump messages all the time and the code becomes unreadable.
The only language not using pointers is python and perhaps this explains why the language has become so famous. How can it be, that Python doesn't need pointers? Because the python interpreter is using pointers internally and hides it from the programmer.
Perhaps it makes sense to compare the edges in pointer programmers. On a low level layer it is possible to write a program in the assembly language which is using pointers for getting access to the arrays in the memory. A simple hello world program will need 100 lines of code and needs additional comments to understand what all the move, push and call statements are doing.
On the other hand, a python program can do the same task in only 5 lines of code but has the advantage that it will run much slower. The C++ language is located somewhere in between.
From the history of programming language it can be shown how pointers are handled over the years. In the beginning there was only assembly and C. Assembly is great for writhing small amount of efficient code and C makes sense for writing larger software like operating systems. The only problem is, that both languages aren't fulfilling the requirement of modern programmers. The reason is that programmers are not interested in writing a single C application but modern software development is about writing thousands of software projects.
The surprising situation is, that even programmers newbies are doing so. They want to create not a single game, but the average newbie likes to write 5 different game, a serious gui app plus some web applicatations in under a year and he has no knowledge about programming at all. The C programming language can't fulfill these expections. It was designed only for writing low amount of projects.
Since the 1990s the C++ language was invented which can - in theory – fulfill the expectation of writing high level applications. but only the python language has fulfilled the demand for modern programming languages in the reality. Because python combines an easy syntax with object oriented features. Instead of advocating the usage of python it makes sense to ask in general what modern programming is about.
An interesting but seldom used example for a modern programming language is groovy. Groovy is the result of many layers which are put together. It will need an operating system, a java VM, some gui libraries and then the groovy code can be executed. Similar to python the amount of needed codelines for creating a game is low. And no pointers are needed beause it is handled by the underlying architecture.
The promise was to compare two very different programming approaches. The concrete question if assembly language or groovy is the better programming language. In terms of easier to use the groovy language wins the comparison. Even newbies are able to write their first program within minutes. The main idea is, that all the complicated problems are hidden from the user in underlying layers. Groovy puts the programmer in a sandbox and he doesn't care about performance, memory management or compiler options.
An unsolved problem of high level programming languages like python was in the past that the execution speed is low. In case of groovy the problem was solved because groovy can be compiled into native java code.
A typical sign for a modern programming is the reduced amount of needed codelines for creating something. In most cases the user can include a library and call a method which needs 2 lines of code and is pretty easy to read. To provide such high level functionality, many underlying software is needed which is an operating system and lots of in between virtual machines. For running a simple python or groovy example, the user has install around 10 GB of software before.
So the question is, how was software developed in the 1980s in which the typical 8bit computer was equipped with 40 kb of RAM? The answer is that at this time, a single programmer hasn't created 100s of apps but only 1. And in most cases he was part of a team so the programmer has created only a function in an assembly program.
Let us investigate what todays programmers are trying to archive. A typical entry level project for a groovy newbie is to rewrite 30 existing arcade games in groovy. That means, a single programmer is doing in a month the same task done by hundred of assembly programmers in the past. And because of this highly difficult problem, modern programmers are searching for programming languages which needs a little amount of written codelines.
There is an interesting situation available for programming languages popularity. Old school languages likes Ada, C++ or Assembly language are loosing it's popularity while modern beginner friendly languages likes javascript, python and java have found acceptance. This is more than only a fashion but it has to do with changing demands.
Let us make an example. Suppose the idea is to write 20 different GUI applications and use Assembly as the programming languages. it won't work. It wil take years until the newbie has learned the language and writing all the code will take decades. The combintation “writing 20 desktop apps and the assembly language” doesn't fit well to each other. What the user can do is to reformulate it's goal. For example he can try to program only a single program which is adding two numbers and then the assembly language is great.

July 05, 2021

How to learn C/C++ as fast as possible

 Sometimes it was mentioned, that C and especially C++ are complicated languages which are hard to learn. The reason is, that C++ allows to write low level code which includes pointers. In addition the amount of possible C++ commands is high and the chance is high that the newbie won't understanding anything.

So the logical choice is to avoid the C++ language at all and take a look for a programming language which works better. Potential candidates are Python (very beginner friendly) and Java (works great for writing productive code).

Sure the Python language works great for creating a prototype. But it fails for creating a productive application. So the question which language would combine the strength of python with a fast runtime performance?

The main problem with potential alternatives to C/C++ is that all these languages are seen as a second choice. Sure it is possible to write code in freepascal, C#, swift or ruby. But the default compiler on all the operating system remains c/c++ and most programs in the world were realized in C/C++. It seems, that from a technical perspective the language is great and the bottleneck is the programmer who doesn't understand it?

The interesting situation with C/C++ is, that the perceived complexity depends greatly on the manual. This is a contradiction to the Python universe in which the language is described in most manuals the same way. There are two sorts of C/C++ manuals available. Older one which are focussed on the language itself and are some sort of reference book. These sort of manuals have created the perception that C/C++ is hard to understand. And there are more recent tutorials available which are describing how to use C/C++ for writing games and apps.

A prominent example for a recent handbook is “SFML Game Development By Example”. The interesting thing is, that this book explains more things than only the language itself and at the same time it is easy to read. The difficulty is not harder than a python book about the pygame envirionment. The newbie learns how to write a small game in under 500 lines of code with the usage of a graphics library and some self defined classes.

The interesting point is, that according to this (and many similar books) C++ is some sort of python like programming language, but it runs much faster.

Let me summarize the situation a bit. First thing to mention is, that C/C++ remains technically the best programming language in the world and secondly it depends largely on the tutorial if the newbie is able to master the language.

Understanding the role of LaTeX

 Most introductions into LaTeX are trying to describe what the software itself is about. But this won't answer the question which role LaTeX is playing in a more general workflow. The interesting point is that most authors are not creating their text with latex itself but they are using external software like Emacs, texniccenter and vim. But, if LaTeX is so great why it is not used for writing the text?

To understand this mismatch we have to take a closer look how the programs are interacting with each other. What LaTeX needs as input text is a highly structured longer text, for example a 100 kb long markdown file, a 50 kb .tex file or a 300 kb long ascii text which contains of sections and subsections. in the next step, LaTeX is rendering this file into a pdf file similar to the ps2ascii utility.

In contrast to the MS-Word software the user never creates something in LaTeX but he creates the textfile for LaTeX. The text is written in additional software like the texnic center. And this explain what the idea behind LaTeX is. The user has to prepare the text in an outliner software and then it gets rendered into the pdf format.

Bascially spoken, creating something in LaTeX is not about the formatting itself but the more interesting point is, which sort of functionality is needed outside the latex software. The functionality is provided by so called outliner programs. That is a sort of software which makes it easy to create a longer text in structured way. Structured means that the contains of hierarchical sections, tables and references.

To understand how the process works let us imagine a world in which latex is not available. The idea is the user creates the text in the emacs org mode, then exports it into the markdown format and then renders the markdown textfile into the pdf format with an external program whcih is not latex but a different tool. The user will spend most of the text for creating the text in emacs. That means, the org mode environment is the software in which the text was created. Similar to other outliner programs like cherrytree, the user won't miss a page oriented layout, but outline means that a draft of the text is created.

There is a reason why apart from the famous ms word software, even under Windows and MacOS many external outliner programs like citavi, scrivener or omnioutliner are available. These programs are calling themself authoring tools. The idea is, that in the first phase of writing a document only the content is important and the layout gets ignored. For example, the cherrytree outline isn't able to format a simple two column layout or create the hyphens for a paragraph. That means, cherrytree is a poor choice for formatting the text on the screen and it was never created for this purpose.

Let us describe in general what outliner software is about. These programs were become famous for it's pane on the left screen which shows the document structure. The user can navigate in the document tree and shuffle the sections. Many features or even all features of a desktop publishing software are missing in an outliner program. Cherry tree doesn't even know what kerning is or how to embedded a type1 font. That means all the important features used for creating a book are not there. How can it be that the software is used in the reality if it has a low amount of features? Because cherrytree and other outliner programs are focused on the text itself. There is a distinction between creating the raw text and formatting the text into a pdf document.

From an authors perspective, a book or journal is not created with a desktop publishing software but with a normal text editor aka an outliner software. What an author is doing is not to create a pdf file but the author creates a 300 kb long plain ascii file. The interesting situation is, that even in the world of MS-Word and Indesign there is a clear distinction between creating the text itself and rendering the text into a pdf file. For example the indesign software has an often used function to import plain ascii files. That means, somebody else has to create the .txt file before and then it can be imported.