Go-tools: Suggest replacing variables that have constant values with actual constants

Created on 17 Oct 2020  路  4Comments  路  Source: dominikh/go-tools

var magicNumber = 42
use(magicNumber)

could use a const instead. Using a real constant would signal to people and tools alike that the value of the variable intentionally never changes.

Labelled as needs-decision for now because I'm not sure how much people appreciate "technically better" suggestions.

needs-decision new-check

Most helpful comment

@cespare should be easy enough to implement, and I'll definitely create a prototype before deciding on this issue. I'll let you know when there's something to test (but that will still be a while.)

All 4 comments

On the surface it sounds good. How hard is it to implement? I'd be interested in running it over my code if you have some prototype.

@cespare should be easy enough to implement, and I'll definitely create a prototype before deciding on this issue. I'll let you know when there's something to test (but that will still be a while.)

As long as the check will take into account const vs. var quirks, like the ones in #833 and golang/go#28591, I'm all for it.

Another quirk to be mindful of: negative zero floating point.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jtreleaven picture jtreleaven  路  3Comments

igungor picture igungor  路  3Comments

tallclair picture tallclair  路  3Comments

ainar-g picture ainar-g  路  4Comments

ainar-g picture ainar-g  路  4Comments