Live data from Hacker News

Anyone who looks at this code instantly becomes insane

github.com

41–50 of 81 posts

Re: Anyone who looks at this code instantly becomes insane

#42

It compares favorably to the official Terraria code (decompiled version here): https://github.com/TheVamp/Terraria-Source-Code/blob/master/... Terraria extensively used God objects with hundreds or thousands of properties, and used naive C# serialization for its netcode. This meant that sending the state of a single object would take over 1KB, leading to truly outrageous network requirements for a 2D platformer game,…

That's decompiled or automatically generated code, right?

Yes it's decompiled, so the chains of if statements would likely be switches instead, but basic things like an object having thousands of properties are exactly as the programmer wrote it.

Re: Anyone who looks at this code instantly becomes insane

#43
> 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! The solution? Copy half of the init() code into a new method, called codeTooLarge(), and call that from init()

I found this in the readme, hilarious (not in a mean way).

Re: Anyone who looks at this code instantly becomes insane

#44
post #14

Honestly the only insane thing is that it's all in one file. Could've also been broken up into more functions (it seems like this person didn't actually want to be using Java), but it's reasonably named and formatted and they did a decent job separating out static data at the top instead of littering it throughout the code. Oh, and that stream of comments by polytomous. That's... something.

That Polytomous is a magnificent troll. They acknowledge the code is awful in their fork's README. Also, their prose is much clearer and more comprehensible in the same README. They must have been putting on a character in that thread.

https://github.com/polytomous/TerrariaClone

Re: Anyone who looks at this code instantly becomes insane

#45

It compares favorably to the official Terraria code (decompiled version here): https://github.com/TheVamp/Terraria-Source-Code/blob/master/... Terraria extensively used God objects with hundreds or thousands of properties, and used naive C# serialization for its netcode. This meant that sending the state of a single object would take over 1KB, leading to truly outrageous network requirements for a 2D platformer game,…

That's decompiled or automatically generated code, right?

The local variable names look like the code was decompiled with ILSpy. All the magic numbers probably (hopefully?) were constants in the original code. The crazy indentation looks like the decompiler just doesn't use "else if". The goto's were just old ILSpy versions being bad at control flow reconstruction.

But neither the C# compiler nor the ILSpy decompiler moves code to different methods/classes (only the JIT does stuff like inlining), so yes it's really a single enormous class handling every possible item in the game via cascading if statements.

Re: Anyone who looks at this code instantly becomes insane

#46
post #5

https://github.com/raxod502/TerrariaClone/blob/master/src/Te... You may not like it, but this is peak programming. A level of perfection attainable only by undergoing the rite of writing a single if statement with 100+ conditions.

Honestly what would you do if you need to switch hundreds of distinct cases? Hundreds of classes implementing an interface?

Re: Anyone who looks at this code instantly becomes insane

#47
post #5

https://github.com/raxod502/TerrariaClone/blob/master/src/Te... You may not like it, but this is peak programming. A level of perfection attainable only by undergoing the rite of writing a single if statement with 100+ conditions.

My phone gave up trying to load that page.

Re: Anyone who looks at this code instantly becomes insane

#48
post #16
post #14

Honestly the only insane thing is that it's all in one file. Could've also been broken up into more functions (it seems like this person didn't actually want to be using Java), but it's reasonably named and formatted and they did a decent job separating out static data at the top instead of littering it throughout the code. Oh, and that stream of comments by polytomous. That's... something.

This kind of thing in particular is really interesting: public static void print(String text) { System.out.println(text); } This person cares enough about brevity to make little wrapper functions like this, but at the same time everything is very procedural and monolithic. This gives a vague, weird sense of refined taste, despite some obvious problems with the artifact as a whole. I'm going to go out on a limb and gu…

I can understand that slightly. Back in college when I was doing a lot of Java if the IDE hadn't had a shortcut to auto complete System.out.println() I probably would have either made it as a macro or defined a function like that in a library (or in a block I would paste in every single project if we're being completely honest).

Re: Anyone who looks at this code instantly becomes insane

#49
post #5

https://github.com/raxod502/TerrariaClone/blob/master/src/Te... You may not like it, but this is peak programming. A level of perfection attainable only by undergoing the rite of writing a single if statement with 100+ conditions.

I'm a second-year CS student that is still learning in this realm. Is there a general way that most developers would rewrite lines 5261-5284? My assumption is I would look to find some rules I can apply to simplify the code but I'm also aware a CS course is a bit of a bubble and what I've learnt so far might not be the way things are handled in industry.

For example, line 5284 has a 8 inequality operators checking every 4th element (140. 144, 148,...). A single "blocks[1][y][x] % 4 != 0" would remove them all. There also appears to be 3 main segments in that huge block of code (111-118, 119-126, 137-168) which would allow it to be simplified.

A second question: Why is there no comments? Is this common?

Re: Anyone who looks at this code instantly becomes insane

#50
post #14

Honestly the only insane thing is that it's all in one file. Could've also been broken up into more functions (it seems like this person didn't actually want to be using Java), but it's reasonably named and formatted and they did a decent job separating out static data at the top instead of littering it throughout the code. Oh, and that stream of comments by polytomous. That's... something.

That Polytomous is a magnificent troll. They acknowledge the code is awful in their fork's README. Also, their prose is much clearer and more comprehensible in the same README. They must have been putting on a character in that thread. https://github.com/polytomous/TerrariaClone

It’s actually pretty great because they’re a person who has worked on the code, acting insane in an issue “Anyone who looks at this code instantly becomes insane”.

If that’s not some very clever trolling, I’m not sure what is.

And what dedication! Pretty funny.

Post reply on HN