4 ms·
That's usually a sign of overly aggressive linters and static analyzers. They probably got a "no magic numbers" diagnostic. The solution to this problem is to
by humanrebar 7y ago
That's usually a sign of overly aggressive linters and static analyzers. They probably got a "no magic numbers" diagnostic.
The solution to this problem is to add some sort of `NOLINT` comment to that line or, if possible, the comment that turns off that particular check. Then you link to the design document describing what "arr" is and how its interface involves accessing indices 0 and 1.
Or you could wrap "arr" up in a class or function of some sort so the code is theoretically more self documenting.
- dymk 7y agoWe had no linters enforcing the "no magic constants" convention. If we did, I'd question the sanity of the engineer who added that linter. The reason we got code like this was because of outsourced contractors cargo-culting something they saw elsewhere.
- humanrebar 7y agoWell, maybe it's cargo culted from a place with such a linter. Or ornery peer reviewers who think their job is to be a human linter. Correcting this sort of stuff is the job of a senior engineer, though. If it's extremely frustrating, I'd become independently wealthy or stay away from technical leadership positions.
- BurningFrog 7y agoYeah, linters that make "you should usually do X" into "you MUST ALWAYS do X" cause a lot of terrible code.
- torgard 7y agoIt took me a while to understand the whole "no magic numbers" thing. I was basically just told that most (if not all) numbers should be stored in constants. So I just added int twentyFive and stuff, and it annoyed me, but my teacher was happy. Much later, I realized the missing part: Name the constant not what it is, but rather what it does. So int rightBoundary instead of twentyFive, and the code suddenly becomes much more readable.