Blog 5 Min. Lesezeit

Finger weg von meinem C++-Code

Artikel teilen
Don't touch to my C++ code.

Im Jahr 2005 arbeitete ich in einem Unternehmen, in dem der Großteil des Codes in C++ geschrieben war. 2006 beschloss das Management, neue Projekte in C# zu entwickeln und außerdem einige C++-Projekte nach C# zu migrieren. Gegen C++ führten sie folgende Argumente an:

  • C++ ist zu komplex.
  • Das C++-Build-System ist zu schwierig zu verwalten und zu warten.
  • C++ hat viele Jahre stagniert und ist auf dem Weg, auszusterben.
  • Es ist sehr schwierig geworden, C++-Entwickler zu finden.

Und natürlich gibt es im Web zahlreiche weitere Meinungen, die Verantwortliche davon abhalten, die Entwicklung mit C++ fortzusetzen.

More important than security is the fact that C and C++ are simply too hard to program, compared to any safe language. Not only is it too easy to write a catastrophic bug in C/C++, it is even easier to write more ordinary bugs. And these bugs are very often not caught by the compiler; they are discovered months or years later, in production, often after the programmer who wrote them has moved on.
As a multi-paradigm system programming language, C++ is a complete beast when it comes to its feature-set and its specs, followed up with a steep learning curve and a very long path to mastery. It’s challenging to keep track of all its complex syntactical constructs that more often than not seem confusing and ambiguous.
C++ does not have a proper module system that most modern languages provide. D, Java, C#, Python, Clojure, you name it. All of them got one. In combination with its primitive preprocessor, this usually results in a messy structure of header files and implementation files that rely on include guards to give basic protection against multiple inclusion.

Damals hatten wir als C++-Entwickler nur wenige überzeugende Argumente, um sie davon abzubringen, C++ aufzugeben – insbesondere weil Microsoft .NET gegenüber C++ stark bewarb und rund um die .NET-Technologie ein großer Hype entstanden war.

Inzwischen schreiben wir das Jahr 2018, und die Sprache C++ hat sich stark weiterentwickelt. Die Frage lautet daher: Wenn Ihr Unternehmen beschließt, sich von C++ abzuwenden, mit welchen Argumenten können Sie das Management davon überzeugen, C++ weiterhin einzusetzen?

Zunächst wäre es ein Fehler, so zu tun, als sei inzwischen alles in Ordnung und C++ habe sämtliche Schwächen überwunden. Es gibt weiterhin vieles zu verbessern, wenn wir die Wahrnehmung ändern wollen, C++ sei zu einer Sprache geworden, die sich vor allem an Experten richtet.

Glücklicherweise gehört es zu den Zielen des C++-Komitees, die Sprache einfacher nutzbar zu machen, wie Herb Sutter in einem kürzlich geführten Interview erläuterte:

Since mid-2015 in particular, I decided to focus my work on seeing if I could find ways to make C++ programs simpler. Because C++ has a long-term future, anything we can do to make C++ programs easier to write, read, and maintain will deliver big benefits to the whole industry.

The way I went about it was by systematically looking at C++ code and seeing where all the boilerplate is – that is, find the things that C++ programmers already do all the time, but that they are forced to express indirectly with excessive ceremony or in complex and brittle ways, and see if we can find a very small number of general mechanisms that could let them express those things in a simpler and more direct and robust way. If we can find the places where we regularly have to fight the language (such as the language’s defaults) or work around the language (such as by using macros or proprietary language extensions) or just rely on English advice (Scott Meyers’ books are great, but wouldn’t it be great if we didn’t need to say 75% of what’s in them), and in those places be able to directly state what we want, that would be actively improving those things that we are doing already.

A “small” historical example is the range-based for loop: We could already write for loops that visit each element, but it took more ceremony such as writing the incrementing logic by hand, and it had more ways to go wrong such as inadvertently incrementing the index or iterator in the body of the loop and skipping elements. By having a ranged-based for in the language, we elevated that very common coding pattern into a language feature that lets us now say directly what we want to do, namely visit each element in order, and that is obviously correct by construction just by looking at the first line of the loop without looking inside the body to see if it might skip elements or something. And I think the range-based for loop, though a “small” feature, was one of the major successes of C++11 – an improvement that people now use every day. Adding it to the language made the language (slightly) bigger, but it made C++ programs simpler.
  • Das erste Argument für C++ lautet, dass seit 2011 zahlreiche Features hinzugekommen sind, die die Sprache verbessern, und weitere folgen werden, um ihre Verwendung zu erleichtern. Um dieses Argument überzeugender zu untermauern, lohnt sich ein Blick auf einige Codebeispiele aus modernen C++-Bibliotheken und -Projekten.
  • C++ ist längst nicht mehr auf dem Weg auszusterben; zahlreiche Rankings von Programmiersprachen zeigen vielmehr, dass C++ wieder an Bedeutung gewinnt.
  • Auch in Entwicklerforen ist C++ weiterhin äußerst präsent. Ein Blick auf Stack Overflow genügt: Dort werden täglich zahlreiche Fragen zu C++ gestellt.
  • C++ wird nach wie vor häufig für die Entwicklung neuer Projekte eingesetzt, wie das GitHub-Ranking in diesem interessanten Beitrag über die Entwicklung der auf GitHub verwendeten Programmiersprachen zeigt.
  • Die C++-Community wächst. Ein Blick auf Google+, LinkedIn, Facebook oder Twitter zeigt, dass sich immer mehr Nutzer für C++ interessieren.

Zusammenfassend lässt sich sagen: Dass C++ zurück ist und leistungsfähiger denn je, ist nicht nur eine subjektive Einschätzung – die Zahlen sprechen für sich. Heute gibt es zahlreiche gute Argumente dafür, bestehenden C++-Code beizubehalten. In vielen Fällen liegt die Entscheidung zwar nicht bei den Entwicklern, doch sie können die Argumente auswählen, die am besten zu ihrem konkreten Umfeld passen, und damit das Management davon überzeugen, C++ weiterhin als zentrale Programmiersprache einzusetzen.

Artikel teilen