Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There are shouldn't be any magic numbers in code #8

Open
bogdasar1985 opened this issue Apr 4, 2021 · 1 comment
Open

There are shouldn't be any magic numbers in code #8

bogdasar1985 opened this issue Apr 4, 2021 · 1 comment

Comments

@bogdasar1985
Copy link
Contributor

bogdasar1985 commented Apr 4, 2021

Magic number is a numerical constant in the code, the purpose of which is unclear.
Example from Platform.cpp:

platformSpeed = speed * 0.00125;

What does 0.00125 mean?
In most cases, this is corrected by adding #define directive with this number in header file.
In that case it should be like:

// Platform.h
#define MEANING_OF_MAGIC_NUMBER 0.00125

The similar sutuation with AllHitboxInf::animationProcess.
For example, in this function:

// Platform.cpp : line 45
void Platform::drawObject(float &time)
{
    if (AHI->animationProcess != 1)
        movePlatform(time, AHI);
}

We can't understand what does 1 mean, without comments. In this situations, we should use enum, like:

enum
{
    LEVEL_PASSING,
    LEVEL_PASSED_ANIMATION,
    LEVEL_PASSED
};

These are just two examples, there is a lot of this in the code.

@fregate
Copy link

fregate commented Dec 9, 2022

Not a define - use some constants, like
constexpr double SPEED_MULTIPLIER = 0.00125;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants