Subscribe to my rss feed.
Current Pictures | Knitting Projects
2007-09-19 . 9:48 a.m. - Eat, sleep, be lazy
«rusted & used . shiny & new»
If I taught a programming class, the first piece of advice I would impart to my students would be "Be as lazy as you can and don't reinvent the wheel."
...
One of our clients wanted me to add a special "feature" to their ordering system: make the quantity fields free-form text fields, but round the value up to the nearest 5. I was furious when I received this spec because a) this would be better served by a dynamically-populated drop-down b) it is going to annoy the FUCK out of the users. However, this is what the client wants, so this is what I have to build. The math is simple enough:
value = value + (5 - (value % 5)) assuming that value % 5 is not zero.
But I needed to cover my ass in the case that the user is a mongoloid and attempts to enter "a bunch" in the free-form text field. Funny thing about Javascript: it doesn't have an "isNumeric" method. Which brings me to my sage advice about not reinventing the wheel. I did a quick google search for "javascript isnumeric" and found this. Omitting comments and extra line-breaks, the function is 16 lines long. I took one look at this and decided, there's no way it should be this complicated ... or asinine. I submit to you, my own isNumeric method:
function isNumeric(s){
return Number(s).toString() != "NaN";
}
It's a good thing I don't get paid per line.
«rusted & used . shiny & new»
|
Pictures:
|
Current Music:
|
|
|
Knitting Projects:
|