Code Renaissance is about building great teams and great software. By exploring best practices, team interactions, design, testing and related skills Code Renaissance strives to help you create the team and codebase that you've always wanted.

The New Spagetti Code: Indirection

Traditionally when the term Spaghetti-Code was thrown around you would hear talk of goto statements. If this, goto line number (or label)... and when you got there it would send you some place else, which would send you some place else to infinity. It was kind of like procedural programming without any encapsulation or meaningful names, where the code could and did step all over itself, and you had no idea why. If you don't know what I'm talking about, count your blessings.

One of my favorite aphorisms is credited to David Wheeler who says: "Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem." The new form of Spaghetti Code is what I guess I'll call Spaghetti-Code by Indirection or perhaps YALI(Yet Another Layer of Indirection). Essentially it goes like this... You're doing maintenance on some code and you've tracked the problem to a particular method, so you step into the method in the debugger and that method instantiates another class. You go to that class and it gets an object from a factory class. You go to class that's being passed by the factory and it sends you to it's base class, which calls a class in the framework, which sends you to another class, which sends you to another, which sends you to another, which sends you to another, ad nausium.

Twenty layers or more in you find out that the business logic that's causing the problem isn't in the code at all... it's actually in a stored procedure. Congratulations you have just experienced the New Spaghetti code. It comes from overly complicated, poorly engineered solutions. That's why I think design reviews and code reviews are so important; there's no way that a programmers peers would let them get away with something like this, because for all they know, they might just be the next person to work on it.

0 - What do you think?: