Archive for the 'Horror Code' Category

Welcome to anti-refactoring lesson number 4. Previously I posted about trivial programming errors, stuff for amateur programmers as in last case. Here we go for a more conceptual mistake. Answer this question: from 1 to 10, how do you think it's smart to bind the name of a configuration property to the internals of your […]

The Repetita Juvant Principle

Welcome to anti-refactoring lesson number 3. The "Repetita Juvant Principle" is the counterpart of the DRY principle: 1 @Override 2 public SomeObject getSomeObject() { 3 return super.getSomeObject(); 4 } 5 6 @Override 7 public void setSomeObject(SomeObject arg0) { 8 super.setSomeObject( arg0 ); 9 } Then, you may think... this code has been written for some […]

Always on getter and setters

Welcome to anti-refactoring lesson 2. There are painters that paint with pencils or brushes and painter that paints with a bucket. A bucket is very effective if you just want a canvas filled. An example: 1 private String prefix; 2 public String getPrefix(){ 3 return getClass().getPackage().getName(); 4 } 5 public void setPrefix(String prefix) { 6 […]

It is quite fun when you see an extremely verbose code that can be replaced by two or three lines, just removing useless stuff, or using the correct API. But it is much less fun, when an expert makes a huge refactoring on your codebase covering it of useless crap. It happened to me today […]

Apparently, with JDK 7 we will have Strings in switch statements. I got a SCPJ certification long time back, but if someone asks me to write a switch statement in a job interview today, I could probably fail: I begun writing Java code in 2000, and I bet I used switch statement six or seven […]

I don’t know what XPers whould say about this, but I found it useful. Maybe someone could say: if you are not able to test something of your API, maybe you’ve badly designed your components… or: you should’n test this, because this is internal specifics of your object and you don’t have to know or […]

It was a late evening when I fall in buggy a code like this: Destination newDestination = null; if (! originalDestination.getId().equals(getDestinationId())); { newDestination = context.loadDestination(getDestinationId()); prefix.setDestination(newDestination); }; if (newDestination != null) { newDestination.addPrefix(prefix); originalDestination.removePrefix(prefix);;; } When the first if block is true, the second one will also be true, because the line […]

That building Strings using StringBuffer (and in Java 5 StringBuilder) is much faster and less memory expensive than using String concatenation, is not a secret. But porting this concept to extremes, you can fall in coding conventions that mandate to never use String concatenation. And you can face hibernate queries like this: 1String alias = […]


You are currently browsing the NewInstance weblog archives for the 'Horror Code' category.

Longer entries are truncated. Click the headline of an entry to read it in its entirety.


October 2017
« Nov    

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:



Tag Cloud