Live data from Hacker News

TerrariaClone – An incomprehensible hellscape of spaghetti code

github.com

41–50 of 289 posts

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#42
post #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 r…

Not having looked at the code, my guess would be what the 1k+ loc of method is doing. If it's mainly a bunch or if elsea or a switch statement that jumps to another function, which is what most gross long Enterprise code is, I imagine it's fine. But if you have 1k loc that is procedurally creating objects and doing a lot that depends on previous operations then I could see starting to run out of memory. We also don't know how much memory they had, most Java code for Enterprise is running on pretty big servers or workstations.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#43
post #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 wo…

I had a rather unique AP Computer Science high school experience a number of years ago.

The AP class was mainly a self or group study class inside of a lower level programming class.

We didn't get as much directed study, but we basically were allowed to chose projects that interested us and spent a lot of time developing them and getting help, iterating, figuring it out.

We ended up doing only OK on the AP exam, but we had built a pretty impressive little java app by the end. A scrolling tile based map, enough network code to run a chat and let users join, and we had started building some game logic on top of our multiplayer game room. Very cool and informative, but not exactly what the AP exam was looking for.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#44
post #9

I love DoubleContainer: https://github.com/raxod502/TerrariaClone/blob/master/src/Do... which is fortunately only used in a comment here: https://github.com/raxod502/TerrariaClone/blob/9ea04b15add48...

I really like this method: https://github.com/raxod502/TerrariaClone/blob/fd1ff8b8b0e78...

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#45
post #23
post #18

Earlier quoted context omitted.

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

Decompiling .NET or Java binaries usually yields code very close if not identical to the original source code, at least unless an obfuscator was used but that seems not to be the case here. Chances are very good the original source code looks almost exactly like that code, maybe with some additional comments.

Mind you, a lot of Java 5 and later features like generics, switch on Strings, Iterable-based for, etc., are syntactic sugar implemented in the compiler, not part of Java bytecode, so those features don't decompile well.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#46
post #26

I did the same trying to write a Minecraft clone back in 2012: https://github.com/beager/craftalike I'm very much not proud of the code, it's sloppy, incomplete, quite copy-pasta. But it helped me learn a lot of concepts about game dev that a web dev wouldn't know, and it was tremendously exciting to create something in code that you could compile and play around with. No regrets.

I did one too.

We basically gave up after the networking stuff grew over our heads.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#47
post #23
post #18

Earlier quoted context omitted.

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

Decompiling .NET or Java binaries usually yields code very close if not identical to the original source code, at least unless an obfuscator was used but that seems not to be the case here. Chances are very good the original source code looks almost exactly like that code, maybe with some additional comments.

In this case, it's just that the decompiler didn't think of "else if" as a single control flow construct/keyword in the way that the original programmers did.

What was no doubt written like this:

  if(a 
Decompiled into this:

  if(a 

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#48
This makes me sad. Not because of the code quality, but because it makes me think of all the games I used to write back in middle school that are now lost to the swirling sands of time. The youngins don't know how good they have it with github!

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#49

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

yes, also that it comes back to the left after it hit the right end lol
Post reply on HN