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

Multiplicative 2 should not be considered a magic number #12

Open
Ryan1729 opened this issue Aug 21, 2020 · 0 comments
Open

Multiplicative 2 should not be considered a magic number #12

Ryan1729 opened this issue Aug 21, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Ryan1729
Copy link

Ryan1729 commented Aug 21, 2020

The 2 is considered a magic number in the following code.

func center(x, y, w, h int32) (cx int32, cy int32) {
	cx, cy = w/2+x, h/2+y

	return
}

In my opinion, whenever a number is divided by 2 or 2 and another number are multiplied together, then it is (almost?) always clear what is meant, and therefore it shouldn't be considered a magic number.

Trying to avoid it being considered a magic number with something like the following seems worse than leaving it as 2:

const havler = 2

func halve(x int32) (out int32) {
	out = x / havler

	return
}

That said, I think that something like this should still be counted as a magic number:

func foo(x int32) (y int32) {
    y = x + 2

    return 
}

(I'm using the named return value form, so that the examples actually produce error messages, given #11 is unresolved as I write this.)

@tommy-muehle tommy-muehle self-assigned this Jan 26, 2021
@tommy-muehle tommy-muehle added the enhancement New feature or request label Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants