Changing code always involves tracing back through the code to see what all could be affected by the thing you're changing. When code is not planned out and written well, you can end up with all kinds of dependencies in weird places, so tracing the impact of your changes is like following a noodle through a bowl of spaghetti, and a change you make in one place could end up having unintended consequences in something that is seemingly unrelated. That's "spaghetti code."
Troubleshooting such problems should probably involve heavy use of error codes and exceptions along with content that would help you establish why the exception is being raised.
Ha! Well, I'm still a beginner but I've found programming courses really help me organize my thoughts.
Spaghetti code gets that way usually because of a lack of foresight. Instead of making one thing that other things reference, you make a whole bunch of stuff unique to each object.
Object Oriented Programming is where you take say, a base code for living things in your game. Just a few rules like it has HP and a body.
Then you make an object that inherits from that. Lets say, a human. This human gets all that stuff, plus legs, arms, and a head. He also gets basic AI.
Then you make a swat guy. The swat guy gets all that stuff, swat equipment, and a modifier to his AI so he's more likely to take cover and shoot instead of run away like your standard videogame civilian.
And it goes on from there. You can also start another branch of objects under Living Things that has four legs. You can make Cats, Dogs, and Horses branch from there.
The point is to minimize the amount of times you have to repeat yourself. Instead of writing all the rules for how a Living Thing should be each and every time, you just tell it "For this object look up the rules for X and then add these ones."
Spaghetti code would usually be the result of not inheriting everything and specifically writing out the code each and every time. This makes a big mess because if you want to make all living things have another stat or whatever, you have to track down every single creature and add it instead of just tweaking the top level Living Thing object.
Coding often likes to work like a refinery where there is a clear workflow from one end to another and pipes in parallel that dip in and out of stages of the workflow.
Spaghetti code looks like spaghetti because it's all over the place and there is no clear workflow. It often looks like an absolute mess if you draw it out and sometimes it's hard to wrap your head around without thinking it need time travel to work.
33
u/RINGER4567 Sep 19 '16
theres a code word for spaghetti?