Ayende @ Rahien

Refunds available at head office

My Code Sucks

There is a point where a project goes beyond the pale, where the complexity goes so far out of line that it is simply ludicrous.

I had such a point today. I had enough with SSIS and decided that I want to replace it with something better. I wrote an ETL tool to handle that in a few hours.

Why is this relevant? Because I have already build an ETL tool. Rhino ETL.

It is quite telling when the author of a tool decide that he doesn't want to use it.

I was decidedly proud of Rhino ETL for a while, then the problems started to creep in. The problems were not in the code per se, the entire architecture of the code was overly complex. In order to handle this complexity, I had resorted to throwing code at the problem, and then more code, and more code yet again.

At the moment, the current code base has two "minor" problems, exception handling and threading. The bigger problem is that I don't want to have to wade into this stinking pile and try to figure out what is going on there. I tried to be clever, and it is clever, in a horrible sort of way.

I don't have the time or patience to decipher code at the best of time, and at this point, it has gotten simply too complex. The project right now is at ~9,000 lines of code, so it is not that it is big, it is simply complex.

From the architecture perspective, I have made one huge mistake, I exposed the threading model to the application code. You can say that this stand in the root of my problems. I actually re-wrote this once already, moving from a home grown threading solution to using Retlang for threading. I made the same mistake and exposed the threading model to the application itself. Can you say: Big mistake!

From the point of view of the project itself, I started by defining the DSL syntax, and then built the project around that. It turns out that this has the usual "let us build the whole layer at a time". It also meant that a lot of the code had deep assumptions about the way it is called, making it unusable for using in other ways. This is excusable if we are talking about the DSL mapping layer, but not for the core code base itself.

Anyway, I am ranting and I should stop.

I spend six to eight hours today rewriting it from scratch.  It doesn't do threading, and it doesn't have a DSL interface yet, but it does pretty much everything that the old project did, in a quarter of the lines of code, and in a way that is much safer and easier to handle than what we are using currently.

Comments

Mats Helander
01/04/2008 02:04 AM by
Mats Helander

"My Code Sucks"

I beg to differ. But:

"Anyway, I am ranting and I should stop."

No, please go on! This was a really good post imho...the "It turns out that this has the usual "let us build the whole layer at a time" " remark was priceless, as was "I tried to be clever, and it is clever, in a horrible sort of way.".

Very few posts are as informative and interesting as when a good coder rips some code to shreds, critisizing exactly what's wrong with it - but doing it to someone else's code isn't really polite so the only reasonable option is to attack your own code. But that takes Big Kahunas to do publicly like this. Kudos.

/Mats

Steve
01/04/2008 02:19 AM by
Steve

I agree with Mats.

Maybe it's the short week for me at work this week, but today I opened some code I was doing before Christmas. I know I was liking it before Christmas, but I saw it today and thought: wow, you really complicated this thing Steve.

I went back, refactored it, removed some of the extraneous complexities and made it more simple.

KISS is a principle I like, and when I try to get too 'fancy' I end up scratching my head later saying 'gee, did it need to be that hard' :)

Just glad to see you share this info though, its insightful

Jeremy Ross
01/04/2008 04:30 AM by
Jeremy Ross

This is great because this is the same kind of stuff that almost every project faces. Sometimes you have to stop and "clean up the kitchen". Boundaries start to get blurred, the orthagonality of layers and abstractions become compromised.

You're doing the right thing. Martin Fowler says that you can NEVER do it right the first time. Always makes me feel good to hear someone like Mr. Fowler say these kinds of things.

Jeremy

Joe Ocampo
01/04/2008 05:23 AM by
Joe Ocampo

I don't know what is more impressive...your humility or the fact that you rewrote the dam thing in less then a day!

Jeremy Gray
01/04/2008 06:50 AM by
Jeremy Gray

Keep it comin'! Everyone's code progressively sucks, a little more with each character they type. :) And it keeps on sucking until you go back and clean it up (which in turn gains its own, but hopefully smaller, suckitude.) There's nothing wrong with this: it's just how we all learn and learn all the time, we do.

Darius Damalakas
01/04/2008 09:09 AM by
Darius Damalakas

You know what I like most in my team?

When people do criticize their own code. Not wheeping, not crying "ah, i am stupid" (yes, maybe you are), but giving strong concrete and personal opinion of why the code is bad.

This is what i do constantly in my team - i publicly criticize my own code and then tell how i would do it better. And i encourage others to do so too.

Jon Skeet
01/04/2008 11:14 AM by
Jon Skeet

Darius: Agreed. There's another attitude I really like - encouraging others to review hard.

In a previous job, I had a colleague who would always come to me for a code review, even though she knew I'd be more likely to really look at the code and suggest changes than other reviewers might. (Many people did really cursory reviews.) She knew that it would almost always mean more work for her, but that she'd improve because of it. I can't think of many better indicators of someone's commitment to quality and self-improvement.

GLM
01/04/2008 12:00 PM by
GLM

The second time you write something it mysteriously goes better :)

Oran
01/04/2008 06:13 PM by
Oran

I agree about the dangers of starting with the DSL. I think the same danger applies if starting with the config interface. It's better to start with the "raw" imperative object model and then layer the config or DSL on top of it, sort of like writing the business logic with no UI dependencies and being able to layer a "wizard" UI on top of it (fluent interface), a "power user" UI, and so on.

Mr_Simple
01/04/2008 06:17 PM by
Mr_Simple

Your mind is brilliant - don't be too hard on yourself.

Keep things Mozart simple. People are more impressed with simple anyway. Besides, simple is easier to debug so you can get on to other pressing issues.

I stop by daily to read you - even if I don't always understand the triple back-flip stuff.

JCichocki
01/05/2008 04:48 PM by
JCichocki

I'm going through the same sort of thing as well. Like others said version one never really works. In my project we never really had any specs to code from (basically a productionized prototype), but in reality that is just a lame excuse on my part.

I think in the end a programmer a while back worded it best, programming has a lot of peaks and valleys. I see that in my own code quite often, one day things are great and the next I am asking myself what was I thinking.

Comments have been closed on this topic.