Live data from Hacker News

TerrariaClone – An incomprehensible hellscape of spaghetti code

github.com

31–40 of 289 posts

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#31

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.

Those SetDefaults methods.. ouch.

On the plus side, it's fun to press the page down and see the code 'animate' from left to right

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#32
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.

I dunno, i would call spaghetti code code with waaaay too many entangled concerns, for which this and global state definitely qualifies.

Personally i associate it with lack of abstractions, or extremely leaky abstractions.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#35
post #25

I think true spaghetti code requires teamwork. I mean that seriously. You need at least 3 people all with different incomplete and incorrect mental models trying to modify the same codebase at the same time.

Instead of having everyone working at the same time, stretch out the team over longer time with some overlap. This ensures both the "broken telephone" effect and discourages any major improvements.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#36
> The TerrariaClone.init() method, which is over 1,300 lines long, actually grew so large that the Java compiler started running out of memory trying to compile it!

Seems surprising, 1.3kloc doesn't feel that big in the scale of things. I wouldn't be surprised if some of the methods at $work would be on the same scale, and it compiles just fine (relatively speaking..). And based on quick scroll-through, there isn't really anything especially egregious in there that would point towards why the compiler fails.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#37

I'd actually try to recruit raxod502 at the high-school senior level. It certainly shows passion and commitment. You just need to grok the higher level abstractions. And may in the end even find your "spaghetti" version is actually more performant at run time ;) The thing is you sort of need to write like this for the first draft of your first game. And Terraria is pretty ambitious. Considering most people struggle w…

Writing code in spare time, not to mention 11,000 lines of it, already sets any high schooler (or any beginning programmer) apart from the majority of peers. It's shocking how little students in "AP" computer science courses actually end up doing, and how few do anything outside of class.

Given the choice between interviewing a student who had produced nothing but verbiage and one who had produced TerrariaClone, I would go with the latter without even thinking about it.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#38
Beauty. I see beauty. I see God in one 6000-line class (TerrariaClone.java), overflowing with constant data / tables embedded in the code.

Awesome!

PS: "Abandon all hope..."

PS/2 * : I saw it and i suspected this was code generated by other tool; then somebody commented that this was based on dissasembled .NET bytecode. This explains it all!

* (c) IBM

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#39

I'd actually try to recruit raxod502 at the high-school senior level. It certainly shows passion and commitment. You just need to grok the higher level abstractions. And may in the end even find your "spaghetti" version is actually more performant at run time ;) The thing is you sort of need to write like this for the first draft of your first game. And Terraria is pretty ambitious. Considering most people struggle w…

I did pong in rust to learn some rust, and it got me thinking how, doing pong was really easy (as an experience programmer) but if you wanted to do pong "properly", say supporting 4 different platforms, 5 languages, proper settings menu and high score table, supporting all manner of screen resolutions, full screen and windowed, sound, all popular controllers (keyboard, mouse, mobile input, game pads, joysticks) etc etc etc

then even pong is pretty hard.

Post reply on HN