Fog Creek Software
g
Discussion Board




A definition of spaghetti code...

...if you please.  Because I see a lot of people using the term, but I suspect they mean something different from what I think of when I see the term.  What is spaghetti code, and what programming habits lead to it?

Kyralessa
Saturday, May 8, 2004

Google suggests http://info.astrian.net/jargon/terms/s/spaghetti_code.html from the Jargon dictionary.

I don't see GOTOs, so instead for me the term implies especially:

* Deep layering (A calls B calls C calls D calls E calls ...)
*Cyclic dependencies (A calls B calls C calls A)

"Spaghetti" also implies that I'm unable to understand a layer without understanding what's above and below it: for example, imagine 3 layers A, B, and C, each containing a dozen methods like A1, A2, A3, ... B1, B2, ..., C11, C12; if I can understand B1 through B12, then it's a layer and not spaghetti; but if I can only understand B5 by looking at A5 and C5, then it's a strand of spaghetti.

Christopher Wells
Saturday, May 8, 2004

http://c2.com/cgi/wiki?SpaghettiCode

My operational definition is how much nonlocal code one has to change when modifying a part. (Substitutability of code? Quine's version of "referential transparency"?)

I disagree with the link's reference to Ball of Mud, because I sometimes like the mudball approach, but it has a couple funny jokes.

I guess it's really about code that isn't good "Structured Programming" code, like with gotos. But Dijkstra was apparently shocked at the influence of his "Goto Considered Harmful" paper; it was originally called "A Case Against Goto" but the magazine editor (Niklaus Wirth) changed it. So I don't think it has a real meaning, and is just one of those things you say when you think some code is funky. I like the Smalltalk/Patterns term "smell" better.

Tayssir John Gabbour
Saturday, May 8, 2004

Spaghetti is to good code like surreal is to real.

You open the fridge and the dog explodes.

Eric Debois
Saturday, May 8, 2004

Think about how spaghetti gets all tangled up with itself and when you try to pull out a small piece of it two dozen long strands tag along with it.  With spaghetti code, you touch one little piece and the whole system comes dragging along (or crashing down) with it.  The code is so entangled that it becomes practically impossible to test or modify any small piece of it in isolation.

NoName
Saturday, May 8, 2004

I left a long term client in February that had become addicted to grandiose "design visions" that in reality have become deeply layered spaghetti. The owner (a CPA) is also the software designer. He is deeply addicted to 'systems everywhere' to the extent that he is paralyzed by his own creation. He cannot ever get to the point and just code anything. But true to denial, he keeps insisting that one day it will all work in perfect synchrony and it will be perfect!

Spaghetti and denial will without a doubt be the death of this company. I told a friend there that he had better be poised to apply as a greeter at Wal-Mart when the sh*t comes down.

Bored Bystander
Saturday, May 8, 2004

"You open the fridge and the dog explodes."

That's brilliant! It just brings back all those memories of inherited projects where you discover that the fridge really is wired to the dog.

An Aussie
Sunday, May 9, 2004

If it sticks to the wall when you throw it at it, you know its done.

cf: The stickiness of loops and logic inversion

Simon Lucy
Sunday, May 9, 2004

>> "You open the fridge and the dog explodes."

Another me-too. Hilarious.

Bored Bystander
Sunday, May 9, 2004

The worst spaghetti I am seeing now is this new fad of breaking down stuff to the point where every single statement gets its own function and the name of the function takes the place of the comment. Comments are then considered unprofessional.

I guess this is supposed to assist hackers in reconstructing the source of the program since the comments are now in the executable.

The result of course is the entire program is totally unreadible without going back and forth from function to function, up down in out. When in the past you might have a function with 10 lines of code, now the fad is to have thirteen functions of one line each over three levels of indirection, none of which are reused outside the encapsulating grandparent function.

Programming using iterator functions is similarly stupid. In the old days you had your loop and your simple three lines of action inside the loop.

Now, the same code takes forty lines, including deriving defiining and instantiating templated iterator classes and similar nonsense.

Absolute stupidity all around.

And the people who write this crap call themselves OO and refactoring gurus and spout their nonsense in expensive books.

Crap is crap. Let's call it for what it is.

spaghetti classes are stupid
Sunday, May 9, 2004

*  Recent Topics

*  Fog Creek Home