diff --git a/doc/contributing/source/coding-style.rst b/doc/contributing/source/coding-style.rst index 4c891e5a3..d9220665a 100644 --- a/doc/contributing/source/coding-style.rst +++ b/doc/contributing/source/coding-style.rst @@ -97,8 +97,7 @@ Disable formatting in specific files or lines ============================================= To disable formatting in specific lines, surround them with the following -C++ comments [example adopted from -`official clang-format documentation `_]: +C++ comments: .. sourcecode:: cpp @@ -917,17 +916,21 @@ to print the numeric value of any variable, such as: Avoid unnecessary casts if minor changes to variable declarations can solve the issue. In the following example, ``x`` can be declared as ``float`` instead of -``int`` to avoid the cast: +``int`` to avoid the cast, or write numbers in decimal format: .. sourcecode:: cpp // Do not declare x as int, to avoid casting it to float int x = 3; - return 1 / static_cast(x); + float y = 1 / static_cast(x); // Prefer to declare x as float float x = 3.0; - return 1 / x; + float y = 1 / x; + + // Or use 1.0 instead of just 1 + int x = 3; + float y = 1.0 / x; Namespaces ========== @@ -1087,7 +1090,7 @@ can be rewritten as: if (n < 0) { - return n; + return false; } n += 3;