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

{0} is a magic number. #426

Open
carlwilson opened this issue Mar 26, 2019 · 3 comments
Open

{0} is a magic number. #426

carlwilson opened this issue Mar 26, 2019 · 3 comments
Assignees
Labels
feature New functionality to be developed good-first-issue Issue suitable for inexperienced developers P2 Medium priority issues to be scheduled in a future release

Comments

@carlwilson
Copy link
Member

carlwilson commented Mar 26, 2019

There are more than 1400 occurrences of this issue.
Why is this an issue?
Since Checkstyle 3.1

Checks that there are no "magic numbers" where a magic number is a numeric literal that is not defined as a constant. By default, -1, 0, 1, and 2 are not considered to be magic numbers.

It is fine to have one constant defining multiple numeric literals within one expression:

static final int SECONDS_PER_DAY = 24 * 60 * 60;
static final double SPECIAL_RATIO = 4.0 / 3.0;
static final double SPECIAL_SUM = 1 + Math.E;
static final double SPECIAL_DIFFERENCE = 4 - Math.PI;
static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
static final Integer ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE = new Integer(42);

A full list of all occurrences on codacy can be found here

Not all numbers will need "fixing", for a decent guide on refactoring taste see: https://refactoring.guru/replace-magic-number-with-symbolic-constant/. This example: https://help.semmle.com/wiki/display/JAVA/Magic+numbers shows the use of public static class constants as opposed to method level constants.

You can find all occurrences of this issue here on Codacy.

@carlwilson carlwilson added feature New functionality to be developed P2 Medium priority issues to be scheduled in a future release labels Mar 26, 2019
@carlwilson carlwilson added the good-first-issue Issue suitable for inexperienced developers label Apr 23, 2020
@marti1125
Copy link
Member

Hi @carlwilson I would like to work in this issue

@carlwilson
Copy link
Member Author

@marti1125, you have your way, be careful what you wish for ;)

@MartinSpeller
Copy link

carlwilson added a commit that referenced this issue Jun 10, 2020
@carlwilson carlwilson modified the milestones: Hackathon tasks , OPF Hackathon 2023 Tasks Jun 21, 2023
@carlwilson carlwilson removed this from the OPF Hackathon 2023 Tasks milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality to be developed good-first-issue Issue suitable for inexperienced developers P2 Medium priority issues to be scheduled in a future release
Projects
Status: No status
Development

No branches or pull requests

3 participants