Live data from Hacker News

TerrariaClone – An incomprehensible hellscape of spaghetti code

github.com

141–150 of 289 posts

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#141
post #108

This 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…

As I had to work more with teams and then supervising teams I changed the abstractions I value from when I was programming solo: Now I care less about my project's function than the structure of the team. There is a saying that any complex project will end up mimicking the communication structure of your organization. I must confess I thought it was silly until I realized it happened to us. I now favor code that has…

Absolutely this. Some people think silos are bad, but it absolutely works brilliantly in terms of team cohesion. No stepping on toes. Few arguments because everyone is responsible for their own stuff. No nitpicking over irrelevant style preferences. Pride in ownership, self accountability, thoughtful decision making (mostly). All this leads to good working relationships that come in handy when cross-realm issues arise.

Every place that had a great team did it this way.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#142

I have an implementation of Minecraft I'm pretty proud of: 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://github.com/sircmpwn/Craft.Net https://github.com/SirCmpwn/PartyCraft https://github.com/SirCmpwn/TrueCraft I still hate the client code of TrueCraft and it's due to be ripped out and rewritten…

So 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 :)

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#143

Earlier quoted context omitted.

Ah, but try that in an interview and see what happens.

Interview coding skills are different from real world coding skills.

Yes, sorry I was not clear. The OP was correct in stating that sometimes one just need to get started, but it's hilarious that what one does in the real world is not something that is valued in an interview where one is expected to come up with a solution and iterate on it to have it fully optimized in 45 minutes.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#144
post #69

Earlier quoted context omitted.

My inherited spaghetti codebase took only 24 months for my predecessor to build. I was told: "don't worry, it's in SVN and all of the important switches are clearly laid out at the top." Well, it was in an SVN repo... with a single commit. It did have all the important switches at the top, none of them but the ones that were set actually worked. Man, I "miss" that job.

Was the comment of that commit 'initial commit'? :)

Not GP but probably: “Here be dragons

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#145
Maybe 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-f...

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#146

Earlier quoted context omitted.

Why do you say it's faster? It's guaranteed to fail branch prediction one out of ten times. My guess is that'd be a lot slower than using the integer modulo operator, which is not an expensive operation.

On their own, % and / are way slower than +, -, *, >. Cycle counts depend on your architecture, you can look them up. That mod is so slow and should be avoided is a kind of folklore based in truth - kind of like function calls being slow - but like everything time-sensitive the mistake lies in not profiling before (manual) optimization. There's an example on SO, I got similar results just now when I replicated it: ht…

> On their own, % and / are way slower than +, -, *, >.

And the branch instruction is free??

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#147
post #108

This 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…

As I had to work more with teams and then supervising teams I changed the abstractions I value from when I was programming solo: Now I care less about my project's function than the structure of the team. There is a saying that any complex project will end up mimicking the communication structure of your organization. I must confess I thought it was silly until I realized it happened to us. I now favor code that has…

> It also allows programmers, these very territorial beasts...

They should be. It's difficult to get quality experience if you're only designing by committee or executing on someone else's designs.

In other words, carving out niches for people is a great way to get your engineers to level up from junior to senior to beyond. They should, hopefully, appreciate the clarity in career progression also. They should be able to see themselves making bigger and more important decisions as they prove themselves.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#148
post #78

This 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…

Premature abstraction is generally worse than immature abstraction. Write the most straightforward thing you can, and wait for that feeling that it won't work out. Then, ignore that feeling until you get proof. If you've kept your code simple and clean reacting to a lack of abstraction is relatively easy, at least compared to what digging yourself out of the wrong abstraction is like.

Sandi Metz's piece on this: https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstracti...

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#149

I'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 w…

I did pong in rust to learn some rust, and it got me thinking how, doing pong was really easy (as an experience programmer) but if you wanted to do pong "properly", say supporting 4 different platforms, 5 languages, proper settings menu and high score table, supporting all manner of screen resolutions, full screen and windowed, sound, all popular controllers (keyboard, mouse, mobile input, game pads, joysticks) etc e…

I've often said that a team couldn't ship a production-ready version of Tic-Tac-Toe in less than a month...even if the implementation were already written.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#150
The 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

[2] https://en.wikipedia.org/wiki/Battle_City_(video_game)

Post reply on HN