Description:
A magic number is a hardcoded numeric value used directly in the code without explanation. Magic numbers reduce the readability and maintainability of the code because they lack descriptive context. If the value needs to be changed or reused, developers must hunt through the code to find all instances of the number, increasing the risk of errors.
Impact:
Reduced Code Readability:
Other developers or auditors may struggle to understand the purpose of the hardcoded value, making the code harder to interpret and debug.
Increased Risk of Errors:
If the same magic number is used in multiple places and needs to be updated, there's a higher chance of missing one instance or inconsistently applying the update.
Lack of Flexibility:
Magic numbers make it difficult to change behavior dynamically or adapt to new requirements since the hardcoded values aren't centralized.
Recommended Mitigation:
use a const with values of all magic numbers.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.