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.
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
#definedirective with this number in header file.In that case it should be like:
The similar sutuation with
AllHitboxInf::animationProcess.For example, in this function:
We can't understand what does
1mean, without comments. In this situations, we should useenum, like:These are just two examples, there is a lot of this in the code.