Posts Tagged “antipatterns”

If there’s one thing that really annoys me, it’s opening code with garbage like this in it:

Set foos = new HashSet<foo>();
String queryString = "from FooTable as foo where foo.barField in (:listOfBarFields)";
try
{
	foos.addAll((List<foo>) HibernateSessionFactory
			.getSession().createQuery(queryString)
			.setParameterList("listOfBarFields", getBars()).list());
}
catch (Throwable th)
{
}

First, all the method chaining kinda bugs me — but I can live with that.

What makes me want to barf is chaining all those Hibernate calls together in one statement, and surrounding it with a try/catch that eats Throwable. Throwable. This is not framework code, this is not a library — it’s application code, and application code has no business catching a raw Throwable. And to make it worse, it completely suppresses the Throwable and makes it look like it never happened - it doesn’t even log it.   Oh, and there’s no JUnit test covering the code.

Anyone who writes code like this should be cruelly and severely punished. Or fired.

What’s also sickening is that anyone can write this kind of stuff and call themselves a professional programmer (and lots of them do it all the time), but you need a state license and show some level of competency to give a pedicure, run an auction house, or be an interior designer.

Comments 3 Comments »

Those of you who know me or who have read my earlier posts know that I am a static code analysis fan, and some of my favorite tools are PMD, Checkstyle, FindBugs, and JDepend, for their excellent feedback on the state of the quality of your code. In fact, I regularly use all of them and usually in combination with other tools (such as JUnit, Emma, etc) to gather code metrics.

The reports from each of these tools naturally identify problems — why else would you run them? And once you see a problem, you naturally want to run right out and fix them. The report shows them all, rated by severity, with counts and everything, and you can see the types of errors. It’s just a simple refactoring, right?

Better think twice before activating that refactoring in your IDE.

Read the rest of this entry »

Comments No Comments »