Live data from Hacker News

Anyone who looks at this code instantly becomes insane

github.com

61–70 of 81 posts

Re: Anyone who looks at this code instantly becomes insane

#61
post #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 ev…

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

Man I remember being this naive once :(

Re: Anyone who looks at this code instantly becomes insane

#63
post #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 ev…

One of the best refactoring tools is naming. Arlo Banshee wrote and interesting article about the subject some time ago (http://arlobelshee.com/good-naming-is-a-process-not-a-single...). This is a really long post, but the overall theme is iterate over code until everything has a name. To apply this to your question, the first thing you would do is take those lines, put it in a function with a bad name like “doesSomething” then keep iterating until someone can actually read the code and it makes sense.

In the beginning of learning to program it’s easy to get stuck on the “clever” side of programming, but a lot of the time it can remove readability. The earlier you learn this, the more your future coworkers will appreciate you.

Good luck!

Re: Anyone who looks at this code instantly becomes insane

#65
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?

I don't have time to go insane today, so I have tried not to look at the code directly. But, "hundreds of distinct cases" would cause me to reach for a data-directed method using a lookup table or other decision-tree data structure.

Re: Anyone who looks at this code instantly becomes insane

#66
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

I think i had a polytomous account on the orange site, but forgot the creds. This is what i settled on in the interim. I dont put on a character, if my acting theory is anything its a derivation of neofuturism.

Re: Anyone who looks at this code instantly becomes insane

#67
post #24

I wouldn’t ever want to work with this code, but there’s a level of persistence here that I kind of respect. Sure, the code sucks, but I can’t help but feel like I couldn’t have written this even if I wanted to. There’s usually a point when I’m too deep in a nested conditional to remember all the variables, and that’s usually before 23 tabs in.

Yeah. This is the code of a very smart person who didn't take the time to make abstractions, either through laziness or naivete. I've seen much more deeply-wrong code that would be much harder to refactor into something maintainable than this would be.

Yes, this kind of "naive coding technique" occasionally pops up, and I think it's a good discussion topic, because its mere existence demonstrates that you can get extremely far in terms of delivering features with a minimal amount of abstraction: "sometimes all you need is a function."

Further, that the code probably would not really be hideously miserable for a more experienced coder to refactor(it's just very duplicated) shows that copy-paste is reasonable for deferring some kinds of architectural decisions. It's not what you would bias towards if you have a whole team pounding away at the same file and rapidly evolving it, but as a solo practitioner who wants to get the feature out and put it away for the day, this style is convenient for letting the code as a whole develop some maturity and functionality before it gets refactored with abstraction.

Re: Anyone who looks at this code instantly becomes insane

#69
post #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 ev…

As mindfulgeek mentions, doing some sort of extract method refactor to slop a name onto it can be a good first step. Then do some sleuthing thru other number name pairings, inserting names in place of the numbers, until you have a solid grasp of what the names should actually be. Feathers in Working Effectively With Legacy Code brings up a concept called seams... u can insert a seam to map to objects and then do object manipulations with polymorphism.

Iirc that particular bit of code is the power logic. You can file an issue on my fork if ys like me to write more on this when im not on a broken phone.

Re: Anyone who looks at this code instantly becomes insane

#70
post #67
post #24

Earlier quoted context omitted.

Yeah. This is the code of a very smart person who didn't take the time to make abstractions, either through laziness or naivete. I've seen much more deeply-wrong code that would be much harder to refactor into something maintainable than this would be.

Yes, this kind of "naive coding technique" occasionally pops up, and I think it's a good discussion topic, because its mere existence demonstrates that you can get extremely far in terms of delivering features with a minimal amount of abstraction: "sometimes all you need is a function." Further, that the code probably would not really be hideously miserable for a more experienced coder to refactor(it's just very dupl…

Give refactoring this code a go! Its sublimely fun!!!
Post reply on HN