
Want one of the simplest ways to reduce bugs?
Have one source of truth. That's it!
Every piece of data should ideally exist in one place and one place only. The more copies you have, the more problems you create.
Imagine storing player health in 3 different places, some sort of HealthSystem, a HealthBar and a Animator IsDead parameter.
Eventually one gets updated but another doesn't. Which one is right?
Now you have a bug and now you spend an hour trying to figure out why.
But the problem isn't the bug, the problem is that the architecture made the bug possible in the first place.
A lot of debugging pain can be avoided before the bug even exists if you have only one source of truth.
Good architecture isn't about being clever, it's about making mistakes harder to make.
One source of truth is one of the simplest ways to do exactly that.
If the HealthSystem is the only thing that owns the health amount, and all the other classes like the HealthBar just read and display that value, then if you have a bug with health amount you know for a fact it has to be on the HealthSystem since that is the one source of truth. If you encounter a bug you know exactly where it is.
That's the massive benefit of following this one simple rule.
I have an entire 1hr talk on YouTube all about this topic titled: "How to Write High Quality Code that doesn't fall apart."
If you're trying to be a professional game dev as opposed to just a hobbyist building throwaway prototypes, then I highly recommend you learn how to write proper high quality clean code. Best of luck!

English




