What is Modern C++?

Contents[Show]

We often speak about classical and modern C++. What does that mean? First of all: What is modern C++?. There is a simple and a not so simple answer? The simple answer is. Modern C++ stands for C++ that is based on C++11, C++14, and C++17. I guess you know it. This post and a series of further posts are about the not so simple answer.

 

With C++11 we had a revolution. That revolutions became with C++14 and will become with C++17 to an evolution. An overview of the timeline of C++ features makes my point clear.

 timeline

If you look at the sheer amount of features we got since C++11 and the reason for their impact, you must come to the conclusion: C++ before 2011 and since 2011 are different languages. The first is called classical C++, the second modern C++. Therefore, the idiomatic way to program C++ before and after 2011 is totally different.

Now you already know it. I want to answer the question. How does this powerful feature changed the way we think about programming in C++? That is the not so simple question I want to answer.

Two resources

I'm not alone in my search. There are great resources available. Here are two of them.

C++ Best Practices

C++ Best Practices from Jason Turner is a "Collaborative Collection of C++ Best Practices". It's a highly valuable source for modern software development with C++ and general considerations of good C++ code. These general considerations include the safety, maintainability, portability, threadability, and performance of the code.

Today, I will not emphasise the general considerations of the code, I will emphasise the collection of tools he provides in his C++ Best Practices.

His C++ Best Practices includes a collection of a lot of tools for

  • source control
  • building software,
  • continuous-integration
  • compilers such as gcc, clang, and msvc
  • static code analysis 
  • runtime checkers
  • testing
  • debugging

If you are a professional software developer - I guess you are because you read the post - and have to make a decision on what tools you should use in your professional software development process you should use this great resource to get an idea of what tools are available.

Today, I want to give you an idea of what I will write about in the next posts. My main topic will be the C++ Core Guidelines.

C++ Core Guidelines

Here are the goals from the abstract: "This document is a set of guidelines for using C++ well. The aim of this document is to help people to use modern C++ effectively. By "modern C++" we mean C++11 and C++14 (and soon C++17)."

The editors are Bjarne Stroustrup and Herb Sutter.

The C++ Core Guidelines are a set of more than 100 rules. These rules are divided into major sections and supporting sections. Here are the major sections.

I want to have a closer look at the Introduction section. It deals with meta-rules such as:

Let me paraphrase the meta-rules. The target reader is even a C programmer. The aim of the rules is to help developers to adopt modern C++ (C++11, C++14, and soon C++17). These rules emphasise static type safety and resource safety. You should understand the rules because they are prescriptive. The rules have aims and non-aims. They are not intended to be minimal or orthogonal, should be read serially, are not a substitute for tutorial treatment. The rules are either a guide to port old C++ code to new one nor should they be exact in each language detail, or enforce an impoverished subset of C++, or are value-neutral or perfect. Each rule has an enforcement section because the guidelines should help people to make their code uniform and modernise them. The rules follow a uniform structure. The structure consists of the points 

  • Rule 
  • Rule Reference Number
  • Reason 
  • Examples
  • Alternatives
  • Exceptions
  • Enforcement of how the rule might be checked "mechanically"
  • See alsos
  • Note
  • Discussion 

To be honest that strongly reminds me of the (design) pattern literature. 

To make the intent of the structure clear here is a short example the rule R.22. The R stands for resource management:

R.22: Use make_shared() to make shared_ptrs

Reason

If you first make an object and then give it to a shared_ptr constructor, you (most likely) do one more allocation (and later deallocation) than if you use make_shared() because the reference counts must be allocated separately from the object.

Example
Consider:
shared_ptr<X> p1 { new X{2} }; // bad
auto p = make_shared<X>(2);    // good

The make_shared() version mentions X only once, so it is usually shorter (as well as faster) than the version with the explicit new.

Enforcement

(Simple) Warn if a shared_ptr is constructed from the result of new rather than make_shared.

What's next?

Before I wrap up this post, I want to say a few remarks about my motivation for writing about modern C++ and in particular about the C++ Core Guidelines. During writing about my motivation, I recognized, that I can not express my motivation in few sentences. So you know what the next post will be about.

 

 

Thanks a lot to my Patreon Supporters: Matt Braun, Roman Postanciuc, Tobias Zindl, Marko, G Prvulovic, Reinhold Dröge, Abernitzke, Frank Grimm, Sakib, Broeserl, António Pina, Sergey Agafyin, Андрей Бурмистров, Jake, GS, Lawton Shoemake, Animus24, Jozo Leko, John Breland, espkk, Louis St-Amour, Venkat Nandam, Jose Francisco, Douglas Tinkham, Kuchlong Kuchlong, Robert Blanch, Truels Wissneth, Kris Kafka, Mario Luoni, Neil Wang, Friedrich Huber, lennonli, Pramod Tikare Muralidhara, Peter Ware, Tobi Heideman, Daniel Hufschläger, Red Trip, Alexander Schwarz, Tornike Porchxidze, Alessandro Pezzato, Evangelos Denaxas, Bob Perry, Satish Vangipuram, Andi Ireland, Richard Ohnemus, Satish Vangipuram, and Michael Dunsky.

 

Thanks in particular to Jon Hess, Lakshman, Christian Wittenhorst, Sherhy Pyton, Dendi Suhubdy, Sudhakar Belagurusamy, Richard Sargeant, Rusty Fleming, and Said Mert Turkal.

 

 

My special thanks to Embarcadero CBUIDER STUDIO FINAL ICONS 1024 Small

 

Seminars

I'm happy to give online seminars or face-to-face seminars worldwide. Please call me if you have any questions.

Bookable (Online)

German

Standard Seminars (English/German)

Here is a compilation of my standard seminars. These seminars are only meant to give you a first orientation.

New

Contact Me

Modernes C++,

RainerGrimmSmall

 

Comments   

0 #1 Roland Ihasz 2017-06-19 08:49
Great short and very informative post. Nice work. Thanks
Quote
0 #2 Vadixem 2017-06-20 08:28
Good post, Guess gonna read one of these.
Quote
+1 #3 masinde70 2017-06-20 10:50
Great work! Thanks
Quote
+1 #4 Szambo 2017-07-22 03:28
Hello there, You've done an incredible job. I will certainly digg it and personally recommend to my friends.
I'm sure they will be benefited from this site.
Quote
+1 #5 Patrick 2017-12-17 02:47
Thanks for a marvelous posting! I really enjoyed reading it, you're a great author.

I will remember to bookmark your blog and will come
back someday. I want to encourage one to continue your great work, have a nice morning!
Quote
0 #6 shelby news 2018-05-26 04:44
Great post.
Quote
-1 #7 Michael Vera 2020-04-09 12:22
Author is absolutely clueless on the use of commas.
Quote

My Newest E-Books

Course: Modern C++ Concurrency in Practice

Course: C++ Standard Library including C++14 & C++17

Course: Embedded Programming with Modern C++

Course: Generic Programming (Templates)

Course: C++ Fundamentals for Professionals

Interactive Course: The All-in-One Guide to C++20

Subscribe to the newsletter (+ pdf bundle)

Blog archive

Source Code

Visitors

Today 8527

Yesterday 10973

Week 19501

Month 180175

All 6828867

Currently are 172 guests and no members online

Kubik-Rubik Joomla! Extensions

Latest comments