C++, or how I learned to stop worrying and love the Weight

When you read https://docs.python.org/2/library/socket.html and its cute, blue and yellow sidelines, its clear-cut and heavily commented functions and class definitions, when you pass by Crystal or Nim‘s simple yet demonstrative functionalities and syntax, or you delve into Dlang‘s beautiful red pages (with a good dose of Ye Olde Docs From Beyond the Century, sadly), coming back to https://en.cppreference.com/w/cpp/string/basic_string is a bit jarring.

It’s like there’s a language where the concept of streamlining things so the programmer doesn’t get lost in a Minoan-tier labyrinth doesn’t exist. Like we are all sponges, born and raised to suck in everything, then fed on poorly coded videogames and blue screens of death, until we become perfectly used to swallow anything program-ey and enjoy it. Sponge Lives do not matter after all, they can easily take 2 more hours on the documentation to get good.

Despite my snark, it is difficult for me to criticize C++ itself. Not really due to its qualities or faults: the faults are absurdly clear from the main page of cppreference. Versions, takebacks, layers upon layers of features over features that cover every possible use case in the Universe. I’m thinking that if someone ever wrote a C++ function called bloat(), all it would do is print « yes, more please ». The documentation model, doubtlessly just like the language itself, is archaic, disorganised and throws the baby, bathwater, bath, sink, bathroom and building at you. C++ is old, C++ is an utter failure at streamlining anything, C++ is shit to learn and if you want to get good at it, I suggest you stop drinking, smoking, doing drugs or crossing the street entirely, because that Quest will require that you live up to 70 years old at least.

C++ is also absurdly powerful, absurdly precise, absurdly awesome in all it can do, it’s the all-star cast of all the features you ever wanted to have, it has more power and performance than anything in the world.

If languages were « quality = (features * performance) », C++ would be the Strongest Language on Earth today.

Perfect is when nothing can be taken away.
Strongest is the one that best satisfies all needs.

Two very opposite goals, indeed, and that’s why they say that better is often the enemy of good.

C++ is the Strongest. C++ is also the language on which I learned coding, along with C. I hated C back in the day, so when it comes to coding, C++ was my first love. It’s difficult to criticise your first love. Even if she was a bitch.
C++ should be difficult for me to take down.

I stopped writing this article here and erased and rewrote the rest 5 times.
So yes, C++ IS difficult to take down for me. It took me rewrites and rewrites, because I have so much to say about, or rather against C++, that I would make an entire book on it instead of an article.

So today, let’s get to a first point, and come back later, as it will probably take a book’s worth anyway.

C++ is old. Very old. Full of libraries. And bloat.

Nameless Elvish Bug Hunter

Which is bad because it is, for all intents and purposes, the Ark of History, the Carrier of Passed Times, and a language that carries strongly a heritage whose value has now been outdated since decades.
In and out of itself, that’s a perfectly acceptable thing, if only because age comes to us all. C++ is a Third Generation language in my personal timeline, counting that the 1st generation was everything until C(yes, it is a gross simplification), C marked the entry into the second generation and made programming as we mostly know it, C++ and the OOP craze of the 80s marked the third generation, and the high-level, light syntax, production oriented languages of the 90s marked the 4th, and yet dominant generation.

But C++ has decided to take the extremely unpleasant habit of Not Aging. Reminds me of the James Bond movie Octopussy:

– You seem to have a nasty habit of surviving.

– Well, you know what they say about the fittest.

Khan to Bond

Octopussy is, by the way, a pretty terrible Bond movie and one of the most forgettable. It was after all the 13th or so Bond movie, so maybe after so many iterations it just has to grow stale.

Speaking of which, C++ is a language that now has at least 5 versions that I can remember, 98, 11, 14, 17, and 20. And 23 soon enough. It is a language that refuses to age and « rejuvenates » itself by appending new things on top of the old ever and ever again.

It’s a language that whenever I look at it, I see the nudges of Python seeping in here and there, between 11’s std::initializer_list, which finally syntaxed in the creation of lists of values:

auto a = {42};   // std::initializer_list<int>
auto b {42};     // int
auto c = {4, 2}; // std::initializer_list<int>
auto d {4, 2};   // error, too many

to also 11’s auto, which finally…made C++ look like a dumb outdated fuck for doing exactly what python does with type inferring, only you had to have a keyword for it.

auto i = 4;          // int 
auto d = 4.0;        // double
auto s = "text";      // char const * 
auto v = { 1, 2, 3 }; // std::initializer_list<int>

A keyword to replace a keyword, so you didn’t have to write type name = value. Now you just wrote keyword name = value. Progress. Look at what it’s chasing though:

i = 4             #int
d = 4.0           #float
s = "text"        #unicode string
v = [ 1, 2, 3 ]   #list

Clean and lean.

I can defend with great vigour C++98 or C++11 for what they were, but the official policy of the language’s board is that it should just keep bettering itself with more junk.
Except it’s not junk, it’s actual genuine features that do make the language far better. 17 tramples 14, 20 will trample 17.

And yet when I look at C++, I recall a time when I was a young boy at a train station with my father. He showed me a big locomotive and told me: « you see, this is a BB15000, you attach 20 wagons behind it, it’ll do 160km/h, you attach 50 wagons behind it, it’ll still do 160 km/h! ».

And like any young boy, I went « waaaaaah! » and asked: « And if you put 200 wagons behind it? »

Yeah, well then no, that’s too much.

The man who taught me everything

C++ is too much. I don’t even mean too much for a programmer, I mean for its own good.
A « feature » is only a feature if you use it. C++’s avalanche of features is so large that you could probably cut away half the language and half of its programmers wouldn’t even realise it, while the other half would scream in anguish.

It’s a collection of decades of ideas that have matured on top of an old C-based husk. I could say the same thing about Python in some ways, but at this point the canopy of features that C++ offers makes the Amazon forest look small and orderly.

So what should C++ do to fix itself?

Nothing. It shouldn’t fix itself. It should do as Khan says, and die.

Votre commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l’aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Google

Vous commentez à l’aide de votre compte Google. Déconnexion /  Changer )

Image Twitter

Vous commentez à l’aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s

Créer un nouveau site sur WordPress.com
%d blogueurs aiment cette page :