Hacker News new | ask | show | jobs
by johnswamps 5508 days ago
Clearly any semi-decent programmer can mentally translate 5 * 60 * 1000 into 5 minutes. So what? This is nonetheless a more intuitive and less error prone way to write times. This is about making readers of your code spend less cognitive effort figuring out what your code does, decreasing the chances of bugs (oops, I missed a 0 or screwed up a conversion factor), and making your code easier to modify. You seem to think this is a plugin for programmers too dumb to use milliseconds; it's not. Stop making excuses for bad code.

That said, sure, this isn't exactly a huge issue that's plaguing the javascript community. I probably won't use this plugin.

2 comments

I'm not disagreeing with your general point, but this does seem a little overkill when you could achieve a similar effect with a few constants:

  5 * MINUTE
  3.5 * HOUR
etc.
Where are you getting these constants in JavaScript? You can't even trust the built-in "undefined" to actually contain "undefined".

(My point is: a library may be more appropriate in the JavaScript case, because of the lack of constants.)

is mytimelibrary.MINUTE what you're getting at?
For the small benefit of making timeout calls slightly prettier, I incur the small-but-probably-net-greater risk that there is some bug, subtle or otherwise, in this code, along with a motley assortment of other issues I usually gloss over but start being significant when we're talking about such small benefits, like adding a dependency and having to worry about the licensing situation. (Even just having to worry about something that turns out to be "public domain" is something to judge.) Net net I'd personally judge it a loss; YMMV, no sarcasm. I would generally analyze any NIH solution that solves such a small problem in the same way. It is, perhaps, one place where NIH is appropriate.