Koz Speaks

Bad Smells in Code

Every now and then I’m surprised at the cruft I find whern digging about in old code. This particular piece of loveliness isn’t of my doing but it’s certainly … interesting.

public TheObjectInQuestion(int a, String b, String c, String d, String e, long f, String g, String h, String i, String j, String k, String l, String m, String n, String u, String v, String w) { }

That’s 17 arguments, most of which are just Strings holding various special meanings such as status flags. You can guess what the javadocs tell you about this constructor… Yep, nothing.

But not to worry, TheObjectInQuestion has another constructor:

public TheObjectInQuestion(int a, String b, String c, String d, String e, long f, String g, String h, String i, String j, String k, String l, String m, String n, String u, String v) { }

Now that looks like You’ve just removed w from the parameters right? Wrong! The argument i from the original constructor was removed. So the compiler won’t pick up on your error, and eventually the app will do something stupid, in this case it’ll confuse the middleware to the extent that it ignores all requests from the app server.

Does anyone know any good books (short, easy to read) that explain to people without OO experience, how to think in OO terms. What I’d like is to have them use lots of small objects to represent data, but they don’t seem able to do it.