https://bugs.documentfoundation.org/show_bug.cgi?id=145759

            Bug ID: 145759
           Summary: Convert magic numerical constants to symbolic
                    constants
           Product: LibreOffice
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
          Severity: normal
          Priority: medium
         Component: LibreOffice
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Using a numerical literal directly in the code can cause problems. Because of
this, it is suggested that it should be replaced by some numerical constant.

ES.45: Avoid "magic constants"; use symbolic constants
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-magic

If it is known (like π), you should use the appropriate symbolic constant like
M_PI. If not, you should define a new constant with proper name and type with
'contsexpr'.

One solution to find such magic constants is to start from a list of some well
known mathematical constants:
https://en.wikipedia.org/wiki/List_of_mathematical_constants

Then, store some of them in a text file, let's say 'constants.txt', then search
for all these values inside CPP files:

git grep -Ff constants.txt *.cxx *.hxx

Many of these symbolic constants like M_PI are already defined in C++ standard
library or some place in the LibreOffice code, and you can use them easily.

You should examine the 'grep' results carefully, because not every 3.14 refers
to PI.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to