So, What is spaghetti code?

Gearpower··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

iainB8532 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.

FantasySniper3 votes

It sounds like 100% of game developers use the Spaghetti code method.

iainB8522 votes

It can become tricky on large scale games, as the amount of people touching the code is massive. Not only that, you have people coming and going throughout the years, so the original people who wrote the code probably aren't even around anymore.

I think League in particular struggles with so many frustrating bugs because Riot started off as a smaller game company with a very tight budget, as opposed to a game like Heroes of the Storm where Blizzard has virtually unlimited funding and can release things on their own schedule.

That being said, Riot has had more than adequate funds for years now -- and I am personally disappointed with the development progress of the game. Sometimes it feels like the game is going backwards instead of forwards in terms of stability and reliability.

Silents4291 votes

That being said, Riot has had more than adequate funds for years now -- and I am personally disappointed with the development progress of the game. Sometimes it feels like the game is going backwards instead of forwards in terms of stability and reliability.

With the reworking the entire projectile system, pathing, the networking, etc you can only do so much for the engine before having to rewrite the game. Hardly fair to say they have been going backwards.

TotalJerk1 votes

Worse than a small company, it was a team of rookie modders making their first actual game.

RedCyclone2 votes

everything is MINIONS

Tyaldan1 votes

very good example of spaghetti code

ZerglingOne1 votes

{quoted}

everything is MINIONS

There is actually a legitimate reason for this. In WC3's campaign editor, many custom spells were made with invisible units. Presumably since this is all the former makers of dota (in this case Guinsoo) knew for creating games, they probably just wanted a platform that worked similarly. So we get minions being used for everything.

TraakSC8 votes

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

Nameless Voice8 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 Tiger4 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?

JustMyBassCannon16 votes

[{quoted}](name=Lao Fu the Tiger,realm=NA,application-id=3ErqAdtq,discussion-id=BeJpWatg,comment-id=0003,timestamp=2015-08-03T18:20:19.099+0000)

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.

♪99 little bugs in the code, 99 little bugs, ♪You take one down, patch it around, ♪107 little bugs in the code

AMYS GRAVE2 votes

This is probably the most accurate representation of what happens with spaghetti code.

Annapii3 votes

Wait. Wait. I have visual aid.

Title: When I change one line of code.

http://imgur.com/gallery/hsN5Mgi

CatAndBookTails2 votes

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

Xonra1 votes

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

TotalJerk1 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.

Gearpower1 votes

It doesn't much matter to me, I didn't realize it really existed outside of League since I've only heard of it in conjunction with league. thanks anyway ^^

Gearpower1 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.

MoonKyung1 votes

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

SEKAI1 votes

{quoted}

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

This thread is FOUR YEARS OLD........

http://i.imgur.com/DZwjU3o.jpg?noredirect

More from Gameplay

More by Gearpower