I've been writing a lot of time related code recently, and in various files, I always end up re-defining things like
var SECOND = 1000;
var MINUTE = 60 * SECOND;
This gets frustrating quickly. So I'm considering two possibilities:
- Getting rid of the constants and instead letting things be inferred from code like
60 * 1000
- I dislike this option because it's not as human readable
- Attaching the constants to a global so they only have to be written in one place
- I think this is the best way to go, but I'm unsure about the potential consequences of this
- I could use a package and import from it
- This has the same problem that I'm already doing, which would be defining it everywhere over and over
How do you handle this issue or is it something we have to live with?
Side note 1: I am writing this in JavaScript, which is why globals are an option, but I feel like this might still be applicable to other languages
Side note 2: Specifically for JavaScript, why are these constants not already attached to the global objects browser
/globals
?