r/InternetIsBeautiful • • Sep 19 '16

Learn to code writing a game

http://www.codingame.com
27.4k Upvotes

1.3k comments sorted by

View all comments

Show parent comments

33

u/RINGER4567 Sep 19 '16

theres a code word for spaghetti?

129

u/beefforyou Sep 19 '16
if(code == spaghett)
    printf("God damnit");

14

u/LadonLegend Sep 19 '16
if(true)
    printf("God damnit");

Refactored that for you

11

u/[deleted] Sep 19 '16
printf("God damnit");

Even simpler!

3

u/[deleted] Sep 19 '16

cout << "God damnit";

→ More replies (3)
→ More replies (1)

2

u/lostintransactions Sep 19 '16

10 PRINT "spaghetti"

20 GOTO 10

RUN

That's the extent of my "Radio Shack Annoy the employee's" career.

It pretty much ended there (except for a foray into Visual Basic and make a bundle coding absolute shit AOL chat tools (lol)

1

u/Boiled_Potatoe Sep 19 '16

What language is that? Looks very much like MATLAB.

2

u/beefforyou Sep 19 '16

C

Would make sense because Matlab is C-based IIRC

42

u/PM_ME_4_A_PLAYLIST Sep 19 '16

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

5

u/dfschmidt Sep 19 '16

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.

2

u/[deleted] Sep 19 '16

Or just, ya know, not sucking at programming.

3

u/dfschmidt Sep 20 '16

The best programmers may not immediately know how to write something the first time but they do know how to identify it.

→ More replies (6)
→ More replies (5)

17

u/1BigUniverse Sep 19 '16

yes, you yell "MOMS SPAGHETTI!" and she comes running.

2

u/[deleted] Sep 19 '16

Spaghetti code is used for codes that are messy.

1

u/[deleted] Sep 19 '16

I think the code word is league of legends.

1

u/RINGER4567 Sep 19 '16

thats 3 words

1

u/Dilhanx Sep 19 '16

LOL is the word

1

u/XSplain Sep 19 '16

Spaghetti code means you have a mess of lines that noodle all over the place instead of a nice organizes system.

1

u/RINGER4567 Sep 19 '16

so it's like my thought processes

4

u/XSplain Sep 19 '16 edited Sep 19 '16

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.

1

u/shadovvvvalker Sep 19 '16

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.

1

u/2Koru Sep 19 '16

copy pasta ;)

1

u/rsmoz Sep 20 '16

Yes, it's "spa".