4 ms·
If you're using Javascript or Typescript, there is an Eslint rule called "no-magic-numbers" which enforces a rule where numbers are required to be assigned to a
by james2doyle 5y ago
If you're using Javascript or Typescript, there is an Eslint rule called "no-magic-numbers" which enforces a rule where numbers are required to be assigned to a variable: https://eslint.org/docs/rules/no-magic-numbers https://eslint.org/docs/rules/no-magic-numbers
You can set ones to ignore, a minimum value for the rule to apply, or require the variable to be a const.
- pojzon 5y agoThis is more about units. int length = 5 Is quite different than: int lenght_in_meters = 5
- hinkley 5y agoI'm a fan of the middle ground here where you limit magic numbers to known constants and arithmetic. This means some constants don't have magic numbers, but also some inline uses don't necessarily have constants. For instance 7, 24, 60, 1000 allowed in defining units of time, and any other intervals are defined as 5 minutes = 5 x 60 x 1000. Still, I've had plenty of experiences with 'is this unit in seconds or milliseconds'. As I recall, Gilad Bracha at one point looked at attaching units to numbers but I think he got wrapped around the axle on automatic conversions - if you divide meters by seconds, this is a meters/second unit. But do you convert to newtons or joules automatically too?
- ttymck 5y ago60 minutes or 60 seconds?