Live data from Hacker News

TerrariaClone – An incomprehensible hellscape of spaghetti code

github.com

171–180 of 289 posts

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#171
post #12
post #7

That 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 arr…

Truthfully - 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.

Spaghetti code by its original conception, code that uses GOTO to jump all over the program willy-nilly, mostly died with the adoption of procedural languages that eliminate or mitigate the usage of GOTO, forcing naive procedural style into something more reminiscent of straight-line code(which is generally a good practice, but still easy to deviate from with nested loops, function calls, state machines, etc.). But the general idea of "pasta code" that is hard to follow is going to stick around by any name.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#172

Earlier quoted context omitted.

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

Until someone goes on vacation, their area blows up and everyone else has to panic fix some code that they've never seen before. As a manager, one of my main jobs is ensuring that the team's bus number is always above 1 and scheduling vacation time so that we always have full coverage should stuff go down. There's a huge difference between a silo and giving someone responsibility for driving the design of a component…

You are right that this is something to consider. In my case the "realm" think was emergent and not enforced at all, but it was a bit implicit that if possible, you ask Bill his advice before rewriting a function of his model. The lead dev was still nosing around everywhere and had authority to call a piece of code defective and impose a rewrite.

One of the important function of the project manager is also to communicate clearly with upper management about what the team is and can do. We were working on a product that was not deployed yet and our priority was to release a functioning version ASAP, so redundancy was irrelevant. We had n features to develop, assigned to various developer. When one developer is on holiday, their features did not advance. We worked around it thanks to our modular architecture.

It meant that sometimes, was impossible to code before . I scheduled or denied those. This team and project structure is optimized for fast development with an heterogeneous team, not for reactivity.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#173

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]. D…

I 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

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#174

Earlier quoted context omitted.

That 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

Yeah, that sort explains why it's so hard to get anywhere with vaguely defined free time projects.

Yeah. 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...

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#175

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]. D…

I 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

most 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...

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#176
I 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.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#177

Earlier quoted context omitted.

> allows programmers, these very territorial beasts, to have their own little realms they control My 25 years of programming experience says otherwise. The only place where this works is with good(ish) programmers who are assholes and must have their huge, fragile egos stroked or they'll throw a diva fit. I don't hire or work with those people anymore. Neither should you. Joint code ownership produces better code bec…

> Joint code ownership produces better code because everyone wrote some of it and nothing is mysterious. I don't think it's one or the other. You need people to be able to jump in and contribute and improve things. But you also need responsibility for the code as a body of work. If everyone with commit access owns the code, nobody does. As time goes on and it's a snarl of spaghetti code and slapdash design, it turns…

What you said is contradictory. Jumping in and contributing and improving things happens when everyone is encouraged to change the code anytime. When individuals get territorial is when it rots because people are afraid to touch that "other person's code."

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#178
I 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.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#179
Props 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.

Re: TerrariaClone – An incomprehensible hellscape of spaghetti code

#180

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…

John Carmack's advice (I don't remember exactly):

"If you don't know which way is better, do it both ways and compare."

Post reply on HN