18 ms·
TerrariaClone – An incomprehensible hellscape of spaghetti code
- Zekio 9y agoI forgot this existed, high quality code right there
- Scaevolus 9y agoThe real Terraria code isn't much better. Here's their 3MB [decompiled] NPC.cs: https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1947ee334ac8dc80d9adb3973cd708/Terraria/NPC.cs https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1... They had serious problems implementing multiplayer because they had to synchronize objects with 50KB of state every frame.
- warent 9y agoI just scrolled to the bottom and all I see is } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } What the fuck
- mikeash 9y agoThis is decompiled code, not the original source, so much/most/all of the craziness probably comes from that.
- danbruc 9y agoDecompiling .NET or Java binaries usually yields code very close if not identical to the original source code, at least unless an obfuscator was used but that seems not to be the case here. Chances are very good the original source code looks almost exactly like that code, maybe with some additional comments.
- amyjess 9y agoMind you, a lot of Java 5 and later features like generics, switch on Strings, Iterable-based for, etc., are syntactic sugar implemented in the compiler, not part of Java bytecode, so those features don't decompile well.
- thefifthsetpin 9y agoIn this case, it's just that the decompiler didn't think of "else if" as a single control flow construct/keyword in the way that the original programmers did. What was no doubt written like this: if(a < 1){ }else if(a < 2){ }else if(a < 3){ }else{ } Decompiled into this: if(a < 1){ }else{ if(a < 2){ }else{ if(a < 3){ }else{ } } }
- danbruc 9y agoI will try this tomorrow, I am pretty sure dotPeek can recognize and output else if. Might be a coding style option though.
- mikeash 9y agoWouldn’t “else if {“ and “else { if” compile to identical bytecode?
- ufo 9y agoSure, but the decompiler can choose to always decompile to "else if {", which is more readable and more likely to match the original source code.
- mikeash 9y agoThat's my point. The compiler's choice of "else if {" or "else { if" is unrelated to the programmer's choice.
- danbruc 9y agoIt does and at least the current dotPeek 2017.2.2 decompiles it to else if and does, other than I thought, not allow to customize it.
- mikeash 9y agoObviously whatever decompiler was used here decided to do it the other way.
- MrMember 9y agoWow, I just glanced at the how they're generating random names and it's incomprehensible. What a bizarre way to do something rather simple.
- mattchamb 9y agoMy guess is they are using partial classes and generating a bunch of the code from other, much simpler files.
- monsieurbanana 9y agoSurely this file can't be edited by humans as is, right?
- XR0CSWV3h3kZWg 9y agoThis looks as if this was a compile target, not the source code. HitEffect is a quite the function. This reminds me of working on CDDA[1] before many of the refactors hit. CDDA is an interesting case, it stemmed from a situation similar to the original post (one person project, embarked upon it before knowing how to do so). It was a complete mess of macros, spaghetti code and data and code living happily side by side. https://github.com/CleverRaven/Cataclysm-DDA https://github.com/CleverRaven/Cataclysm-DDA
- TeMPOraL 9y agoIt was, or still is? Also, are you still working on it? I'm currently having lots and lots of fun playing this game (experimental builds). It's pretty much halfway there to Dwarf Fortress...
- XR0CSWV3h3kZWg 9y agoI stopped many years ago. I was working on it in between sending out job applications, I was happy to gain experience working on a code base larger than I felt comfortable reading and one that is ugly but a rewrite is not an option. I didn't add too many features, I was mostly reducing the amount of compiler noise and fixing any bugs I ran across.
- kbenson 9y agoFrom the first couple hundred lines, they obviously know how to use a switch statement (as in how it works at least), but the odd cascade of if statements at the bottom makes me question whether they know when to use a switch statement (but then again, the stuff a the top makes me wonder that a bit as well). Edit: As someone else noted, if this is a generated file, that might explain a lot of this.
- jcl 9y agoPer the description on https://github.com/csnxs/Terraria/ https://github.com/csnxs/Terraria/ , this isn't the Terraria source code -- it's a decompilation of the binary.
- maxton 9y agoImportant to note is that this code is not the source code, but rather was generated by dotPeek, a C# decompiler, as mentioned in the repo's README: https://github.com/csnxs/Terraria/ https://github.com/csnxs/Terraria/
- Scaevolus 9y agoVariable names and comments are lost, but the overall control flow structure of decompiled Java and C# code closely matches the original.
- danbruc 9y agoEven variable names are usually not lost.
- TeMPOraL 9y agoStill - does that decompilation roll back any kind of array unrolling C# compiler may be doing (assuming it's doing it)? If not, it could explain those long chains of if/else seen in the decompilation. Maybe they're arrays of constants in the real code?
- kevindqc 9y agoThose SetDefaults methods.. ouch. On the plus side, it's fun to press the page down and see the code 'animate' from left to right
- k__ 9y agoyes, also that it comes back to the left after it hit the right end lol
- saltedmd5 9y agoThis gave me palpitations and then killed my browser.
- taw55 9y agoOh wow. That might explain a lot of my lag I’ve had when multiplaying on large maps (on LAN).
- danbruc 9y agoThat actually doesn't look too bad to me. Sure, it's verbose, repetitive, and deeply nested, but just from skimming it, it looks quite comprehensible. Load all the data from files instead of filling huge arrays and maps in code, abstract similar code into methods, tame the usual mess when dealing with grids with some helper functions taking care of clamping or wrapping around coordinates, replace all the parallel arrays with structures, and you should be able to have some reasonable good code in no time. Might be a nice exercise in refactoring.
- yathern 9y agoTruthfully - I wouldn't call it spaghetti code. I think of spaghetti code as way to many abstractions (AbstractEntityFactoryFactory). This code has the opposite problem - needing more abstractions - which is the easier direction to move.
- fleitz 9y agoYeah, I call the abstract code problems astronaut code, or more generally J2EE best practice code. To me this perfectly fits spaghetti code. https://www.joelonsoftware.com/2001/04/21/dont-let-architecture-astronauts-scare-you/ https://www.joelonsoftware.com/2001/04/21/dont-let-architect...
- watwut 9y agoSpaghetti code is when procedural/functional coding goes wrong which is pretty much opposite of too much abstaction. Basically, spaghetti is what was before OOP when it went bad. At least, I did not heard people to refer to too much abstraction as spaghetti before. For the record, this one is not that bad. It is comprehensible and pretty easy to refactor. Real spaghetti is something you have no idea what it does.
- jdmichal 9y ago> I think of spaghetti code as way to many abstractions... That's usually termed lasagna code. Lots of layers with a little bit of filling in between. https://en.wikipedia.org/wiki/Spaghetti_code#Lasagna_code https://en.wikipedia.org/wiki/Spaghetti_code#Lasagna_code
- stuaxo 9y agoI've seen way worse code than this in my time, some in the last year.
- yathern 9y agoI love DoubleContainer: https://github.com/raxod502/TerrariaClone/blob/master/src/DoubleContainer.java https://github.com/raxod502/TerrariaClone/blob/master/src/Do... which is fortunately only used in a comment here: https://github.com/raxod502/TerrariaClone/blob/9ea04b15add48141dbcb905af8fc906d423d854d/src/World.java#L725 https://github.com/raxod502/TerrariaClone/blob/9ea04b15add48...
- XR0CSWV3h3kZWg 9y agoAnd here is someone that is trying to rewrite it in scala: https://github.com/BusyByte/TerraFrame/tree/convert-to-scala https://github.com/BusyByte/TerraFrame/tree/convert-to-scala
- tbodt 9y agoA perfect example of "it's so bad it's good."
- beala 9y agoI think true spaghetti code requires teamwork. I mean that seriously. You need at least 3 people all with different incomplete and incorrect mental models trying to modify the same codebase at the same time.
- russellbeattie 9y agoI agree. But then again, I'm like a completely different programmer than I was a few years ago, and even more different than I was years before that. I've got some long running personal scripts and projects I tweak every so often, and the end result is pretty much the same. "What the hell was I doing here? Whatever... I'll just add a bit of code and get it working. Done."
- davisdude 9y agoThat describes my experience with some of my GitHub projects fairly accurately. Actual commit I did a few days ago: > Begin rewrite of rewrite of rewrite
- worldsayshi 9y agoYeah, that sort explains why it's so hard to get anywhere with vaguely defined free time projects.
- davisdude 9y agoYeah. The trouble is, I have a very clear idea of what I'm doing when I start it, but then I get busy and drop the project for weeks to months at a time, only to pick it back up again. Sometimes I remember exactly what was going on. Most of the time, though, I look at the code, think "This was done horribly! Why are there so few comments?" then proceed to do the exact same thing. It's a vicious cycle...
- zokier 9y agoInstead of having everyone working at the same time, stretch out the team over longer time with some overlap. This ensures both the "broken telephone" effect and discourages any major improvements.
- beager 9y agoI did the same trying to write a Minecraft clone back in 2012: https://github.com/beager/craftalike https://github.com/beager/craftalike I'm very much not proud of the code, it's sloppy, incomplete, quite copy-pasta. But it helped me learn a lot of concepts about game dev that a web dev wouldn't know, and it was tremendously exciting to create something in code that you could compile and play around with. No regrets.
- k__ 9y agoI did one too. We basically gave up after the networking stuff grew over our heads.
- indescions_2017 9y agoI'd actually try to recruit raxod502 at the high-school senior level. It certainly shows passion and commitment. You just need to grok the higher level abstractions. And may in the end even find your "spaghetti" version is actually more performant at run time ;) The thing is you sort of need to write like this for the first draft of your first game. And Terraria is pretty ambitious. Considering most people struggle with BlackJack or Pong or Snake!
- apo 9y agoWriting code in spare time, not to mention 11,000 lines of it, already sets any high schooler (or any beginning programmer) apart from the majority of peers. It's shocking how little students in "AP" computer science courses actually end up doing, and how few do anything outside of class. Given the choice between interviewing a student who had produced nothing but verbiage and one who had produced TerrariaClone, I would go with the latter without even thinking about it.
- criley2 9y agoI had a rather unique AP Computer Science high school experience a number of years ago. The AP class was mainly a self or group study class inside of a lower level programming class. We didn't get as much directed study, but we basically were allowed to chose projects that interested us and spent a lot of time developing them and getting help, iterating, figuring it out. We ended up doing only OK on the AP exam, but we had built a pretty impressive little java app by the end. A scrolling tile based map, enough network code to run a chat and let users join, and we had started building some game logic on top of our multiplayer game room. Very cool and informative, but not exactly what the AP exam was looking for.
- johnvonneumann 9y agoComments like this kill me a little on the inside, I can't stand having real work devalued for the sake of contrived assessment criteria.
- 1001101 9y agoI had to see for myself. Yep, that's bad. What's not bad is the author's attitude about learning and improving. It also looks like this was a stop on the way to Harvey Mudd CS. [1] So, a happy ending, perhaps. [1] https://github.com/raxod502 https://github.com/raxod502
- iaw 9y agoWith one exception I've never looked back at code I've written and thought "well that's well designed." Typically every few months I've improved enough to notice the quality difference.
- DubiousPusher 9y agoA little more egregious than usual but some of this is not that far from code I've seen in multiple AAA games. Some of which you've probably played.
- zokier 9y 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! Seems surprising, 1.3kloc doesn't feel that big in the scale of things. I wouldn't be surprised if some of the methods at $work would be on the same scale, and it compiles just fine (relatively speaking..). And based on quick scroll-through, there isn't really anything especially egregious in there that would point towards why the compiler fails.
- ecshafer 9y agoNot having looked at the code, my guess would be what the 1k+ loc of method is doing. If it's mainly a bunch or if elsea or a switch statement that jumps to another function, which is what most gross long Enterprise code is, I imagine it's fine. But if you have 1k loc that is procedurally creating objects and doing a lot that depends on previous operations then I could see starting to run out of memory. We also don't know how much memory they had, most Java code for Enterprise is running on pretty big servers or workstations.
- tigershark 9y agoIn one of my previous jobs there was ClassSomething1, ClassSomething2 until 5 just because java can't have more than 65535 methods in a class..
- jcl 9y agoGiven the relative size of the function and typical memory, I suspect that the issue the author ran into was actually the JVM's 64KB limit on the bytecode size of a compiled function. https://stackoverflow.com/questions/17422480/maximum-size-of-a-method-in-java-7-and-8 https://stackoverflow.com/questions/17422480/maximum-size-of...
- flavio81 9y agoBeauty. I see beauty. I see God in one 6000-line class (TerrariaClone.java), overflowing with constant data / tables embedded in the code. Awesome! PS: "Abandon all hope..." PS/2 * : I saw it and i suspected this was code generated by other tool; then somebody commented that this was based on dissasembled .NET bytecode. This explains it all! * (c) IBM
- kevan 9y agoIt's beautiful. I have a sudoku solver that's almost as bad (but not as impressive as yours) written in Scheme when I was first learning how to code. It's good to look back on your past work every once in a while and see how far you've come.
- deleted 9y ago[deleted]
- fancyPantsZero 9y agoThis makes me sad. Not because of the code quality, but because it makes me think of all the games I used to write back in middle school that are now lost to the swirling sands of time. The youngins don't know how good they have it with github!
- sgs1370 9y agoYour comment reminded me of a game (maybe the only one) I wrote in middle school, on a TRS-80 Color Computer (I think 4K, although maybe I had the 16K upgrade by the time I wrote the game). I wrote it in basic & saved it on some cassette tape... random blocks of one color on the screen, and you are a block that starts at the bottom and you use arrow keys to avoid the blocks as you are thrust upward. (I guess it was basic in more ways than one). I might have added a 3rd color block that gave you points if you hit those. I wonder if I could even write it now - even at low resolution? My limited scripting is now systems-oriented, the tiny bit of UI stuff takes me forever & I find HTML & JS way more complex than basic ever was. (Don't misunderstand, I think my python scripts that interact with various AWS services, postgres, etc are just fine and don't take me long to write or maintain, its just the whole graphics world I never latched onto...)
- speedplane 9y agoMissing out on the nostalgia definitely is a loss. But re-reading that old code, or worse, putting it on github for all to see makes me cringe.
- azr79 9y agoO(N^2)is hell of a drug
- writeslowly 9y agoThis reminds me of the C# source code for DRAGON. Its code was actually much worse, because the creator wasn't aware of things like loops or method definitions (the main game loop and class appear to have been generated by a framework). The C# code is here, and it works well enough that you can buy it on Steam, apparently: https://gist.githubusercontent.com/alessonforposterity/832da4fab11e10609dad/raw/258df12378399919ae088ba8731a7571d9c2c947/drgn.txt https://gist.githubusercontent.com/alessonforposterity/832da...
- serhei 9y agoThe ability to buy something on Steam is sadly no longer a guarantee that it works.
- jackmott 9y agoI played it. it worked.
- dividuum 9y agoI'm a bit reminded of the central GAME.C file from the original Duke3D source code: https://github.com/videogamepreservation/dukenukem3d/blob/master/source/GAME.C https://github.com/videogamepreservation/dukenukem3d/blob/ma... It's almost 10k lines of nested if statements, lots of magic values and so on. Still one of the most enjoyable games of its time :-)
- chris_wot 9y agoThe Terraria clone is apparently very much like the original: https://github.com/raxod502/TerrariaClone/issues/2 https://github.com/raxod502/TerrariaClone/issues/2
- Buttons840 9y agoThis makes me miss my early days of programming, where no code was too verbose or horrible to stop me from progressing towards my goal, no matter how misguided I was. Nowadays I'm distracted by the first hint that there might be some better way, and all progress stops. I think I'm just beginning to recognize this, and maybe one of these years I'll learn to recognize when the right abstraction is really important and when it's not worth sweating the small stuff.
- jackmott 9y agowatching the creator of The Witness do some live stream coding made me realize this too. he just typed the convenient thing he needed at each moment and didn't try to abstract away the mess. just forged ahead.
- baby 9y agoThinking of video game, I think this is a good analogy: a lot of what you write in the beginning are just tools to your own program. I'm really talking about the lines in your code, they're structured so well that they will help forge more code in the middle and later parts of your code life. Like any good video game, if you produce good tools in the beginning to produce levels, modes, multi-player games, etc... then you will produce something great. If you don't care about what you're writing, then it will become a huge mess and you will either give up or your users will give up. Or once in a life time, the mess you created will still be fun enough that everyone will start playing it, deadmau5 will make a tattoo of it and Microsoft will buy you out and you will have the most expensive house in the world/LA.
- jackmott 9y agoBut you can go too far there. The Witness guy explained it like this: You need to do a breadth first search of your code. If you rabbit hole for weeks making the perfect level design tool before you have already made a working prototype of the game for example, you might then months later, as you build out the game, realize the level building tool you have made isn't really suitable. As you start filling out the breadth of your design a time will come when you know an idea is going to work, and you have more knowledge to inform your tool. Of course to what extent you should approach the coding breadth first vs depth first will depend on how clear of an idea you have for the design. If you were just doing a near-clone of Doom and you have done this before then maybe you can just rabbit hole pretty deep from the get go.
- jason_slack 9y agoThe fact you took the time to follow your idea is great. Kudos. Also, the fact you "think" your code is spaghetti shows you have grown as a developer. Kudos. Love the part about codeToLarge()
- smrtinsert 9y ago6560 loc in TerrariaClone.java. Closed tab, will never look again.
- hinkley 9y agoA lot of that file is data. Some of it is just plain data (arrays), a lot of the rest is a bunch of setters one after another.
- S_A_P 9y agoAs Ive gotten older, I have severely relaxed my dogma on coding standards. I agree that code should be maintainable, legible and logically formed. Sometimes though, you just need to get things done, and architecting a large solution of abstractions and frameworks, just doesn't seem like a good use of time.
- hinkley 9y agoFor me it feels more like a zero sum game. Some things I care about a lot less, others I care about more. The biggest problem I have is with obscure code, and my understanding of obscure has shifted over time. Basically, I prefer code that gets you to ask the right questions. I'm still trying to put my finger on what qualities those are. I still care about code that looks one way but does something else, and I care about code that conceals what it's doing and how it accomplishes it by using convoluted delegation. But a function with a single purpose and clearly named? If it's loaded with kruft I only care if it's on a flame chart or I have to keep stepping through it while debugging another issue. So I care more about functions in the middle or the top of the call tree and less about the leaf node ones. I still push back on "It's not that hard to figure out this code" on the grounds that when an odd bug happens I'm going to be scanning dozens of functions trying to spot an issue. If every one is chock full of code smells, that process takes forever. In fact it discourages people from doing the right thing and instead they slap more workarounds on top instead of trying to find the real cause.
- twic 9y agoReminds me of a rather insightful comment from a Hackernews a few years ago [1]: > People write MLOC monstrosities in Java because they can. You get some boring financial topic and some sub-par programmers and they'll write as much garbage as the language can possibly sustain. > These things are a testament to how safe and simple Java is as a language. > Not having massive crappy code bases is a negative sign in terms of how reliable and easy to understand a language is. [1] https://news.ycombinator.com/item?id=7653762 https://news.ycombinator.com/item?id=7653762
- egeozcan 9y agoI think that has a lot to do with the IDE as well. When I'm using Visual Studio, I autocomplete and peek until I find something that even remotely does what I need in the library and move on. I come back and optimize when I see smoke coming out of the CPU or my project manager :) (Of course I'm responsible with my code and this is an exaggeration but could this be called "too mature optimization"? :) )
- giancarlostoro 9y agoI'm guilty of this, matter of fact I'm sure a good number of us (developers) are. Though lately I find myself looking up documentation aside so I can read through examples and find more information. Some languages / libraries are better documented than others, and sometimes Stack Overflow fills a niche. I noticed one library that was not afraid to document things recorded on Stack Overflow that they made into official documentation and made a reference back to Stack Overflow which I thought was perfect since you get the context behind that documentation, as well as it solved a real problem.
- tgb 9y agoWhen I first started programming (this was in C++), I decided that the obvious optimisation was to declare all these redundant local indices i,j,k as globals. Then the program won't need to make all this redundant crap! Of course that led to absurdly subtle bugs that only occasionally showed up since whenever I called a function which had a loop in it from inside of another loop, I would use i as the index for both loops. Error! I learned several important lessons when I figured that one out. But now the author here says they're doing that same thing! How has this not inevitably led to problems? Or am I misunderstanding the scoping in Java?
- MetallicCloud 9y agoI'm sure it would have lead to problems, that's just one of the examples of beginner mistakes with the code. That's kind of the point of this post, for the author to poke fun at themselves for the number of newbie mistakes they made.
- raxod502 9y agoOriginal author here. The fact that all the methods were so ridiculously large made declaring loop indices globally less of a problem. But trust me, it caused plenty of bugs... :P
- keithpeter 9y agohttp://sohcahtoa.org.uk/kepler/tmoon.c http://sohcahtoa.org.uk/kepler/tmoon.c Grunge C and huge comment block at start, compiles and works though. One day, I'll revisit this and have a think about data structures.
- Retr0spectrum 9y agoWow, that indentation...
- keithpeter 9y agoYup. Was written about 20 years ago. I'm an amateur.
- BlakeCam 9y agoI wonder how hard it would be to write a program to automatically refactor code like this into something reasonably clean. My intuition thinks it should be difficult but possible... and extremely useful.
- jeremyjh 9y agoThere are linters which do a bit of this, but they only cover the lints they have rules for. I'm pretty sure no one has a rule for "all loop indices declared as class members" because no one writing code of this quality has yet used a linter. Many issues in this code-base are not tractable at all for automated repair: how are you going to rework thousands of line long methods into well-factored classes and methods?
- dbremner 9y agoReSharper (and presumably IntelliJ) supports expression-based search and replace. Here are some commits where I used it to remove boilerplate from some test cases. The code was written long before MSTest added support for Assert.ThrowsException. https://github.com/dbremner/PowerCollections/commit/a364a1548e7ba0e8e57ec63f4cd09aab04c09cda https://github.com/dbremner/PowerCollections/commit/a364a154... https://github.com/dbremner/PowerCollections/commit/1de2f916faacea4c62403edb4916363711c5a0e9 https://github.com/dbremner/PowerCollections/commit/1de2f916... https://github.com/dbremner/PowerCollections/commit/183e3c7c345c667c575a046af348dd6444a24895 https://github.com/dbremner/PowerCollections/commit/183e3c7c...
- amatecha 9y agoI can barely even read the README.md ... too scary. This is perfectly in time for Halloween season! :'D
- hinkley 9y agoI would love if we could get together as a community, take a project like this, and use it as an example for what a little refactoring can do. As a cooperative endeavor it should be doable, but a competition would be more fun, though I can't imagine how you'd judge such a thing.
- raxod502 9y agoSee https://github.com/BusyByte/TerraFrame/pull/1 https://github.com/BusyByte/TerraFrame/pull/1.
- mcdirty 9y agoI did a 3 month contract working on porting Terraria (the actual game) from XNA to Unity and updating things like UI from sprite batching etc. Coincidentally and fwiw, the actual source code to Terraria was also a hellscape of spaghetti code.
- doesnt_know 9y ago> porting Terraria (the actual game) from XNA to Unity Can you talk about this? What was involved? Why do it? Major roadblocks? Do you feel it was it worth it?
- MBCook 9y agoXNA is limited to MS platforms isn’t it? Is imagine it was so they could port/sell to iOS, PlayStation, Mac, etc.
- doesnt_know 9y agoMonogame is practically a drop in replacement which has multi-platform support/targets. FNA is also effectively the same, with a slightly more "purist" approach. I honestly just assume that anyone that says XNA in the context of development in the last 5 years actually means one of the modern mono implementations.
- 201709User 9y agoYou can hire cheaper ready-made Unity devs afterwards. There is even a certification now.
- photojosh 9y agoAh, so you're the one to blame for the "loss" of hour upon hour of my kids' lives. It's pretty nice to see them sitting side by side on the couch, each with an iPad, muttering gibberish at each other. Warms this nerdy father's heart. :)
- smithkl42 9y agoI'd hire in a second anybody who's thought this hard about how to critique their own code.
- deleted 9y ago[deleted]
- Sir_Cmpwn 9y agoI have an implementation of Minecraft I'm pretty proud of: https://truecraft.io https://truecraft.io However, it is the evolution of several much more embarassing projects. In order from oldest to newest: https://libminecraft.codeplex.com/ https://libminecraft.codeplex.com/ https://github.com/sircmpwn/Craft.Net https://github.com/sircmpwn/Craft.Net https://github.com/SirCmpwn/PartyCraft https://github.com/SirCmpwn/PartyCraft https://github.com/SirCmpwn/TrueCraft https://github.com/SirCmpwn/TrueCraft I still hate the client code of TrueCraft and it's due to be ripped out and rewritten from scratch. There were also projects earlier than LibMinecraft which, thankfully, have disappeared from the internet.
- Posibyte 9y agoSo I see you everywhere on HN. You usually have the not-so-consensus opinion that I usually agree with. First off, so we have a baseline. I never thought to check your profile and look for projects or blogs or anything. But wow, you have written some super neat things I had no idea about. Though apart from just posting to comment praise, more to the topic, I love seeing developer's old work when they were new. It's almost.. humanizing? Like, I swear EVERYONE at one point has were they said "I'm going to learn programming and make the coolest game, better than the other stuff, because I'm creative with ideas." And then you try it and you realize how not simple and straightforward that is. But you keep on it, you gain a passion for it. And as you posted here, you can see the evolution of skill and pragmatism. But apart from the topic again, Truecraft is super cool. Sway is super cool and I didn't know about it. I'm going to play with both of them tonight, so thank you for writing two awesome programs for me to spend my day off with :)
- Sir_Cmpwn 9y agoThanks for the kind words :)
- danschumann 9y agoWhen technical debt gets so large that you go bankrupt ( quit the project ). I did this with an actionscript game. Then an html editor. I did not know what I was doing. I looked back at the code and decided that starting from scratch would be much faster than refactoring what existed there.
- userbinator 9y agoMaybe the introductory text primed me to expect much worse, but I actually found the code quite readable although definitely underabstracted. I was expecting the opposite, the sort of code I usually see from beginning Java programmers: classes and methods everywhere, but almost no real work. A long time ago, I (briefly) worked with Enterprise Java. The things I saw were far worse than this. 100+ deep callstacks[1]. Dozens of layers upon layers of do-nothing indirection. Dependency inversion and injection used for just about everything. 50+ character-long identifiers. Tons of XML-based configuration. The majority of the code consisted of nothing but methods that only called other methods, perhaps with a trivial conversion or reordering of the arguments. This is perhaps an excellent example of how severe underabstraction is much better than severe overabstraction. There's very long sections of code here and some of it's very verbose, but it's all very concrete and just about every line is actually "doing something": the ratio of "actual computation" to fluff is very high. If given the choice, I'd much prefer working with a codebase like this than a lot of the Java/C# stuff out there. I also echo the sentiment from others that the author is clearly very talented and dedicated, and deserves much praise for even attempting to write something like this and getting so far with it. [1] Not mine, but for an example of this insanity: https://ptrthomas.wordpress.com/2006/06/06/java-call-stack-from-http-upto-jdbc-as-a-picture/ https://ptrthomas.wordpress.com/2006/06/06/java-call-stack-f...
- bendbro 9y agoI wholeheartedly agree. I've been trying to work that kind of coding style into my job, but it is difficult to do so without feeling embarrassed. My team also tends to jump on me when I try
- sytringy05 9y agomost stuff I look it is 95% boilerplate. At least this code does something :P @Author - Must admit although I'm glad there was a 3d array, I'm a little disappointed there were no object arrays. good job for getting it working, even though it was probably should have been put to bed...
- c3534l 9y ago
- avenoir 9y agoThe best thing about this is the open issue claiming it's "Too much like the real Terraria source code." [1] :) This bring back a lot of memories. Way, way back in the day i wrote a clone of Battle City [2] in XNA with a half-decent AI. I had intentions to learn and use some OOP patterns. I ended up with a handful of monstrous classes and generally a clusterfuck of spaghetti code. But... i learned a lot about AI and path searching algorithms and, best of all, it worked. I think i still have this code sitting on a disk somewhere. This makes me want to throw it on Github. Thanks for sharing! [1] https://github.com/raxod502/TerrariaClone/issues/2 https://github.com/raxod502/TerrariaClone/issues/2 [2] https://en.wikipedia.org/wiki/Battle_City_(video_game) https://en.wikipedia.org/wiki/Battle_City_(video_game)
- TeMPOraL 9y agoHoly shit. Be sure to read the issue. It turns out it's not really a joke - someone in the know points out that Terraria's code is basically the same quality, if not worse...
- sciolistse 9y agoYou used to be able to decompile Terraria into perfectly readable code, since its c# and they didnt use an obfuscator. The code base was atrocious, but it is impressive that they got something working, and pretty fun, together as quickly as they did. These days there are a fair amount of production Unity games out that you can extract full sources for.. Can make for a fun read sometimes.
- codingdave 9y agoNormally when I hear people disparage their early attempts at code, I think to myself, "Oh, come on... how bad can it be?" Well, this is bad. Really, really bad. On the other hand, there was nowhere to go from here but up. Gotta start somewhere, right?
- imron 9y agoI remember when I first started programming, and I couldn't figure out the obscure error message preventing the Turbo Pascal game I was making from compiling. Turned out having over 65k of global variables was too much :-D
- BearOso 9y agoThis isn’t too bad. Check out the source code for qb64, it’s hilarious: https://github.com/Galleondragon/qb64/blob/master/internal/c/libqb.cpp https://github.com/Galleondragon/qb64/blob/master/internal/c...
- aryehof 9y agoI think this is a good example of what has become standard thinking for much of general programming. That the way to write a complex application is an "agile" approach of hack it 'till it works. The result too often is that slowly over time, the result increasingly approaches being a big ball of mud as seen here. I find in interviews that nearly all programmers only have an approach for two types of applications. The first being a run-to-completion program that produces an output based on inputs. The second being a program where concepts are modeled as data entities, manipulated by behavior (typically just add/edit/delete) in an application/service/controller layer organized using functional decomposition. For problems that don't fit these two, all that is left is that agile hack-it approach. My hope is that some additional lessons were learned about how to apply appropriate program design to produce a result that won't just result in a different mess next time.
- partycoder 9y agoI have seen way worse. At least this code is indented, it executes, etc. I have seen code that is absolutely devoid of reason, logic, formatting, that doesn't even execute... an evented mess with 40 levels of nested callbacks with methods 6000 lines long made by people that just got fired after an incident with comments in some foreign language slang.
- gigatexal 9y agoProps to you man for making a game clone as a way to learn: even if it sucks that’s more than I’ve done to date (making useful utilities in python isn’t as cool as a game). I think it’s good to ever remember the past and learn from it so that you don’t repeat it.
- mickronome 9y agoDone 15 years as a consultant, and that code looked much better than some of the code I've worked with. Even right now I work with code that looks worse in many aspects, although in a slightly different way. The code of the game is very obviously written by someone which at the time had much more passion than knowledge, but who tried his/her best anyway. It's a lot easier to deal with that, than with 3000 line methods of complete and utter madness written by people who really should know better, people who actually get paid.
- andrewstuart 9y agoI like that people have the courage to start the process of learning and improving.
- deleted 9y ago[deleted]
- yellowapple 9y agoReminds me when I first stumbled upon a book on BASIC at my elementary school library, then got ambitious and tried to write my own Galaxian-ish game. Started with a whole screen with all the enemies and stuff, prompted for an input, and started trying to map out every single possibility. Needless to say, I gave up very quickly and convinced myself that this "programming" thing was way too hard. Didn't even start to dabble in it again until high school (and that was mostly a bunch of mucking about with VB6 in Word/Excel).
- vilius 9y agoNot sure if this is a common story for most programmers or maybe me and the author have same personality traits. Back in the Delphi 6 days I was 16, with no internet access I started learning about programming. It all began by reading an article of how to write assembly code in Delphi. Had no idea what it meant, but it was interesting. So I've started. 12 months forward I had made my first "commercial" product - Power Crypt. A Windows application allowing to encrypt / decrypt files. It as written in Delphi, had a single class of ±5000 LOC and used open source cryptography library. Main selling point was that it encrypted a file not by using a single algorithm, but with all (about 10 or even more) the algorithms the OS library had implemented. Thus making it more secure :-)
- arianvanp 9y agoThis reminds me of the original RuneScape codebase. It's a 16k line God class, with some utility classes for networking and graphics. Decompiled code floats around on the web under the name "runescape 317 deob" if you want to check it out. it's a real "beauty" and hacking around in it to create bots was my first experience with programming. Edit here it is: https://github.com/Rabrg/refactored-client/blob/master/src/com/jagex/runescape/Game.java https://github.com/Rabrg/refactored-client/blob/master/src/c...
- kdazzle 9y agoYou are so brave
- d--b 9y agoif (left) { if (right) { if (up) { if (down) { blockds[y][x] = 0; } else { if (upleft) { if (upright) { blockds[y][x] = 1; } else { blockds[y][x] = 2; } } else { if (upright) { blockds[y][x] = 3; } else { blockds[y][x] = 4; } } } } else { if (down) { if (downright) { if (downleft) { blockds[y][x] = 5; } else { blockds[y][x] = 6; } } else { if (downleft) { blockds[y][x] = 7; } else { blockds[y][x] = 8; } } } else { blockds[y][x] = 9; } } } else { if (up) { if (down) { if (downleft) { if (upleft) { blockds[y][x] = 10; } else { blockds[y][x] = 11; } } else { if (upleft) { blockds[y][x] = 12; } else { blockds[y][x] = 13; } } } else { if (upleft) { blockds[y][x] = 14; } else { blockds[y][x] = 15; } } } else { if (down) { if (downleft) { blockds[y][x] = 16; } else { blockds[y][x] = 17; } } else { blockds[y][x] = 18; } } } } else { if (right) { if (up) { if (down) { if (upright) { if (downright) { blockds[y][x] = 19; } else { blockds[y][x] = 20; } } else { if (downright) { blockds[y][x] = 21; } else { blockds[y][x] = 22; } } } else { if (upright) { blockds[y][x] = 23; } else { blockds[y][x] = 24; } } } else { if (down) { if (downright) { blockds[y][x] = 25; } else { blockds[y][x] = 26; } } else { blockds[y][x] = 27; } } } else { if (up) { if (down) { blockds[y][x] = 28; } else { blockds[y][x] = 29; } } else { if (down) { blockds[y][x] = 30; } else { blockds[y][x] = 31; } } } }
- nuclx 9y agoThe code doesn't look much worse than some of the production code bases I encountered.
- mwexler 9y agoThe ability and willingness to slag your own defective work is rare, especially in public. Compliments to the dev, who recognized how much he's changed and was able to point out flaws with no holds barred and some humour.
- zackify 9y agoLooks just like the Freepbx codebase, but that's php https://github.com/FreePBX/core/blob/release/13.0/Core.class.php https://github.com/FreePBX/core/blob/release/13.0/Core.class...
- louithethrid 9y agoOpen the Git Repository. Eyes glaze over. Just like the Robotsourcecode, you get to see every day, if you work in automation. Close the Git Repository. Dear Author, at least you know while and for.. it can be worser.