Chapter 18

Nonrules and Myths

I assume that you already know many nonrules and myths about C++. Some of these nonrules and myths predate modern C++ and sometimes even contradict modern C++ techniques. Sometimes these nonrules and myths were best practices for writing good C++ code. The C++ Core Guidelines address the most resistant don’ts but also provide alternatives.

NR.1

Don’t insist that all declarations should be at the top of a function

This rule is a relict of the C89 standard. C89 doesn’t allow the declaration of a variable after a statement. This results in a significant distance between the variable declaration and its usage. Often the variable is not initialized. This is exactly what happens in the example provided by the C++ Core ...

Get C++ Core Guidelines Explained: Best Practices for Modern C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.