News for hackers. Stuff that matters.
Re:Anyone who looks at this code instantly becomes insane by rococode on Thursday August 01, 2019 @02:40PM (#20586911)
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.

Re:Anyone who looks at this code instantly becomes insane by DiscoMANNNN on Thursday August 01, 2019 @03:08PM (#20587207)
I love that the function is called "resolvePowerMatrix."

What does this function do? Oh the power matrix? Oh it resolves that? Cool.

Re:Anyone who looks at this code instantly becomes insane by MRD85 on Thursday August 01, 2019 @03:59PM (#20587704)
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 by munmaek on Thursday August 01, 2019 @04:21PM (#20587930)
> Why is there no comments? Is this common?

It's frighteningly common, and more likely if only 1 developer is working on something. CS students comment far too much, but I would expect a monstrous chain like this to have at least -some- documentation.

Re:Anyone who looks at this code instantly becomes insane by mindfulgeek on Thursday August 01, 2019 @05:26PM (#20588528)
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 by jrgilman on Thursday August 01, 2019 @05:18PM (#20588454)
> 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 by Cthulhu_ on Friday August 02, 2019 @03:17AM (#20591178)
My first major project (at an internship) had all the comments on every file (even getters / setters, and it even had getters/setters because someone told me to). Interestingly enough it was a project that had to read static analysis tools' output and combine it into a single report / webapp, so I was very aware of all the output that was reported and all the niggly little things that these tools (think PMD, CPD, FindBugs, etc) pointed out. Including how a getter wasn't commented.
Re:Anyone who looks at this code instantly becomes insane by realSlavojTrump on Thursday August 01, 2019 @06:57PM (#20589142)
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 by realSlavojTrump on Thursday August 01, 2019 @07:02PM (#20589175)
https://github.com/polytomous/TerrariaClone/issues/6 gives an example of how i work thru this sort of question, but its also spoiler laden so view at your own risk.
Re:Anyone who looks at this code instantly becomes insane by bazooka_penguin on Thursday August 01, 2019 @03:54PM (#20587647)
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 by saltcured on Thursday August 01, 2019 @05:56PM (#20588760)
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 by MRD85 on Thursday August 01, 2019 @04:05PM (#20587769)
The way I'm reading this code is that the cases aren't that distinct. Look at lines 4367 to 4390 and you see 23 distinct cases that could be handled by a range and Mod 3.
Re:Anyone who looks at this code instantly becomes insane by Izmaki on Thursday August 01, 2019 @03:55PM (#20587660)
My phone gave up trying to load that page.
Re:Anyone who looks at this code instantly becomes insane by nine_k on Thursday August 01, 2019 @02:45PM (#20586980)
No, this is peak coding.

A coder strives to write the longest and most impressive code.

A programmer strives to write the code that solvers the problem at hand at the simplest and most reliable way.

Re:Anyone who looks at this code instantly becomes insane by have_faith on Thursday August 01, 2019 @02:48PM (#20587014)
"You may not like it, but this is peak X" is an internet meme, usually sarcastic in nature.
Re:Anyone who looks at this code instantly becomes insane by arvidkahl on Thursday August 01, 2019 @02:53PM (#20587080)
It feels like this may have been "peak bikeshedding"...

Certainly, a great meme to use but also indicative of the divisive nature of some discussions, often without any sarcasm.