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»

blog comments powered by Disqus
Hope you didn't miss these:
2008-04-02 - The Stranger's Funeral
2008-03-10 - I have room for you in this Melee
2008-03-04 - FOWA Miami 2008
2008-03-03 - Barcamp Orlando
2007-12-12 - Whachoo mean I no sound hispanic?


Pictures: Current Music:


Knitting Projects:
Nautie #1[pattern]
Robot for Neutron[model]
Seed Stitch Scarf for Neutron[XXXXX]
Katamari Damacy Hat for Dan[pattern]
Katamari Damacy Hat for Pete[pattern]
Katamari Damacy Hat for Bob[pattern]
Katamari Damacy Hat for Drew[pattern]
Kate[pattern]
Cable, zipped jacket[model]
Fuzzyfeet[pattern]
Drop Stitch Scarf #2[XXXXX]
Drop Stitch Scarf #1[XXXXX]
Cell Phone Cozy[XXXXX]
Striped Pastel Scarf[XXXXX]
Punk Rock Backpack - Monkey[model]
Starfish Washcloth[XXXXX]
Flower Washcloth[model]
Flower Washcloth[model]
Horrid Halter[XXXXX]
Honeymoon[pattern]
Kyoto[pattern]
Spiral Hat (sans stripes & pom pom)[pattern]
Bar Color(s) = Project color(s)