4 ms·
https://github.com/raxod502/TerrariaClone/blob/master/src/TerrariaClone.java#L5261 https://github.com/raxod502/TerrariaClone/blob/master/src/Te... You may not
by rococode 7y ago
https://github.com/raxod502/TerrariaClone/blob/master/src/TerrariaClone.java#L5261 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.
- nine_k 7y agoNo, 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.
- have_faith 7y ago"You may not like it, but this is peak X" is an internet meme, usually sarcastic in nature.
- arvidkahl 7y agoIt 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.
- DiscoMANNNN 7y agoI love that the function is called "resolvePowerMatrix." What does this function do? Oh the power matrix? Oh it resolves that? Cool.
- bazooka_penguin 7y agoHonestly what would you do if you need to switch hundreds of distinct cases? Hundreds of classes implementing an interface?
- MRD85 7y agoThe 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.
- saltcured 7y agoI 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.
- Izmaki 7y agoMy phone gave up trying to load that page.
- MRD85 7y agoI'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?
- munmaek 7y ago> 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.
- jrgilman 7y ago> A second question: Why is there no comments? Is this common? Man I remember being this naive once :(
- Cthulhu_ 7y agoMy 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.
- mindfulgeek 7y agoOne 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-step/ 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!