October 21, 2022
Tribute to Ansi C
Which programming language is the best?
Is C# obsolete?
// c #include<stdio.h> #include<string.h> #include<stdlib.h> char *sconcat(const char *s1, const char *s2) { char *s0 = malloc(strlen(s1)+strlen(s2)+1); strcpy(s0, s1); strcat(s0, s2); return s0; } int main() { char str1[]="Hello "; char str2[]="World"; char *str3=sconcat(str1,str2); printf("%s\n",str3); return 0; } // c# class Program { static void Main(string[] args) { string x = "foo"; x += "bar"; System.Console.WriteLine(x); } } // python str = "12345678"; str += "9!"; print(str)
Writing larger programs in Ansi C and Forth
Modular programming with python
The surprising success of the C programming language
The development of the c language after the year 1992
Writing GUI apps with the c language
October 05, 2022
The remarkable success of the C programming language
C vs C++
Creating header files in Ansi C
Why has the C language evolved into C++?
October 03, 2022
Programming exercises to understand robotics
AI and robotics is mostly described as programming technique or as an algorithm. The question is which sort of program provides AI, or which sort of AI library is available? The surprising situation is, that AI is located in a different position. It has to do with with a programming exercise.
Some typical Non AI programming exercises are:
- "Write a software in python which prints out 6 randomly generated numbers"
- "Write a python program which plots a line on the screen"
- "write a java program which adds two numbers and prints the result on the screen"
These exercises are used to a teach programming and a certain programming language at the university. It depends on the student how to solve it. AI and robotics is some sort of advanced programming exercises which can be labeled as ultra-hard. The question is which sort of AI programming exercise is available? A possible challenge is given next.
There is a robot in a maze which can be controlled with the keyboard. The task is to write a grounded sensor for the robot which contains of 6 elements:
[xpos,ypos,distancefront, distanceleft,distanceright,distancetoenergy]
The sensor array should be printed to the screen all the time.
Such a programming exercise fits into the same category like "write a program which prints out all the prime numbers" because it formulates a problem which can be solved with an algorithm. The task for the student is to understand the problem, write a short program in Python or Java and then it can be determined if the software solves the task.
From an abstract point of view it is important to ask which sort of programming exercises are needed to explain the subject of robotics. What all these challenges have in common is, that not a certain algorithm is needed but a certain exercise. The formulated problem with the sensor array doesn't contain of program code nor an algorithm. But is a figure plus a text which formulates a problem. It is up to the opponent (the student) to provide an answer to the problem. The answer is written in a certain proramming language and will contain of an algorithm. In the concrete example, the typical answer will take the requested 6 elements from the underlying physics engine and in case of the distance value it has to be calculated from scratch. Then a print routine is needed to show the result on the screen.
Creating a GUI with Ansi-C
/* gcc -ansi 2_ansic.c $(pkg-config --cflags --libs gtk+-3.0) && ./a.out */ #include <stdio.h> #include <gtk/gtk.h> void show_about(GtkWidget *widget, gpointer data) { GtkWidget *dialog = gtk_about_dialog_new(); gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(dialog), "Sample program"); gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), "0.1"); gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), "The quick brown fox jumps over the lazy dog"); gtk_dialog_run(GTK_DIALOG (dialog)); gtk_widget_destroy(dialog); } void button_clicked(GtkWidget *widget, gpointer data) { printf("clicked\n"); } void initwindow() { gtk_init(NULL, NULL); GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Hello World"); gtk_window_set_default_size(GTK_WINDOW(window), 400, 300); GtkWidget *fixed = gtk_fixed_new(); gtk_container_add(GTK_CONTAINER(window), fixed); GtkWidget *btn1 = gtk_button_new_with_label("Button"); gtk_fixed_put(GTK_FIXED(fixed), btn1, 150, 50); gtk_widget_set_size_request(btn1, 80, 30); GtkWidget *entry1 = gtk_entry_new(); gtk_fixed_put(GTK_FIXED(fixed), entry1, 150, 5); /* events */ /*g_signal_connect(G_OBJECT(btn1), "clicked", G_CALLBACK(button_clicked), NULL);*/ g_signal_connect(G_OBJECT(btn1), "clicked", G_CALLBACK(show_about), NULL); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_widget_show_all(window); gtk_main(); } int main() { initwindow(); return 0; }
October 01, 2022
Programming languages in a cluster diagram
The amount of programming languages is endless. One suboptimal option to categorize them is by their history. The more elaborated attempt in building clusters is by a two variable model which contains of interpreted vs compiled and procedural vs. objectoriented. The interesting situation is, that all the existing languages can be located at a certain position in the 2d chart.
And secondly it is possible to name only the languages located on the four corner which are: Basic, Python, C++ and C. Each of these languages has in one variable the maximum value. For example, the Basic language is an interpreted language which is working with the procedural paradigm.
Let us determine the best programming languages for professional purposes. The interesting situation is, that even more than 200 different programming languages were invented, most of them are only used in an academic context. At the university lots of languages are taught, e.g. Pascal, Python and of course Prolog. But, most of these languages are not used for writing operating systems which includes applications for operating systems. The concern of expert prorammers against these academic languages is, that they are objectoriented which is equal to rreject them or they are interpreted which also implies to reject them. The only language which is not object oriented and not interpreted is C.
A closer look into the debian repository and into the anecdotal description of what is used for creating MS-Dos and Win16 bit application will show, that 100% of the software in the past was written in Ansi-C. This is especially the case for the early 1990s. According to the programming books of this time, the future is about object oriented programming namely C++, Delphi and Java, But at the same time, these languages were not used to write production ready sourcecode. But the programmers are prefering Ansi-C.
According to the picture it is very easy to explain the reason why. Professional programmers are prefering a language which is compiled and procedural at the same time. The only language available in this category is C. All the other languages like C++, Basic, Prolog, Lua and so on have a different self understanding.
The question which remains open is, why exactly professional software is written with compiled&procedural languages. It seems that only this combination ensures the maximum performance and the ability to maintain a larger amount of codelines. What the Linux sourcecode and the Windows sourcecode have in common is, that the project has over 1 million lines of code and that the binary file is executed very efficient.