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++, which 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 revolution began 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 conclude: C++ before 2011 and since 2011 are different languages. The first is called classical C++, and the second modern C++. Therefore, the idiomatic way to program C++ before and after 2011 is 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 precious source for modern software development with C++ and general considerations of good C++ code. These general considerations include the code's safety, maintainability, portability, threadability, and performance.

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

His C++ Best Practices include 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 decide 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 following posts. My main topic will be the C++ Core Guidelines.

 

Rainer D 6 P2 540x540Modernes C++ Mentoring

Be part of my mentoring programs:

 

 

 

 

Do you want to stay informed about my mentoring programs: Subscribe via E-Mail.

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 rules aim to help developers adopt modern C++ (C++11, C++14, and soon C++17). These rules emphasize 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, and are not a substitute for tutorial treatment. The rules are either a guide to port old C++ code to new ones, nor should they be exact in each language detail, enforce an impoverished subset of C++, or are value-neutral or perfect. Each rule has an enforcement section because the guidelines should help people make their code uniform and modernize 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 also
  • Note
  • Discussion 

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++, particularly the C++ Core Guidelines. During writing about my motivation, I recognized that I could not express my motivation in a 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, G Prvulovic, Reinhold Dröge, Abernitzke, Frank Grimm, Sakib, Broeserl, António Pina, Sergey Agafyin, Андрей Бурмистров, Jake, GS, Lawton Shoemake, Animus24, Jozo Leko, John Breland, Venkat Nandam, Jose Francisco, Douglas Tinkham, Kuchlong Kuchlong, Robert Blanch, Truels Wissneth, Kris Kafka, Mario Luoni, Friedrich Huber, lennonli, Pramod Tikare Muralidhara, Peter Ware, Daniel Hufschläger, Alessandro Pezzato, Bob Perry, Satish Vangipuram, Andi Ireland, Richard Ohnemus, Michael Dunsky, Leo Goodstadt, John Wiederhirn, Yacob Cohen-Arazi, Florian Tischler, Robin Furness, Michael Young, Holger Detering, Bernd Mühlhaus, Matthieu Bolt, Stephen Kelley, Kyle Dean, Tusar Palauri, Dmitry Farberov, Juan Dent, George Liao, Daniel Ceperley, Jon T Hess, Stephen Totten, Wolfgang Fütterer, Matthias Grün, Phillip Diekmann, Ben Atakora, Ann Shatoff, and Rob North.

 

Thanks, in particular, to Jon Hess, Lakshman, Christian Wittenhorst, Sherhy Pyton, Dendi Suhubdy, Sudhakar Belagurusamy, Richard Sargeant, Rusty Fleming, John Nebel, Mipko, Alicja Kaminska, and Slavko Radman.

 

 

My special thanks to Embarcadero CBUIDER STUDIO FINAL ICONS 1024 Small

 

My special thanks to PVS-Studio PVC Logo

 

My special thanks to Tipi.build tipi.build logo

 

My special thanks to Take Up Code TakeUpCode 450 60

 

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.

  • C++ - The Core Language
  • C++ - The Standard Library
  • C++ - Compact
  • C++11 and C++14
  • Concurrency with Modern C++
  • Design Pattern and Architectural Pattern with C++
  • Embedded Programming with Modern C++
  • Generic Programming (Templates) with C++

New

  • Clean Code with Modern C++
  • C++20

Contact Me

Modernes C++,

RainerGrimmDunkelBlauSmall

 

Comments   

+1 #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

Stay Informed about my Mentoring

 

Mentoring

English 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

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

Course: Master Software Design Patterns and Architecture in C++

Subscribe to the newsletter (+ pdf bundle)

All tags

Blog archive

Source Code

Visitors

Today 978

Yesterday 6503

Week 27235

Month 7481

All 12085690

Currently are 312 guests and no members online

Kubik-Rubik Joomla! Extensions

Latest comments