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

Hardcoded numbers #13

Closed
pauliax opened this issue Nov 18, 2017 · 1 comment
Closed

Hardcoded numbers #13

pauliax opened this issue Nov 18, 2017 · 1 comment
Labels

Comments

@pauliax
Copy link

pauliax commented Nov 18, 2017

    require(_matronId <= 4294967295);
    require(_sireId <= 4294967295);
    require(_generation <= 65535);

// ... some other code...

    require(newKittenId <= 4294967295);

It's generally advised to avoid hardcoded numbers in functions. Functions shouldn't have magic numbers inside it. It makes harder to maintain the code and also decreases readability. Imagine if you use a magic number, let's say 350 ten times in your code. One day you decide to change it from 350 to 360. What do you do? You search all occurrences in the code and change them. If you have this value extracted, you can change it only in one place to achieve the same effect.

@dete dete added the wontfix label Nov 19, 2017
@dete
Copy link

dete commented Nov 19, 2017

Functions shouldn't have magic numbers inside it.

I totally agree, but – believe it or not! – we didn't realize until recently that Solidity efficiently supported named constants. (See #6.)

We're actually planning on replacing these checks with a technique @Arachnid suggested in the Gitter chat (link).

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

No branches or pull requests

2 participants