Live data from Hacker News

TerrariaClone – An incomprehensible hellscape of spaghetti code

github.com

11–20 of 289 posts

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#11

The real Terraria code isn't much better. Here's their 3MB [decompiled] NPC.cs: https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1... They had serious problems implementing multiplayer because they had to synchronize objects with 50KB of state every frame.

This looks as if this was a compile target, not the source code.

HitEffect is a quite the function.

This reminds me of working on CDDA[1] before many of the refactors hit.

CDDA is an interesting case, it stemmed from a situation similar to the original post (one person project, embarked upon it before knowing how to do so). It was a complete mess of macros, spaghetti code and data and code living happily side by side.

https://github.com/CleverRaven/Cataclysm-DDA

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#12
post #7

That actually doesn't look too bad to me. Sure, it's verbose, repetitive, and deeply nested, but just from skimming it, it looks quite comprehensible. Load all the data from files instead of filling huge arrays and maps in code, abstract similar code into methods, tame the usual mess when dealing with grids with some helper functions taking care of clamping or wrapping around coordinates, replace all the parallel arr…

Truthfully - I wouldn't call it spaghetti code. I think of spaghetti code as way to many abstractions (AbstractEntityFactoryFactory). This code has the opposite problem - needing more abstractions - which is the easier direction to move.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#13
post #12
post #7

That actually doesn't look too bad to me. Sure, it's verbose, repetitive, and deeply nested, but just from skimming it, it looks quite comprehensible. Load all the data from files instead of filling huge arrays and maps in code, abstract similar code into methods, tame the usual mess when dealing with grids with some helper functions taking care of clamping or wrapping around coordinates, replace all the parallel arr…

Truthfully - I wouldn't call it spaghetti code. I think of spaghetti code as way to many abstractions (AbstractEntityFactoryFactory). This code has the opposite problem - needing more abstractions - which is the easier direction to move.

Yeah, I call the abstract code problems astronaut code, or more generally J2EE best practice code.

To me this perfectly fits spaghetti code.

https://www.joelonsoftware.com/2001/04/21/dont-let-architect...

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#14

The real Terraria code isn't much better. Here's their 3MB [decompiled] NPC.cs: https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1... They had serious problems implementing multiplayer because they had to synchronize objects with 50KB of state every frame.

From the first couple hundred lines, they obviously know how to use a switch statement (as in how it works at least), but the odd cascade of if statements at the bottom makes me question whether they know when to use a switch statement (but then again, the stuff a the top makes me wonder that a bit as well).

Edit: As someone else noted, if this is a generated file, that might explain a lot of this.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#15
post #12
post #7

That actually doesn't look too bad to me. Sure, it's verbose, repetitive, and deeply nested, but just from skimming it, it looks quite comprehensible. Load all the data from files instead of filling huge arrays and maps in code, abstract similar code into methods, tame the usual mess when dealing with grids with some helper functions taking care of clamping or wrapping around coordinates, replace all the parallel arr…

Truthfully - I wouldn't call it spaghetti code. I think of spaghetti code as way to many abstractions (AbstractEntityFactoryFactory). This code has the opposite problem - needing more abstractions - which is the easier direction to move.

Spaghetti code is when procedural/functional coding goes wrong which is pretty much opposite of too much abstaction. Basically, spaghetti is what was before OOP when it went bad. At least, I did not heard people to refer to too much abstraction as spaghetti before.

For the record, this one is not that bad. It is comprehensible and pretty easy to refactor. Real spaghetti is something you have no idea what it does.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#17

The real Terraria code isn't much better. Here's their 3MB [decompiled] NPC.cs: https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1... They had serious problems implementing multiplayer because they had to synchronize objects with 50KB of state every frame.

Per the description on https://github.com/csnxs/Terraria/ , this isn't the Terraria source code -- it's a decompilation of the binary.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#18
post #4

The real Terraria code isn't much better. Here's their 3MB [decompiled] NPC.cs: https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1... They had serious problems implementing multiplayer because they had to synchronize objects with 50KB of state every frame.

I just scrolled to the bottom and all I see is } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } What the fuck

This is decompiled code, not the original source, so much/most/all of the craziness probably comes from that.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#19

The real Terraria code isn't much better. Here's their 3MB [decompiled] NPC.cs: https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1... They had serious problems implementing multiplayer because they had to synchronize objects with 50KB of state every frame.

Important to note is that this code is not the source code, but rather was generated by dotPeek, a C# decompiler, as mentioned in the repo's README: https://github.com/csnxs/Terraria/
Post reply on HN