So, What is spaghetti code?

Gearpower·8/3/2015, 3:00:30 PM·18 votes·19,330 views

Title is pretty self explanatory. since I hear it being used as an excuse or scapegoat for things., I want a good explanation for what it is and how it works. Just, I want to know all about spaghetti code.

23 Comments

iainB858/3/2015, 3:13:36 PM32 votes

It's the opposite of modular coding, where you code functions of your application in a modular fashion -- meaning that there is no lines of code that effect multiple features.

Spaghetti code, on the other hand, is where the code constantly references itself all over the place. This is bad, because then when you go to change one line of code to to modify feature 'x', features 'y' and 'z' have unintended changes because they referenced that same piece of code.

TraakSC8/3/2015, 3:02:24 PM8 votes

Sloppy coding basically where trying to change something will usually break a bunch of other things.

Nameless Voice8/3/2015, 3:48:42 PM8 votes

Code usually runs sequentially from one point to another, for example from an event through the various effects it should cause. The things that the code is doing are a bit like a straight line - like a single piece of spaghetti.

Now imagine that your piece of spaghetti is in a pot full of spaghetti. You want to figure out the path of instructions that the code follows, but to do that you need to follow the single strand of spaghetti through the whole pot, and trying to untangle it will probably result in you pulling other strands of spaghetti around or even breaking them.


To put that less poetically, spaghetti code is basically badly-designed code, where it's hard to follow the flows and interactions, and where changing something might well break other things. One concrete example might be a particular feature which is coded separately in each of the abilities with that effect, rather than them all calling one single shared piece of code to handle that feature - that means each of the places using that feature might do it slightly differently, have or not have different bugs, and generally might be inconsistent, and that if someone wants to change that feature, they need to change it in every single one of the places that use it, rather than just in once place.

Lao Fu the Tiger8/3/2015, 6:20:19 PM4 votes

The hardest part about spaghetti code isn't even debugging the problem; it's rewriting the segment of code.

Debugging is easy enough in many instances; find the problem, fix it in that one specific instance (sometimes by hard forcing values that should be automatically calculated), and boom, it's good to go.

Rewriting, on the other hand, means potentially destroying several currently working functions in order to make the code more modular.

That's the difference between fixing and patching. Patching code to make it run (even if temporarily) is easy. Fixing it, however, is a much, much more challenging affair.

The question becomes, would you be willing to have the entire game offline for several weeks to make it modular?

Annapii8/3/2015, 7:06:52 PM3 votes

Wait. Wait. I have visual aid.

Title: When I change one line of code.

http://imgur.com/gallery/hsN5Mgi

CatAndBookTails8/3/2015, 11:34:40 PM2 votes

It's about half of Riven's power budget.

Xonra8/3/2015, 11:48:11 PM1 votes

Man I went to respond and you guys already had this covered.

TotalJerk8/4/2015, 6:28:25 AM1 votes

It literally has a definition as the first result on Google. It would've taken you less time to look it up than it took you to start this thread.

https://www.google.com/#q=spaghetti%20code

Spaghetti code is a pejorative phrase for source code that has a complex and tangled control structure, especially one using many GOTO statements, exceptions, threads, or other "unstructured" branching constructs.

Gearpower8/5/2015, 12:15:21 PM1 votes

Y'all have been super helpful, I'm not a big coding guy (or even much of a computer guy) as is probably obvious.

MoonKyung2/17/2019, 3:27:22 PM1 votes

Akali summoner 4 item 3146 [sg-ahri-2]