The Perl language was developed in the late 1980s and had fallen out of fashion since a while. It's a programming language which has revolutionized computer programming in the past, because it was the first widespread used scripting language. Perl was introduced in a time, in which programming in UNIX was done entirely with the C language. From the perspective of C, Perl doesn't make much sense. Because all the libraries are written in Perl again. It was yet-another-programming language which resulted into extra work, new scripts and a different ecosystem.
Exactly this was the reason why Perl and all the other later examples of scripting languages were successful. Because they are focussed not on classical programming but on scripted programming. The advantage of using Perl over C is the same, like modern Python programmer would explain why they have choosen the language of Guido van Rossum: because in a few lines of Perl it's possible to create complex applications. Secondly, there is no need to use pointers, integer variables or a compiler. But a simple hello world script fits into a single line of code.
From the computer history perspective, Perl was a successful attempt in reinventing computer programming. Instead of writing code for the machine, the code was written for a parser, called the Perl interpreter. Similar to a modern Java VM or a PHP interpreter, the Perl parser isn't compiling the code into machine code, nor it is doing a syntax check if the semikolon was put at the correct position. The self-understanding of Perl programmers is, that they are not interesting in creating machine code, or want to extend the operating system. But they want to deliver a HTML webpage or test a prototype.
Another interesting point is, that Perl never replaced existing C code. After the invention of Perl, the previous created c applications were used unchanged. But Perl was thought as an additional language. It was the beginning of creating a zoo of languages. Instead of deciding between C and assembly language, the programmer had the choice between Perl, TCL, Bash script, Modula-2, Postscript and Clipper.
From an abstract point of view, Perl resulted into many newly created lines of code. The CPAN directory was created from scratch. It started with 0 entries and today around 180k modules written in Perl are available. All of the code was created manual and tested by the community. In most cases, the code is doing exactly the same what a well maintained C program can do, but it's written in Perl. It seems, that there is some kind of general law which says, that the number of different programming languages has exploded. And each language community follows it own rules.
Does it make sense to invent the Perl language next to the C language? Sure, because technically both concepts are different. For some tasks, C is the better choice, but many things can be done with Perl perfect. With the same argument, new languages after Perl can be explained. For example the Java language is very different from Perl and C together. Java is not a compiled language, but it's also different from an interpreted language. In contrast to Perl, Java was developed with object orientation in mind from the beginning.
All the programming languages can be divided into two groups. The first one are optimized for the compuer in mind. They are compiled low level languages which are hard to learn but run efficient on today's hardware. Typical example is the C++ language. The second group are prototyping languages which are mostly interpreted but sometimes they run a virtual machine like C# language. Their idea is, that it's ok if the program runs 5x slower than a C program, but it provides an easier syntax and makes it useful for programming newbies. The typical example is Python, but languages like AutoIt (Macro language for Windows GUI testing) and Matlab script (embedded language in a mathematics software) can be included in this category as well.
The most interesting fact is, that code reuse between the languages isn't there. Instead, each community is creating all the libraries from scratch. The idea is to increase the total number of codelines. The reason why so many languages were invented has to do with the architecture which runs the code. The classical platform for run computer code was a barebone CPU. That means, the CPU contains of 10 registers and an instruction pointer, and the language of choice was Assembly. The next logical step is a compiled language which simplifies assembly programming. In the C language the programmer doesn't create a program for a Register machine, but he is programming software which runs on a general computer which contains of memory and lots of subroutine. This kind of evolution goes on: OOP means to program code for an architecture which is more powerful, and the latest version of the AutoIt programming language assumes that a well equipped Windows operating system is already there which contains of preinstalled programs.
September 14, 2019
Transitions in media history
Media studies is strongly connected with the invention of the printing press in the 15th century. The past can be divided into the time before books were available and after them have become a mainstream good. The interesting point is, that the time after inventing the Gutenberg press has become faster. Revolutionary inventions were made which have made the original press obsolete. The first one was the steam driven printing press in the 19th century which has reduced the costs dramatically. This sort of machine made it possible to print apart from books newspapers.
Another important invention was the first typewriting machine. This machine democratized the writing of books. Anybody who likes was able to write a book by it's own. He needs only an empty sheet of paper and a bit language skills. The next revolutionary device after the mechanic typewriter was the homecomputer. The businessman Jack Tramiel is a good example for this transition. In it's early years he worked for a company who produced typewriting machines, later he founded Commodore Computers and sold the famous homecomputer with 64kb of RAM. The transition from trypewriters to homecomputers was made during the early 1980s. The transition was much faster, then the invention of the first printing press 500 years ago. In less then 10 years, the desktop computers have replaced former typewriters at homes and in business.
After the homecomputer was on the market the next revolutionary invention was even bigger, it was the internet which was introduced for the mass market during 5 years. It took only 5 years from the release of the first WWW server in 1993 until the Internet was available widespread in the year 1998 which resulted into the dot com boom.
On a longer timespan the time between two revolutionary inventions has become shorter. It took 300 years from the Gutenberg press to the steam driven press. It took only 100 years from modern printing press to typewriters but it took only 15 years until the homecomputer replaced the typewriter and it took 5 years until the Internet was available worldwide.
Typewriters
In the year 1968 the Commodore 2200 was widespread available. It wasn't a homecomputer, but a home typewriter. From a technical perspective the machine wasn't very advanced, it looks like any kind of typewriters from that period. The fascinating feature was the brand name because only 20 years later, Commodore has evolved from a typewriter company to a computer manufacturer. In the year 1968 it was rare or not possible to become the proud owner of a homecomputer with 64kb of RAM. In that time, the computer hardware nor the software wasn't invented yet. That means, a personal typewriter was the most advanced technology the people can buy in this time.
Even a mechanical typewriter looks outdated for today's eyes in the 1960s it was a modern technology. Because the typewriter allows for anybody to create a book. It was similar to today's word processing tool. Instead of using a pen, the user was using mechanical keys. This allows him to write faster and more accurately. An additional was that a typewriter can be utilized for photocopy tasks by using a special sort of paper.
The social aspect of mechanical typewriters is amazing. It allowed the people to educate themself. If somebody has written some letters and complete books on the machine it was able, that he was trained as a writer. He was using language not only passive by consuming existing information, but in a active fashion. It was not a coincident, that mechanical typewriters were widespread used by students, in the office, by teachers and by play writers. It was a tool for improving the own mind. The interesting point is, that without such a tool it was not able to become educated as well. Writing lots of letters only with a manual pen is not possible. And if somebody hasn't written many letters, he wasn't trained in using language efficient. This was equal to missing education. So the most powerful of a typewriter was not located in the hardware of the machine, but in the effect on humans who are using the tool on a regular basis.
Another important invention was the first typewriting machine. This machine democratized the writing of books. Anybody who likes was able to write a book by it's own. He needs only an empty sheet of paper and a bit language skills. The next revolutionary device after the mechanic typewriter was the homecomputer. The businessman Jack Tramiel is a good example for this transition. In it's early years he worked for a company who produced typewriting machines, later he founded Commodore Computers and sold the famous homecomputer with 64kb of RAM. The transition from trypewriters to homecomputers was made during the early 1980s. The transition was much faster, then the invention of the first printing press 500 years ago. In less then 10 years, the desktop computers have replaced former typewriters at homes and in business.
After the homecomputer was on the market the next revolutionary invention was even bigger, it was the internet which was introduced for the mass market during 5 years. It took only 5 years from the release of the first WWW server in 1993 until the Internet was available widespread in the year 1998 which resulted into the dot com boom.
On a longer timespan the time between two revolutionary inventions has become shorter. It took 300 years from the Gutenberg press to the steam driven press. It took only 100 years from modern printing press to typewriters but it took only 15 years until the homecomputer replaced the typewriter and it took 5 years until the Internet was available worldwide.
Typewriters
In the year 1968 the Commodore 2200 was widespread available. It wasn't a homecomputer, but a home typewriter. From a technical perspective the machine wasn't very advanced, it looks like any kind of typewriters from that period. The fascinating feature was the brand name because only 20 years later, Commodore has evolved from a typewriter company to a computer manufacturer. In the year 1968 it was rare or not possible to become the proud owner of a homecomputer with 64kb of RAM. In that time, the computer hardware nor the software wasn't invented yet. That means, a personal typewriter was the most advanced technology the people can buy in this time.
Even a mechanical typewriter looks outdated for today's eyes in the 1960s it was a modern technology. Because the typewriter allows for anybody to create a book. It was similar to today's word processing tool. Instead of using a pen, the user was using mechanical keys. This allows him to write faster and more accurately. An additional was that a typewriter can be utilized for photocopy tasks by using a special sort of paper.
The social aspect of mechanical typewriters is amazing. It allowed the people to educate themself. If somebody has written some letters and complete books on the machine it was able, that he was trained as a writer. He was using language not only passive by consuming existing information, but in a active fashion. It was not a coincident, that mechanical typewriters were widespread used by students, in the office, by teachers and by play writers. It was a tool for improving the own mind. The interesting point is, that without such a tool it was not able to become educated as well. Writing lots of letters only with a manual pen is not possible. And if somebody hasn't written many letters, he wasn't trained in using language efficient. This was equal to missing education. So the most powerful of a typewriter was not located in the hardware of the machine, but in the effect on humans who are using the tool on a regular basis.
Using scripting languages for number crunching
In the past, the task of number crunching was handled very well with the C/C++ language. The optimizing compiler generates efficient machine code and forces the programmer to use the existing ressources optimal. A C++ library which calculates prime numbers is the most efficient way in software engineering. That means, the C/C++ is the perfect choice for such applications.
Surprisingly the situation has changed nowadays. Scripting language were used not only for prototyping reasons, but especially for number crunching. On the first look, it doesn't make much sense to calculate prime numbers or to plan the trajectory of a robot arm with a python script, because both tasks are numerical intensive tasks which needs a lot of cpu ressources. On the other hand, a slow scripting language gives the programmer the opportunity to think twice about the implemented algorithm. He knows, that the Python interpreter is not very efficient so there is a need to search for a fast algorithm first, before programming a single line of code. The idea is to ignore a potential speedup by the C compiler by the factor 5, and search for an algorithm which improves the program by the factor 500.
The paradox success of Python wasn't limited to GUI prototyping and interactive applications but has become obvious for number crunching applications. The question is not how to convert an existing algorithm into efficient machine code, but the problem has to do with algorithm identification and discuss existing one in academic papers. The python language has become a quasi standard for such applications and has replaced C/C++ in number crunching tasks.
Prime numbers
On the first look, a prime number generator has to do with a certain algorithm which has to be implemented. The following codesnippet is moderately fast.
def isPrime(n) :
if (n <= 1) :
return False
if (n <= 3) :
return True
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
In contrast to a naive prime number testing, it will check only for 6. value in the for loop which reduced the amount of computational effort. It's surprisingly to know, that far more efficient prime algorithms are known. To get access to them is not a question of mathematics, but using a search engine for asking the Stackoverflow website. After a bit of search we will identify a Stackoverflow post which gives a more efficient implementation:
def primes(n):
""" Returns a list of primes < n """
sieve = [True] * n
for i in range(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
return [2] + [i for i in range(3,n,2) if sieve[i]]
Now we can compare both versions in term of speed. The first one calculates the prime numbers from 0 to 3000000 in 15 seconds on a standard computer. The second version is doing the same task in only 0.3 seconds. That's a 50x times speed up.
The reason for the enourmous speed up was, the Stackoverflow forum. On the same place different users have argued pro and against certain algorithm and other have found the information with the search engine. That means, the speed up was not the result of using efficient machine language nor it has to do with a certain mathematical approach, but it is located in the gutenberg galaxy. Python is a language which supports the communication about different algorithms. Python programs are human readable. This is interesting for number crunching applications.
C/C++ was designed for number crunching
In the early 1990s, the C++ programming language was already known. In that time, it was described as a complicated but powerful programming language. Surprisingly, C++ was never the only programming language under the UNIX operating system. A well known handy to use example was the PERL scripting language which is working the opposite over C++. The controversy between C++ and Perl is very similar to today's arguments which are speaking for or against Python. The interesting point in the early 1990s was, that Perl didn't replaced C++ and the other way around, but both languages were used in parallel. It was the beginning of a language variety, in which new languages were developed quickly.
The reason why scripting languages like Perl, PHP, Python and Javascript were developed is obvious, because they are focussed on the speed of program creation but not on the performance of the resulting code. The advantage of C/C++ is the other way around. The language is used heavily in the domain of number crunching, in which the CPU runs with 100% and it's important to make the program faster. A typical example for a C/C++ application would be a video encoder.
The interesting point is, that C/C++ is well suited for such applications. The programmer has to invest more time until the program is created, because he has to deal with pointers, variables types and complicated compller workflows, but in exchange he gets a software which outperforms Perl and Python easily. Encoding a video with Python would take 10 hours, but the same task can be done with C++ in under 10 minutes.
Outside of number crunching C/C++ has nothing to offer. If the program doesn't occupies the CPU by 100% which is true for a normal desktop application or a simple game, C/C++ has no advantage over a scripting language. The programmer has to deal with the complex language syntax and has to realize the program with pointers but he gets nothing in exchange. That is the reason, why most programmers stay away from C++ and preferring scripting languages.
Not the programmer but the CPU has to decide, if C/C++ make sense. If the application takes 100% of the CPU, it make sense to rewrite the existing Python code with C/C++. The result is an improvement in performance. Which means, that a compiled C/C++ program is using the existing CPU more efficient. The generated assembly statements are highly optimized and this allows the CPU to run more efficient. How many programs take 100% cpu time? Only a few, in a typical programming situation it's the exception, that the programmer has created an algorithm or a subroutine which occupies all the ressources. Dedicated number crunching problems are not very common in normal programming tasks. The typical webframework, the normal GUI application and even the average 3d game doesn't use the CPU intensively. Switching to the C/C++ language is not needed here.
The problem is, that some programmers understand software engineering and number crunching application as the same. They identify themself with a social role, in which computers are used mainly for important number crunching applications. The idea is, that the computer is started in the batch mode, has to add millions of numbers and then he prints out the result to the screen. And the programmer is trying to realize such software with C/C++. The problem is, that this application is not there in modern software engineering. Today's software is at foremost complex, which means, it contains of thousands of sourcecode lines and is described in hundred of pages of documentation. At the same time, this software need only a little amount of CPU ressources. That means, after the software is started, the CPU demand has increased only from 2% to 3%. If the software makes trouble, it's not because the computer is too slow, but because there is a bug in the software, which throws an exception.
Perl
The invention of Perl has lead into many newly written sourcecode. Instead of propagating code reuse, the Perl community has invented everything from scratch. Today, all the written code is useless, and most of them was rewritten in modern languages like Python. At the same time, the Perl language was loved by it's users, because it was easier to master than C/C++.
From a historical perspective, Perl was the first important scripting language. It was invented by the advent of Java or Python. The concept behind Perl was very similar to what Python is today, because the programmer is no longer forced to declare variables before it's first usage and he doesn't need to compile the program into machine code. In contrast, to C/C++ Perl is a dynamic scripting language. It's main purpose is to create software prototypes. Sometimes, these prototypes are rewritten in C/C++ later, but in most cases the Perl code is used on a production server. This kind of strategy was replicated by modern programmers who are running their PHP and Java applications on a production server.
The reason why Perl and other scripting language have became successful is because the computer speed was fast enough at a certain time. If the created console application doesn't need much cpu power but waits most of the time for a server request, there is no need to optimize the application in terms of performance. Let me give an example. The same is true for cron jobs and GUI applications. In 99% of the running time the app is in the idle mode, that means, it does nothing but waiting for a user input. Does it make sense to optimize the software in terms of low cpu consumption? It's a rhetorical question and explains, why C/C++ has fallen out of fashion.
From the point of view of a C/C++ programmer the CPU is occupied by the current application. That means, the software produces a heavy load in term of memory consumption, cache requests and integer multiplication. And the question is, how to program the software in a way, that it will run with less energy. That means, how to optimize the assembly instructions and the memory map so that the CPU works smooth.
Again, is C++ dead?
The question was asked https://www.quora.com/What-are-the-areas-where-C-is-dead and some examples were given. The interesting fact is, that the amount of projects which are using C++ is very small. Some examples are given in which C++ is not widespread used. The Linux kernel was written in C, Web applications are written in PHP and Java, desktop GUI apps are programmed in C#, Android games are written in Java and prototyping is done with the Python language. At the end of the post, a remarkable statement can be found:
quote: “Technically C++ can be used for all of these, it is just that people tend to prefer other tools for these applications.”
Is the statement wrong? I didn't found a mistake. It's correct, that the Linux kernel was written in C, and it's also true, that Microsoft is promoting C# and Google promotes Java for android applications. C++ is ignored by mathematicans as well, they are prefering R, matlab or Python for creating a model quick and easy. It seems, that there is a gap. In the literature, C++ is covered in thousands of books and papers. But it seems, that in reality no one is reading these tutorials are is motivated to attend the C++ community.
The reason why is not hard to define. C++ has become famous because it combines object oriented programming with a compiled language. This is very different from all the other languages. In most cases, object oriented langauges are interpreted or run in a virtual machine, while structured languages like C are compiled. Or let me ask the question from the other perspective. If C++ is so great, why it wasn't able to replace all the other languages? This question can be answered step by step. We have to convince a certain community to migrate to C++. We are starting with Python programmers. C++ is more powerful than Python. It provides many object oriented features and a modern LLVM compiler can produce the binary file quickly. The problem is, that the average python programmer won't switch to C++, because he likes his language which has less features and gets interpreted interactively. The next candidate would be the Microsoft community. All what we have to do is to explain to long term C# programmers, that their language is wrong and that the don net strategy doesn't make much sense. The better alternative is the C++ language which is not controlled by a single vendor but works on all operating system. Unfurtunuately, the prediction is, that Microsoft users are not interested to switch from C# to C++.
The same is true for Android programmers. Technically they can write C++ applications but it's harder than using the normal Java workflow. The same is true for web application which will run faster with C++, but the PHP community is not motivated to switch. That means, the C++ is a nice programming language which is searching for a user base.
If a language has problem to become attractive to users, the language can be called death. It means, that the language is ignored. It make sense to write a obituary for C++. It was a great language in the 1990s before the advent of the internet. The promise was to combine object oriented programming with efficient compiling technology. In reality, this concept was attractive to programmers only during the 1990s because in that period no alternative was there. With the advent of new programming paradigms C++ has become obsolete. Microsoft has attacked C++ with the dot net strategy, and non programmers have discovered scripting languages like PHP and Python as an easy to use replacement for a compiled language. Even the core programmer from within system development and hardware programming were not motivated to support the C++ language.
From a technical point of view, C++ was designed as a “one fitts for all” language, which means, that any type of application and any type of user can profit from C++. In reality, many different programming langauges were developed for specialized needs. It was easier to invent yet another programming language instead of writing a simple C++ library. The current situation is, that the world doesn't speak C++ but prefers around 100 different languages which are all incompatible to each other.
We can say, that C++ was the most influential language in the 1990s but has lost all the programmers. A modern C++20 compiler works better than ever, the generated sourcecode is efficient and the binary file will run on any computer plattform. Unfortunately, the programmers are not interested in using this technology. On the long run, C++ will become obsolete, or it is in that stadium since a while. The prediction is, that the ranking of the C++ in the tiobe index will decline in the next years, and other languages which includes completly new languages like Javascript or Go will become more popular.
The reason why C++ is ignored by the normal programmer is because the migration from C++ to any other language is very easy. In most cases, it's possible to rewrite existing code. If somebody has written a C++ application he can convert all the code manual into the C# code. And the advantage of creating new C++ code is low. Another problem is, that most code isn't created with libraries in mind but is used once in a project. Creating system libraries can be done with plain C more efficient than with C++. Because plain C is the smallest standard on x86 architecture and object orientation is perceived as an addon which supports software development similar to the UML notation.
From the perspective of a C++ advocate, most today's programmer have decided for the wrong language. If somebody prefers PHP over C++ for a web framework he is not using an efficient language, if somebody prefers C but not C++ for creating a library, his workflow is not optimal. And if somebody writes code in C# but not in C++ he is not vendor independent but focussed on Microsoft operating system. The problem is, that this description of the world would declare 95% of the programmers as wrong and the only one who has understand programming right are C++ programmers. That means, programming In C++ is not something which is available in reality, but it's wishful thinking.
I wouldn't argue against C++, because it's one of the most interesting languages ever. In contrast to PHP or Python, C++ is a universal programming language. Which means any type of program can be created with the compiler from small to large projects. And perhaps this feature has made C++ obsolete. Because programming has to do with writing millions of codeline by thousands of programmers. Allowing them only to use one programming language doesn't make much sense. The needs of the different projects are very different. For example, if somebody likes to prototype a new game with pygame, he has a different understanding of the world, than somebody who is creating a library for a web framework.
The question is not how to define one language which fits all needs, but the problem is how to connect existing Python code with PHP frameworks over the internet. Perhaps it make sense to describe the descent of C++ by an example. In the year 2012 Google has announced the Go language. The alternative over go would be a C++ library for creating RESTful services. Google has decided against C++ but has implemented a language from scratch. According to the written codelines in the Go language, Google was right. The newly developed language has become a success. Go helped to convince formerly C++ programmer to switch over to Go if they want to create responsive web applications. The exact reason why Google has ignored C++ is not clear, Perhaps, the C++ language was not attractive enough. It was perceived as outdated, or technically not compatible.
Another reason was perhaps, that creating a new sort of language and a new compiler provides the opportunity to learn something. If the programmer is forced to use only existing C++ compilers he restricts himself into already known technology, this is equal to resist against technology progress.
The problem with C++ is, that the concept is not able to develop into future needs. The concept of combining a compiled language with object oriented language is fixed in the case of C++. Also the requirement of providing a language for lowlevel system programming and high level classes is fixed in the C++ specification. This makes it hard to test out new ideas.
The main problem of C++ is perhaps, that the language is compiled. This technique doesn't fit to modern needs in which programs are created inveractively in a test driven development. It makes no sense to comipile the complete project after adding smaller modifications. The idea of compiled binary file has become popular many decades ago and has much in common with batch processing. The idea was, that the programmer types in a program and every 3 days he press the compile button once. Then he edits the sourcecode at once until the next compile run is made.
The most obvious reason why C++ is dead is the Python language. Python works completely different from C++. Python is interpreted, has an easy syntax and is prefered by non programmers.
Creating object oriented libraries
The most efficient way in implementing a library is the assembly language. Surprisingly, it's not possible to create object oriented assembly programs, because an assembly program is able to read and write in the entire adress space. It can call any subroutine and their is no classes which are equal to boundaries. The alternative over Assembly is the c language which has also no object orientation abstraction.
At the same time, it's possible to implement any algorithm in assembly and C, which means, that object orientation is not a must have in modern system programming. It simplifies the software engineering workflow only for the programmer because it helps him to divide a problem in smaller chunks. If the prototyping stage is over the programmer can write the program itself. He doesn't need object orientated features in software and it's possible to create libraries in normal C code very well. The interal working of these libraries is realized with structs and pointers. If a certain subroutine should modify a struct, the subroutine gets the pointer to the struct. This sort of understanding is exact the way how computers are working internally and the programming is close to the machine.
The hypothesis is, that libraries written in C are more efficient and closer to the machine than libraries written in C++. This make C the better choice for creating system libraries. The only language which beats C in terms of performance in Assembly. There are some examples available in which a math library written in Assembly outperforms C by 30% in terms of speed and memory consumption. But for most cases, normal C code is fast enough.
Is this maybe the explanation why C++ has struggeled in reality? Because it has compared to normal C problems in term of efficiency? At least we can reduce the topic to a simple question: is a library written in C more efficient than a library written in C++? One possible way to answer this question is by an example. But i think it's also possible to describe the situation from an abstract standpoint. The interesting point is, that the syntax of C++ which includes classes can't converted directly into machine code. A class is nothing which can be stored in the main memory. All object oriented programming languages like Python or C# are converting the class notation in a different syntax which is utilizing pointers for matching existing data and subroutines. Let me give an example.
In the C++ language it's not possible to call a subroutine from a different class. In term of object orientation this feature is called encapsulation and means, that a class has a border to the rest of the program. For the programmer this feature is very important because the amount of variables in the class is smaller. A typical class which contains of 100 lines of code has only 10 variables. The programmers has only to maintain this small amount of information.
If the program is executed in an operating system as binary code, the concept of classes is gone. For the operating system the program forms a large adress space whcih contains of hundreds of variables. Each of them can modified by any subroutine. No one forbids the program to modify the variable from a different class. The reason why the C++ compiler prevents such behavior in the sourcecode is because the compiler checks if the programs fulfills the object oriented standards. And this is the reason why C++ are so complex to realize. Because they are adding features which are not needed. The ability to check if the programmer is allowed to modify a variable is not necessary from the standpoint of the computer program but has to do with object orientation. A c compiler doesn't prevent the programmer in changing variables from different classes, because the class feature isn't there. This makes it easier and more efficient to realize a plain c compiler.
According to internet forums, it's unclear if C or C++ is the faster language. In most postings it was written that modern C++ compilers are faster than C compilers. But makes this explanation any sense? Let us make first a working hypothesis in which C is superior over C++, because a c compiler is needs less features and as a result it's a smaller piece of software. With this hypothesis in mind, we can search for examples and counter examples. It seems, that the awareness of the difference between C vs. C++ is not very widespread available. C++ is described mostly as the queen of all programming language and it's rare to find an opinion which declares C++ as obsolete. It seems, thate is a missing of objective judgment about C++.
History of C compilers
In the 1980s with the upraising of the IBM many C compilers were available like Microsoft C, Watcom C and Borland C. From the early 1990s all of these compilers were enriched with C++ functionality which resulted into the description “C/C++”. The same compiler was able to parse C and C++ source code as well. In the middle and late 1990s, C++ was the only object oriented language. Newly languages like Java, C#, PHP and Borland Delphi were developed as an alternative to the C++ language.
If C++ is desclared as obsolete in the 2010 it make sense to take a closer look at the original C compilers. Without any doubt, c is the programming language of the future. But not the C/C++ ideology of the 1990s but the strip down version which means the plain C language without it's object oriented plugins. The advantage is that a compiler which generates only C is much smaller than a full blown C++ compiler.
Pointers
The reason, why libraries which are written in C are fast is because pointers are used as default in C. Pointers plus dynamic allocated memory allows to write very efficient programs. It can't replaced by anything else because this is how computers are working on a low level perspective.
It's surprisingly to know, that at the same time pointers and dynamic memory are perceived by high level programmers as something which is slow down the development process. The average Python programmers wants to store data a dictionary, but he is not interested in dynamic allocating an array and copy the adress to a subroutine. That means, pointers are at the same the most hated and most important feature in modern programming. A possible workflow in combinging the advantages is to write a program prototype in a high level scripting language like Python. In Python there are classes available and there is no need to use pointers. If the Python code runs well, it make sense to convert the program into lowlevel C sourcecode which is using pointers everywhere. The execution speed will become much better.
Is C faster than C++?
The question was asked recently in a blogpost somewhere in the internet. For measure the performance on an objective basis, a pi calculating routine was written which was realized with the same algorithm. The first routine was compiled with gcc, the second one with the C++ compiler. The result was, that the execution time in seconds was exactly the same.
In my own experiment i came to the same conclusion. The runtime speed of the binary file is the same, and even the program size in bytes was the similar. Does that mean that C++ is comparable to plain C? No that is not the conclusion, because we have to take a broader look into the ecosystem. A c++ compiler is more difficult to realize than a C compiler. And a book which describes C++ has more pages than a book which gives an introduction to C. That means, C is the baseline, and the C++ compiler is trying to imitate the standard.
Instead the answer has to do if someone likes to program object oriented or not. Most current libraries are not written in C++ but in normal C. The reason is, that the increased complexity of C++ doesn't provide an advantage so the programmer stay within the C universe and ignore the extension of C++. If they want to program object oriented they are switching from C to a scripting language like PHP or Python. There is a second reason why plain C is recommended over C++. If the aim is to improve the performance of a program there is a need to use pointers and program close to the machine. This results into a programming style which is called c programming. That means, the programmer allocates manual memory, and gives the pointer to a datastructure to a subroutine.
Using this kind of tricks in context of a C++ is possible but it is not compatible with object oriented programming. That means, the C++ language is used as some kind of C language and the question is why the OOP extensions are available. On the other hand, the programmer can not ignore pointers, because then he will loose all the performance. It is important to decide either for lowlevel hardware programming or high level object oriented software engineering.
Software engineering has to do with designing an application. It is realized by drawing UML charts, creating prototypes in a scripting language and write throwaway code. In contrast, the production ready code is written in low level C language which doesn't provide object oriented features but is using the CPU as fast as possible. It make sense to separate both steps.
From programming to algorithm invention
In some previous blogposts, I've explained why programming is obsolete. Not a certain kind of language like Python or C# is outdated for computer scientists, but all available language have fall out of fashion. Programming is too easy to teach it in a computer course. It was replaced by something which has a higher priority and needs an academic background. This alternative is called algorithm invention. An algorithm is an abstract description how to solve a problem. A typical example for a search algorithm would be to sort first the data in the ascending order and then go through each item to search for the term. This search algorithm can be implemented in any programming language, for example in Ruby, Fortran, Javascript and so on. The interesting fact is, that the implementation will look very similar. Another point is, that the task of converting an algorithm into sourcecode is not very hard.
In the easiest case, a certain algorithm is expressed in the python language in around 20 lines of code. The task of programming which means to enter the program lines into the computer and check for potential syntax errors is outside the scope of computer scientists. In most academic papers, not the needed sourcecode is shown but the algorithm is described.
The hypothesis is, that computer science at a university is about algorithm but not about programming itself. If somebody has tried to implement a search algorithm in C++ but not in Python and gets a syntax error, nobody cares. That means, the question how to realize an algorithm into a concrete programming language is not important for computer scientists. They are don't care about it. What they are interested in, is discussion different kind of algorithm to search in a data structure.
Is the C++ language dead?
On the first look, the idea behind C++ make sense. C++ combines object oriented programming with a compiled language. Buth features are perceived as powerful technique in modern software engineering and the C++ is the most important language with this aim. But, if C++ is so amazihg, why so many alternatives were developed in contrast to C++?
In the Open Source / Linux domain there is a widespread concern, that object oriented programming doesn't provide a useful addition to structured programming but make things more complicated. The complete Linux kernel for example was written in plain C, and most libraries like the GTK+ too. In case of GTK+, a plugin was used to provide simple OOP features which is called gobject, but it's not a C++ library. The same mistrust against C++ is obvious in the Windows operating system. Microsoft has developed since the year the C# language and the dot net framework which stands in direct contrast to the C++ language. Programming with C# is very similar to programming in Java, which means, that the language is not compiled into machine code but interpreted as runtime. Last but not least, the famous Python language which supports also object oriented programming doesn't provide a compiler but it's an interpreted language.
To analyze the situation in detail it's important to give some facts. It's widespread accepted that the lowlevel C language is compiled. Another fact is, that most object oriented languages like Java, C#, Ruby and Python are interpreted ones or they are running in a virtual machine. What is a potential explanation for this gap?
Converting a structured C like program into machine language is not very complicated. A normal program contains of variables and program text. A C compiler converts high level C sourcecode into assembly statements and this is executed by the operating system. On the other hand, an object oriented programming style asks for a different kind of converter. The first object oriented languages like Simula and Smalltalk were realized as interpreted languages. The reason is, that objects are not stored in assembly syntax but in a datastructure. Let me give an example:
Suppose, in the pacman game the object “ghost” was created in the program. Ghost contains of variables for storing it's x/y position, and it contains of methods for moving the object to another position. The code for moving the object is stored only once in the physical memory, but all the instances have access to the code. The translation from sending on a high level layer a message to the object to low level instruction execution is done by the interpreter / virtual machine. A second reason why most object oriented language are implemented with an interpreter is because it allows interactive edit and test the sourcecode.
The question which remains open why C++ isn't working in this way, but combines a compiled language with object oriented features? I'm not the first one who asks the question. Microsoft struggles too by answering it and the Linux community as well. This was the reason, why they have developed both an alternative to C++. The disadvantage is, that these alternatives are slow (in case of C#) or they are complicated to program (in case of GTK+ and gobject). That means, the original idea of C++ is not perfect, but potential alternatives are also criticized as the wrong way.
To investigate the situation in detail we have to do again a step back and describe first which kind of technology is perceived as stable. The combination of a structured language like C plus a compiler is a best practice method in modern software engineering. There is no need to interpret a c program because this would reduce it's executation speed. All the important libraries in an operating system are written in pure C, and this is used in all operating systems. The open question is, if the same compiler technique can be utilized for object oriented languages. It seems, that the problem has to do with pro and cons of object oriented programming.
OOP is a relative new development. It is something which is not available in assembly language and it isn't there in classical languages like Fortran or C. It's hard to define what object oriented programming is. On the first look, it's a language feature, which is built in into the syntax, but at the same it's also a software engineering technique which was made famous with the UML notation. Especially in the Python environment, OOP is used as a prototyping technique to develop software from scratch.
From a critical perspective the question is, if OOP is needed in classical programming. Suppose the look and feel of an application is already known and the algorithm is fixed. Then the advantage of OOP is relative low. That means, in most cases, the more efficient way in creating sourcecode is to not create classes but to utilize lowlevel techniques like pointers and linked lists.
I think it's important to make clear what kind of best practice method is accepted widely and which not. What is used by all programmers is to compile a structured language like C, and use Object oriented design for prototyping new applications. This is done with interpreted prototyping languages like Python. The open question is, how both parts can be combined. One option is to use C++, the other idea is avoid any OOP feature in executable code, or to introduce a Java like bytecode concept.
From a technical point of view, it's interesting to ask how an existing object oriented design in the UML notation can be converted into a non-OOP language like C. What are the steps to convert the Pacman ghosts and the other objects in a game, into normal structured programming code which gets compiled by a c compiler?
The answer can be found in concrete game project which utilizes the C language but not C++, https://stackoverflow.com/questions/43127769/creating-a-game-board-using-struct In the example game, the current game state is stored in a struct. And then the struct is given as a parameter to a function. It's easy to imagine who a pacman clone would be realized in plain C. The first thing is, to create an array struct which holds the ghosts. And then the item in the array is given to a move routine which adjusts the position.
What is different to object oriented programming is, that in the sourcecode there a no explicit classes given, but the machine model is used as a representation. That means, the program gets access to adress in memory, and can call subroutines. The prediction is, that this kind of programming style results into a faster program executation, because it comes closer to the inner working of a computer. Object oriented languages like C# or C++ are providing an additional layer not available in assembly language which makes the code slower.
Conclusion
Object oriented programming is at foremost a software engineering technique which allows humans to develop a prototype. Implementing OOP features into a computer language or a compiler make the system slower. From a computer point of view, the programmer should avoid object oriented programming and type in the sourcecode in normal C code.
Subscribe to:
Posts (Atom)