Bad Code

Early last week we delivered a build of our application to the “customers” that has all of the planned features. Not a big bang release of course, since we practice TDD and XP so we release often. Sometimes too often for our liking but that’s another story!

So we all were in bug fixing mode but the bug list is moderated by our domain expert so there are times when all the bugs are being worked on and no new bugs are in the tracker.

The standard practice when that happens is to look for code to refactor. The amount of code we have and the uneven level of skills in the team meant there are plenty of opportunity for refactoring. After I did some light refactoring on some UI code, I came across this piece of gem:

if (someText.Length > 0)


if (someText.Length == 0)


Needless to say phrases such as, “WTF?”, “You are fired!” (in Donald Trump style), and many others came to my mind. I knew who wrote this piece of code and it amazes me that someone who has years of programming experience produces this kind of sloppy code. Even college students won’t make mistake like this.

Perhaps it is a one-off, you say? Try another piece of code that I’ve seen from the same developer at another time:

string fooString = new myForm().MyTextBox.Text;

string fooString2 = new myForm().MyTextBox2.Text;

I could immediately see three problems here. First, using a TextBox’s text property to store a default string for later use? Should have used constants. Second, exposing a TextBox as public property? Third and most important, instantiating a form just to get access to some data inside the form that has nothing to do with the form? How expensive is that!

So this developer violated some of the most fundamental rules/concepts of programming (Encapsulation in Object Oriented Programming, anyone?) for what, I don’t know and I don’t want to know.

Anyway, I showed the first piece of code to another team member who I know is discreet but even he shouted “What?” rather loudly after reading the code. I didn’t dare to show it (let alone the second one) to the team lead or the boss because I knew Donald Trump will definitely make an appearance!

Technorati Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Website Built with

Up ↑

%d bloggers like this: