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.
No comments:
Post a Comment