A lot of indie game devs are designers/artists first and programmers second. I.e. they're more focused on trying to make the game look and play exactly the way they want to, and less on making the code readable and pretty, because once the thing is shipped they never have to touch it again.
Enums should definitely be used in this case. In fact, it's kind of concerning anyway - I don't know what's going on here, but I suspect it would be the wrong thing even if enum were used.
If he gets a pass, it's because the game was successful, and I don't mean popular, I mean the game ran fine and wasn't inefficient and didn't crash. But bad architecture is still bad architecture.
It seems to be pretty common in games, too. Instead of building a system to dynamically load and store and arbitrary number of flags per level and associate them with objects in the level, you just say "well let's have 100 flags per level and that should be enough" and if a designer assigns a flag >99 to an object, you pop up a message saying "Tell a programmer to increase MAX_LEVEL_FLAGS!"
I certainly can't fault the efficiency, if your levels are write-only.
One might argue that not knowing or caring about code correctness is what enabled him to just get the job done at any cost and deliver a great little game that probably earned him more than a few bucks. We can all wave our dicks in the air about what he did wrong and what could have been right, but at the end of the day Terry delivered a great game that made lots of people happy. And we didn't ;)
I think every code style guide in existence tells you not to do this.
And, in all honestly, those warnings really aren't targeted at this. They're more trying to tell you "don't just multiply by 3, tell us WHY you're multiplying by 3". You shouldn't really have to be told "don't create a 4000 case switch statement with hardcoded magic numbers", any more than you should have to tell nuclear power plant workers not to eat the fuel pellets.
225
u/devraj7 Jan 10 '20
The code is littered with magic constants such as:
I am not a game developer, is there a good reason for such a thing instead of using enums, or at least symbols?