What if I am terribly wrong about C++?

I’ve been running away from C++ for most of my professional career. And I have to admit, in 15 years, I didn’t run away very far.

My first full-time job was about maintaining a project written by five different teams over eight years. Every team brought the fad of their own into the project so it had everything from 3-star programming to the Alexandrescu-style template magic. It wasn’t something designed from the top. Or from the bottom. It was more like a scrapheap challenge project.

By that time, I already had some experience with Delphi, C, Python, and Assembly from academia and part-time jobs but C++ was new to me. Especially the “bring it all, bitch” type of C++.

Needless to say, I was not impressed by its elegance and simplicity since there was none of the latter or the former. Suddenly, the company needed someone to write shaders in GLSL, and I willfully agreed to give it a try. It couldn’t be worse than C++, right?

And it wasn’t. Next, there were tools in MASM32, tech-demos in plain C, a game scene editor in C#, a game engine in Objective-C, a side project in ActionScript, a documentation system in PHP, some front end works in JavaScript, some back end works in Erlang, a bit of Haskell, a bit of Scheme, C again, Assembly again, Python again and again and again.

I gathered some of these experiences into essays and even published a free book about this whole adventure. The conclusion, both from the career and the book is, not only all these things are not worse than C++ but C++ is not worse than all these things.

Or, in other words, they are all equally bad. Or good, it really depends on your perspective.

In my opinion, the whole language design was running in circles for the last 50 years or so. There is no new language that would differ from C++ more than APL (1959) differs from Prolog (1972). There are no distinct advantages in Julia or Rust or even Idris that could make C++ obsolete. There is no reason to invest heavily in a new shiny thing if you’re getting the same assembly with the same effort in it.

C++ is fine enough to live and prosper.

But what if I am terribly wrong?

I mean, I am ok with C++ but I did spend a lot of time practicing C++. I am quite obviously biased by experience. And all the diving into other languages only made this bias worse. For instance, encapsulation in C++ is pretty much like an alcoholic hiding a bottle from the future self. But in Objective-C, it suddenly starts to make sense. Objects are not just structs with functions, they are truly separated entities with thin interfaces.

Type system in C++ is meant mostly to aggravate people from teams other than yours. But in Haskell, with its type-classes setting explicit relations between types, it really brings value into the design.

Unlike in D which allows you meta-programming in D itself, template meta-programming in C++ is alien even to C++. But when you realize that it’s actually a completely different language trying to get out, you see it in another light.

So yes, I may have learned a few languages through the years but essentially I just learned C++ better. And now it’s suddenly ok. No wonder.

But what about someone who didn’t have this experience? Do they have to struggle?

How much effort people from all over the world spend fighting the compiler to do things right? Fixing the bugs that didn’t have to occur in the first place? Redesigning the code written back when multiple inheritance was considered cool since Java doesn’t have it?

Does it really make sense to invest years in mastering a language instead of mastering the domain? Learning all the accidental quirks of it, learning the best practices, learning the pitfalls?

From the user’s standpoint, a programming language is about just as relevant to the product as a text editor the programmer uses. It’s just something that automates machine code generation. A transformer that turns programming ideas into an executable thing that does the actual work.

Work is important, the language isn’t.

And C++ is just not effective enough in turning programmers’ ideas into products. Its accidental complexity brings too much overhead. If a junior programmer spends half a day working on a problem pen-and-paper style, and then half a day programming it in C++, they only do something that contributes to the world half of the day. Half of the day spent on googling C++ reference is just a waste.

It would have been fine if there were no alternatives to C++ but there are. Some are more prominent than others but they all suffer from the C++ shadow. Remember, from the standpoint of people like me, C++ is fine enough to live and prosper. We’re already too much invested in the current system to learn things that bring no clear benefit for us.

And now for the big question. I’m honestly on the fence with this one and I’d like to hear from you in the comments or otherwise.

Should we, the experienced C++ programmers, discourage C++ usage among less experienced programmers like long time smokers discourage smoking among the younger generation?

It does hurt right in the ego but it seems the ethical thing to do, too.

I mean, sure, I’ve wasted a lot of time convincing the compiler not to be a douche, and I learned to find a masochistic pleasure in doing that, but it’s really not what software creation should be about. If there are better tools, if they save time, save frustration, then maybe we should if not adopt them personally then maybe not divert other people from adopting them?

Again, it’s not a rhetorical question. I honestly don’t know. If you could convince me that this is the right thing to do, I’ll stop publishing anything C++ related on my https://wordsandbuttons.online.

P. S. I’ve added a Twitter poll for this question: https://twitter.com/wordsandbuttons/status/1299666634265763842

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store