From 05118054f6cb6899218a5fa8ff6068049e75bc9d Mon Sep 17 00:00:00 2001 From: Bjarne Stroustrup Date: Tue, 18 Apr 2017 18:11:30 -0400 Subject: [PATCH] NL.11 literals --- CppCoreGuidelines.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 7140b00..374ec16 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -18853,6 +18853,7 @@ Naming and layout rules: * [NL.8: Use a consistent naming style](#Rl-name) * [NL.9: Use `ALL_CAPS` for macro names only](#Rl-all-caps) * [NL.10: Avoid CamelCase](#Rl-camel) +* [NL.11: Make literals readable](#Rl-literals) * [NL.15: Use spaces sparingly](#Rl-space) * [NL.16: Use a conventional class member declaration order](#Rl-order) * [NL.17: Use K&R-derived layout](#Rl-knr) @@ -19160,6 +19161,38 @@ Some IDEs have their own opinions and add distracting space. We value well-placed whitespace as a significant help for readability. Just don't overdo it. +### NL.11: Make literals readable + +##### Reason + +Readability. + +###### Example + +Use digit separators to avoid long strings of digits + + auto c = 299'792'458; // m/s2 + auto q2 = 0b0000'1111'0000'0000; + auto ss_number = 123'456'7890; + +###### Example + +Use literal suffixes where clarification is needed + + auto hello = "Hello!"s; // a std::string + auto world = "world"; // a C-style string + auto interval = 100ms; // using + +###### Note + +Literals should not be springled all over the code as ["magic constants'](#Res-magic), +but it is still a good idea to make them readable where they are defined. +It is easy to make a yypo in a long string of integers. + +###### Enforcement + +Flag long digit sequences. The trouble is to define "long"; maybe 7. + ### NL.16: Use a conventional class member declaration order ##### Reason