4 ms·
Eh, it seems the author never worked for a big organization and when it finally did, it has a pet peeve. Lemme tell you, every single organization that respect
by unnouinceput 5y ago
Eh, it seems the author never worked for a big organization and when it finally did, it has a pet peeve.
Lemme tell you, every single organization that respect itself, it will tell you, during code review, that you do not use magic numbers in code. It's a red flag, so his "Do this: frobnicate(timeout_seconds=300)" will actually fail the code review.
Here is what you would do instead. Declare a constant in some constants only unit, with explanation what it does and then use that constant, like this:
//constant unit
const TIMEOUT_SECONDS = 300;//bla bla why this is 300 seconds, usually from client requirement
//code unit
frobnicate(TIMEOUT_SECONDS);
- aembleton 5y agoIn this case, the units are in the variable name. I think that was what the author was arguing for.
- gpderetta 5y agoBut that still using a magic number, so obviously you should do something like this: const TIMEOUT_SECONDS = ONE * HUNDREDS; The definition of ONE and HUNDREDS is left as an exercise. Snark aside, the rule zero of all coding conventions is that they should not be applied if they do not make sense in a specific case.
- unnouinceput 5y agoThe "bla bla" explanation will suffice. Usually will include a link to documentation, no need to further split the hair