by JeffSnazz · 2y ago · 0 comments
This would necessarily presume applying the same attitude towards the happy path—you're describing something short of that.
Or to put it a different way: defensive programming necessarily implies a skepticism that you even are sure what the happy/error paths are!
I realize that this is a different person from you, but that's the attitude I am replying to.
There's code that can be allowed to fail, and furthermore, it will eventually fail due to the sheer amount of this code, the development time constraints, the number of possible game states, etc. I don't care that this code rarely fails under some arcane conditions, because this simply causes some button to stop working, some NPC to stop moving, but the game will remain playable. Even if the player notices the bug, they'll just shrug and keep playing. My aim is to make sure that the game recovers and returns to a healthy state after the level/save is reloaded. (Obviously, I'd like to fix/avoid every single possible bug, but it's impossible in practice. You'll have more luck continuously tracking in your head how dangerous the code you're working on is. Also, you rarely have the luxury of being the only programmer on the team. Bugs will happen.)
The other kind of code is the core game system stuff, the low level stuff, the error handling stuff, the memory stuff, the pointer stuff. You must pay special attention while working on this code, because failures will straight up crash the process or bring the game into an irrecoverably broken state (eg. all objects stop updating, stuck in some menu, the player never respawns...). Bugs like these are also highly prioritized by management. My update loop needs to be shiny.
Such is the reality of working on complex systems (or simple object-oriented programs ;))
But I insist the "unknown unknowns" are handled extremely simple, predictable and decoupled. Because those happy paths will fail. And then the exception-path must take over and this must be able to handle it predictable.
So no third party error services that I have to call over HTTP (HTTP will fail). No complex logging libraries (dependencies will become outdated). No difficult tracing middleware that has to be configured "just right" (configs will break). And certainly no flows that require a spaghetti-wrangler to follow along.