Skip to content

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

Description

@bogdasar1985

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions