Archive for February 2007
One Site All Your JavaScript Files Have To Go Through
Don’t you hate JavaScript sometimes? You may miss a comma or a semicolon somewhere, and the error message that you get is something like “‘obj’ is not defined”, and you’re staring at the code and you know that that freakin obj is there, so how come it keeps insisting that it’s not there?
Enter JSLint. This is very useful JavaScript lint utility, written by Douglas Crockford–one of the most well-known personalities in the JavaScript world. This cool utility is very accurate–most of the time it can pinpoint exactly where the mistake is. Other than that, it also points out the best practices of JavaScript coding. Since I’ve found this utility, I never commit my JavaScript files before running them through it.
Check it out here: http://www.jslint.com/
How To Avoid Reinventing Your Wheel with StringUtils
Ray’s Law of String Util Reinvention: “The probability of somebody creating a ‘Util’ class that contains common String manipulation methods is directly proportional to the number of people working on a project. When we have more than 3 developers, this probability is 100%.”
We’ve all been there haven’t we? After checking whether a String is blank one too many times, we decide to put this into a method and call it some unimaginative name, the most common of which is isEmpty. The most delightful occasion is when there are about 10 people working in the same project, and we have more than one StringUtils scattered in different packages doing roughly the same thing. Or one is StringUtil and the other is CommonUtil, but both have slightly different String manipulation methods.
Really, one shouldn’t anymore. Whenever you need something not included in JDK’s java.lang.String, your default action should be to go this existing, tested StringUtils implementation and check it out to see if it fits your needs. I’ve found that most of the time it does, unless the String manipulation is very domain/application-specific.
(UPDATE: Here’s a good example why you should not reinvent the wheel over and over again.)