C++ For The 21st Century
Monday, 17 February 2025

C++ is a language under attack from newer languages such as Rust and from more primitive languages such as C, yet it has a large community of committed and enthusiastic users. How can things be made better? Its creator Bjarne Stroustrup has some ideas.

I admit to being a C++ lover/hater. The ability to create classes and objects without having to give up the basic access to the hardware that C gives me is a big attraction. I also find the language very clear and elegant, when written properly. However, I tend to steer clear of C++ in other people's projects because I cannot think of a language which is written in so many different styles - and some of them are terrible. I think C++ is a very dangerous language because of the way it has accumulated features without dropping older features all in the name of backward compatiblity.

Bjarne Stroustrup

 

The most consistent voice for writing high quality C++ has been its creator Bjarne Stroustrup. Whenever I read something by him I am convinced, for a few hours at least, that C++ is a great language. And so it is again with his latest missive, 21st Century C++. This is an outline of how C++ can be mutated into something modern and safe. 

He starts out by describing how you can write better versions of old code just using the new features of C++, but this fails to convince me that the language is the key because the examples are better because of the use of data objects and this is an object-oriented versus procedural distinction. The fact that many C++ programmers don't think of using a map or a set is, well something we encounter in any language. Educating people about objects isn't making C++ better.

Stroustrup then goes on to outline the desirable properties of C++, of any language really, but with no radical suggestions how to make this utopia a reality. He does list a collection of topics old and new that can help and then says:

"What matters is to use the language and library features as a coherent whole in ways that suits the problem to be solved.  Given the billions of lines of C++, we cannot change the C++ language incompatibly. However, we can change the way C++ is used."

Absolutely true but this is exactly the problem with C++ having such a wide range of possiblities.

The rest of the essay details some ideas which might help with the project. Adding automatic resource management is one option - when a resource goes out of scope it is destroyed. This is made easier by clarifying the lifecycle and the functions that control it. Making move- versus copy-semantics explicit. Don't use header files - modules are better. Make generics better. Use compile time predicate functions, "concepts" to do jobs like validating template parameters. The final suggestion is to move from guidelines to enforced profiles as a way of getting C++ back to a "good" core language.

Stroustrup seems to believe that the solution to improving C++ is mostly to get C++ programmers to use the language correctly and in a modern way. All I can say is good luck with that.

"However, the evolutionary approach caused some serious problems. Many people got stuck with an outdated view of what C++ is. Today, we still see endless mentions of the mythical language C/C++, usually implying a view of C++ as a minor extension of C embodying all the worst aspects of C together with grotesque misuses of complex C++ features. Other sources describe C++ as a failed attempt to design Java. Also, tool support in areas such as package management and build systems have lagged because of a community focus on older styles of use."

C++ needs a radical overhaul, but my guess is that this would make it a different language.

C++ was a great idea and it almost worked. Today it is a mess of a language which gives the programmer far to much scope for expression. This is a good thing for a poem - not so much for a program.

CppUdacitylogo

More Information

21st Century C++

Related Articles

Bjarne Stroustrup Defends C++ As Safe

Bjarne Stroustrup On Why Learn C++

Google's Carbon Is Trying To Be A Better C++

Bjarne Stroustrup Thinks He Has A Better Way To Do Generics

The Feds Want Us To Move On From C/C++

DARPA Wants All C Converted To Rust

Rust And C++ Should Be Friends?

C++ In The Linux Kernel?

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


JetBrains Adds Claude Support To AI Assistant
12/02/2025

JetBrains has added support for Anthropic's Claude Sonnet 3.5 and Haiku 3.5, OpenAI's o1, o1-mini, and o3-mini models to its AI-powered coding tool, AI Assistant, along with local LLM support via LM S [ ... ]



Unitree G1 - See How It Runs
26/01/2025

Chinese robotics company Unitree has made a significant breakthrough with its G1 humanoid robot which walks and runs in a convincingly natural way. This is thanks to its advanced hip joint design. See [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 

Last Updated ( Monday, 17 February 2025 )