At Fischer's company, they work with a lot of consultants. Many of these consultants, not worth their salt, are sent down the river when their contracts end. Once in a blue moon, however, a shining example of what it means to be a developer comes down the pipe. These mighty few are given offers to become real employees.
As he puts it,
Normally, you'd think this could be a positive thing whereby we could listen to all the consultant's battle stories and learn from other people's mistakes without making them ourselves. Well apparently we're going to be learning from our own mistake for many years. Here's some fresh code from by our newly hired, full-time staff member.
public static boolean isEmptyString( Object obj ) { if ( obj != null ) { if ( obj instanceof String ) { if ( ((String)obj).trim().length() == 0 ) return false; } } else return false; return true; }
The unfortunate part is that this code was checked in on production. Luckily, another developer caught it. The new hire --- after having some things explained to him --- was sent off to fix it.
Here's the "corrected" version.
public static boolean isEmptyString( Object obj ) { if ( obj == null ) return false; if ( obj instanceof String ) { /* a bunch of spaces is not an empty string */ if ( ((String)obj).length() == 0 ) return false; } return true; }
[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!