3 ms·
Why would I add 1.8K of possibly buggy minified code, compiled from 247 lines of possibly buggy un-minified code, to my web app, just in order to avoid having t
by kragen 16y ago
Why would I add 1.8K of possibly buggy minified code, compiled from 247 lines of possibly buggy un-minified code, to my web app, just in order to avoid having to write
function after(seconds, fn) { return setTimeout(fn, seconds * 1000); }
function every(seconds, fn) { return setInterval(fn, seconds * 1000); }
var MINUTE = 60, HOUR = 3600;
in my program?
I do like the naming and argument order better than the standard functions, but the cost-to-benefit ratio of this library seems off by two orders of magnitude, given the ability to get the same benefit in two or three lines of code instead of 200 or 300.
- avk 16y agoAuthor here. Point taken. Please use whatever works best for you. I mostly wanted to encourage people to write more readable JS timers. Ideally, after() and every() would make it into ECMAScript in some optimized form so you wouldn't need my code :) By the way, the argument order and flexibility is what contributes to most of those lines.
- kqueue 16y agomilliseconds is pretty readable. What's not readable is "9.7" and 100 because I am not sure if that's in seconds, milliseconds unless I know the default.
- kragen 16y agoYou might have a point if we were talking about mass (is that 9.7 grams or 9.7 kilograms?) or length (9.7 feet or 9.7 meters?), but if you're talking about voltage or current or power or time, and using floating-point numbers, there's really only one reasonable default unit you could be using in each case. And the millisecond it is not.
- nitrogen 16y agoAnd the millisecond it is not. ...unless you're talking about computer programming instead of physics, in which case one uses counts of milliseconds, microseconds, or nanoseconds. Also remember that integers are valid floating point numbers, so after(100) is ambiguous in the context of computer programming (as pointed out by the prior poster).
- kragen 16y agoIf you have floating-point numbers, there's no reason to use milliseconds, microseconds, or nanoseconds instead of seconds, except to deliberately obfuscate your code, or if you need more than 53 bits of precision.
- nitrogen 16y agoSure, if you're running JavaScript on a CPU with a beefy FPU there's no reason now, but you're still going against decades of ingrained behavior and potentially affecting performance on embedded systems.