Re:Terraria Source Code (2013)
by tentacleuno on Tuesday February 15, 2022 @08:56AM
(#30346423)
Posted this because I remember seeing it a few years back and was like 'woah, thsi is bad.'
[ Parent
| on HN ]
Why is it bad? It fulfilled all purposes: It made the developer some (a lot of?) money, a bunch of people very happy, Terraria shares among the most positive reviews of all games on steam (also meaning there can't be too many critical bugs, as that would piss off gamers pretty easily), was/is frequently updated since years, and is generally considered "a good game".
What would a metric such as "clean code score" help with any of this?
Re:Terraria Source Code (2013)
by hesdeadjim on Tuesday February 15, 2022 @09:59AM
(#30347275)
This 100%. You are doing a great job if you maintain clean code for 50% of the project, because that last 50% will be a mad dash to get to ship.
Source: 12 years in gamedev ;P
The code looks bad. I guess it has been refactored later.
The repo says this code is only for educational purposes. This spaghetti can be still a good example for the reasons you mentioned. Or maybe it is a good example for an ugly prototype version of an game.
This could be even better if people could see a refactored version of this codebase.
Re:Terraria Source Code (2013)
by CodeGlitch on Tuesday February 15, 2022 @09:56AM
(#30347219)
Games don't optimise for "clean code" or maintainability - they optimise for speed and cost. Of course in a perfect world it would be all of those.
- Former game developer
I'm really wondering why clean code or maintainability imply higher cost or lower performance for you.
Re:Terraria Source Code (2013)
by CodeGlitch on Tuesday February 15, 2022 @10:16AM
(#30347506)
Because game code is "throw away" = don't assume you are making a sequel = there's no reason to make it maintainable. You write it as fast as you can to fulfil the requirements. Stuff like unit/system tests are a waste of time because it's cheaper to hire people to manually press buttons.
Yes I know this sounds bad - but that's how the games industry works. And is one of the reasons I left.
Note that if you are working in engine code, then you want all the automated tests, proper architecture, etc.
Are you not aware that decompilers exist and that is likely the reason this code looks the way it does?
Re:Terraria Source Code (2013)
by tentacleuno on Tuesday February 15, 2022 @01:58PM
(#30351034)
Hmm, no? It says nothing about decompilation in the repository, from what I can ascertain. How have you deduced that the code is decompiled?
Re:Terraria Source Code (2013)
by crossworth on Thursday February 17, 2022 @10:00AM
(#30373742)
It's pretty clearly reverse engineered from bytecode by some sort of tool. It's full of `goto IL_label` statements. Would a programmer write a goto in C# at all, let alone call their procedures "intermediate language xyz"?