C++ complexity: it's a feature

Posted by user on 22 Jan 2016

One of the constant reproaches we can hear about C++ is that it is too complex, too hard, too unsafe and has too many features, really these r-value references are useless and dangerous and why would you need variadic templates anyway, and "lol" you are still managing memory manually in 2016.

It's easy to believe you need only two kind of screwdrivers when you have only met slot and cross screw drives. It's easy to mock the ridicule of a large toolbox with arcane and complex tools that take a while to master and can maim the user.

C++ is rich. That's granted. It has many features. You cannot cut down on the list easily because people are actually using the feature you think is useless. The .* operator sounds ridiculous to you? I've used it more than once, and not because I could, but because it was actually useful.

C++ has history. That's something you can't remove or fix. Sure, if you start a language from scratch, that problem is gone, but if your programming language is going to be actually used for similar tasks, it will very likely suffer from the same problems ten years down the road.

Nothing prevents you from not using features you don't need, and actually, when working on a C++ project you should restrain yourself to a dialect. That is you can go for a Javaesque C++ with virtual inheritance and OOP paradigms, but you can also go generic, template heavy and compile-time checks all the way (which would be my personal choice).

The real trap of C++ is to end up with a byzantine program because you mix all the concepts into a single project. This, you shouldn't do.

C++ is unsafe. It's an expert toolbox meant to be used when you actually know what you're doing. The C++ community has been able to produce guidelines and patterns to mitigate this lack of safety (with modern C++ it's now much more difficult to have buffer overruns and memory leaks for example) but when you need to set the bit of a memory address to a certain address without regards for safety, because this memory address is used by a device and flipping the bit signals that very device it should, launch a missile and kill all humans, you can.

In Saint Petersbug you can visit the C-189 submarine. Inside the submarine there is a plaque saying that you shouldn't use an equipment before understanding how it works.

C189

The same goes for C++ (or any programming language for that matter). We realize the toolbox is fancy and some tools look definitely awesome but if you don't want C++ to blow in your face, make sure you understand how it works before using it.

There are a certain number of programming languages attempting to go after C++ market shares by improving on its weaknesses (and there are weaknesses). I think it's great and that it gives a lot of great ideas to everyone. However, from a language survival perspective I think C++ 11 and even more C++ 14 greatly narrowed the window of opportunity.

That being said I would like to say that my hate for std::string knows no limit.

Topics: cpp, programming, rant, Uncategorized