8 ms·
Anyone who looks at this code instantly becomes insane
- ynx0 7y agoThis is pretty entertaining.
- z3t4 7y agoDoesn't look that bad. Could probably be optimized to run faster. Making a Terraria clone is not easy. If you manage to make it run smoothly and its a decent game, no player will complain about the source code.
- trixie_ 7y agohttps://github.com/raxod502/TerrariaClone/blob/master/src/TerrariaClone.java https://github.com/raxod502/TerrariaClone/blob/master/src/Te...
- sol_remmy2 7y agoItem #: SCP-3137 Object Class: Keter Infohazard, Cognitohazard Special Containment Procedures: Do not look at this code
- packetpirate 7y agoIf SCP-3137 is viewed, the subject shall be immediately taken into custody and then fed to SCP-682.
- AnIdiotOnTheNet 7y agoIf it can be contained that easily it is 'Safe', not 'Keter'.
- rococode 7y agohttps://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.
- Scaevolus 7y agoIt compares favorably to the official Terraria code (decompiled version here): https://github.com/TheVamp/Terraria-Source-Code/blob/master/Terraria/Item.cs 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, on the order of >100KB/s/player.
- GrayShade 7y agoThat's decompiled or automatically generated code, right?
- tudelo 7y agoI have to believe there is a 0 percent chance a human wrote all of that. It's the only thing that will keep me sane 8)
- Scaevolus 7y agoYes 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.
- ynik 7y agoThe 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.
- sbraden 7y agoI read Snow Crash; will not click.
- juliangoldsmith 7y ago𒌓𒁺 HN's font saves you this time...
- leetbulb 7y agoSame here. Ha!
- waqf 7y agoSo what you're saying is that a pattern of printed symbols that you looked at once in the past has permanently affected your response to stimuli?
- bryanrasmussen 7y agoAbout 12 years ago I was working at a company in which a developer had recently left, and left behind some code that had a bug in it that needed fixing, the code was processing some XML and I knew a lot about XML so I was called over to look at this code. The code was actually very simple, it consisted of for loops over a bunch of element nodes in which child nodes had to be compared with child nodes in other element nodes, or in which attribute nodes needed to be compared with other attribute nodes, whenever one of these nodes that needed to be compared with other nodes was found a new for loop would be started to loop over the whole set of nodes once again to find the attribute or element with children that needed to be compared with the currently selected attribute or element. I am describing this so succinctly and clearly for you so that you may experience a deeper understanding of just how succinct and clear the code itself was. Whenever values where found that matched they were added to an array that was later looped over to get the values to actually doing something with them. They had printed out the oode, it was nearly 100 pages - I was pretty sure I could have done it in less than 2 pages (it was in C# and I sucked at C#), I mean the actual XML that was being analyzed would be less than 5 pages if printed. After looking at it for a few minutes I announced that it should be rewritten. The other developers wanted to continue on with it to find the bug. I think they had been driven insane. on edit: by less than 2 pages I mean that it might be more than 1 page but I suppose not 2 full pages.
- xtracto 7y agoReminded of a time I took the code of our Data Scientists (2 physicists that "coded". They decided to make their own ORM in Ruby (called "Mondongo") instead of using one available. No wonder, the code was a real mess... For example, they needed to get a numeric value from a dropdown box that got several text options. The way they did it was: fieldVal = textField.gsub('text string 1',0).gsub('another string 2',1).gsub('anotherstring3',3)..... and so on with all the options. And in theory they looked for a 0, 1, 2... etc. Another WTF was that, when we told them we would be upgrading from Ruby 1.8 to 2.0, they told us that they were not sure, because 2.0 did not work that well... As it happens, at some point in the code they were using the .object_id property of a boolean value and testing it == 2 or 0. Well... ruby 2.0 made true.object_id == 20 , so things did not work as expected.
- AstralStorm 7y agoI've seen different kinds of comparably atrocious over the years. This is at least obvious and easy to explain badness... And the lesson was learned. Some people don't learn it or are forced to ignore it all the time by middle management. (This is how you go grey haired from stress.)
- maximente 7y agosounds like it runs a game-like thing (albeit with a lot of errors), so hey, he shipped something and probably learned a lot as an aside, i have never seen short used in java code until today after like 10 years
- _bxg1 7y agoHonestly 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.
- _bxg1 7y agoThis 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 guess that the programmer came from a C background (where brevity tends to be valued and abstractions tend not to be) and used Java because it's cross-platform.
- stirfrykitty 7y agoThat's not bad, actually. It's one reason why I hated leaving Perl for Python. Python is a little too orthodox sometimes. What I'm seeing is where frameworks are becoming the new "programming languages". People now bicker over what framework to use rather than first master the language they are using for a task. I tend to favor the method of "do the simplest thing that works".
- agumonkey 7y agototally should have been called p(...)
- jlewallen 7y agoI'd bet they made that function so they had a single place to intervene on text being written, not necessarily for the brevity/aesthetics.
- _bxg1 7y ago
- squirrelicus 7y agoSetting up a game world is notoriously imperative and makes every OOP-minded dev rip out their hair trying to do it how they think it should be done before realizing the truth that, for this kind of problem, ugly and imperative is good. In my estimation, the sin is the cyclomatic complexity.
- Bukhmanizer 7y agoI 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.
- jschwartzi 7y agoIt seems like you could use all the extra whitespace to embed another program within the program.
- _bxg1 7y agoYeah. 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.
- stirfrykitty 7y agoBut isn't this the beauty of programming to begin with. Barring certain things like medical devices, cars, etc., where it has to be very orthodox, for stuff like Web back/frontends, and even gaming, this is how people learn, I guess. Sure, that code could be re-factored for speed, cleaner in appearance, etc. Reminds me of the video driver (forget card) some Linux developers wrote that was ~30k lines of code. OpenBSD wanted to use it because the HW manufacturer wouldn't release the specs, but because the Linux code was GPL, the OpenBSD guys re-wrote it from scratch in less than 1/4 of the code.
- kehphin 7y agohttps://intuitiveexplanations.com/assets/Resume.pdf https://intuitiveexplanations.com/assets/Resume.pdf - author's resume is pretty impressive. Glad to see he's doing well.
- mntmoss 7y agoYes, 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.
- roland35 7y agoIt appears the author is well aware of this issue! From the readme: "Back when I was first learning to program in Java, I decided to try to make a clone of the excellent PC game Terraria. Of course, I was convinced that my version would have many more features than the official one. But before I realized how silly that idea was, I produced 11,000 lines of, to date, the most atrocious code I have ever seen in my life. I make it available here mostly as a cautionary tale of what can happen if you don't pay attention to the quality of your code. (Lesson learned, in my case!) Here are some of the highlights..."
- everyone 7y agoI'd like to know what age the writer was when they did this + How long they had been programming. Seems like they learned a lot from it.
- joeblau 7y agoI feel like the Java community will step up and refactor this to be as robust as Enterprise Fizz Buzz [1]. [1] - https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
- gattr 7y agoSo, to avoid people going insane, the code shall be put to refactoring. Each volunteer will only work on a single line of code [0]... [0] https://en.wikipedia.org/wiki/The_Funniest_Joke_in_the_World https://en.wikipedia.org/wiki/The_Funniest_Joke_in_the_World
- cpr 7y agoThe burning question of the day: Did it work?
- egdod 7y ago> it does not encourage meaningful / non-ableist dialog with the work Is it really ableist to think that sanity is objectively better than insanity? > ins*ne This is peak wokeness. We can’t even spell out the word “insane” for fear of offending someone.
- dang 7y agoOk, but please don't cherry-pick provocations from other places and bring them in here to get upset about. It's agitating, but not interesting.
- mr_puzzled 7y ago> 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).
- notacoward 7y agoI've seen tons of code, including code at companies famous for rigorous coding-interview processes to weed out weak programmers, that was far far worse than this. For all its bad properties, this code at least doesn't succumb to over-abstraction, obscure control flows or object-lifecycle rules, or desperate attempts to use every possible combination of language features in a (failed) attempt to look smart. Those things will kill readability and maintainability far more effectively than a bit of linearity or bad variable naming.
- pupppet 7y agoThis Radon has a good head on his shoulders.
- mikevp 7y agoI feel this way about git itself. https://git-man-page-generator.lokaltog.net/ https://git-man-page-generator.lokaltog.net/
- rv-de 7y agoCan someone ELI5 what's the big deal about that repo?
- carti 7y agoIt's absurdly "bad" form taken to such an extreme that it's basically parody (or art).
- RantyDave 7y agoI work with worse code than this on a daily basis. In fact, it's worse code than this I'm currently hiding from.
- stibba 7y agoI have a project from last year where I made my own little pokemon game using processingjs. I thought I had some decent knowledge of developing but the code consists of a file with 1900+ lines of code. It's terrible.. Also because I had barely any knowledge of how I should structure code.
- systemtest 7y agoI cloned the repo, wrapped it in Maven and sent it to SonarQube. - 9.5k lines of code - 333 bugs - 2 vulnerabilities - 6 security hotspots - 56 days of technical debt - 2172 code smells - 0.0% coverage - 21.5% duplications - 117 duplicated blocks I might be masochistic enough to try to fix these issues with a merge request.
- avierax 7y agoOne of the best things are the comments.
- env123 7y agoit's unmaintainable, "legacy" code at this point