Code Quality Week part 5 of 8
This week we at Little Chicken are celebrating code quality. Resident Developer and Code Quality Guru Joris Van Leeuwen penned eight byte sized posts on this subject. Each day will see a new post on this subject.
PART 5: Code is Tight
Code that has high quality means that it is tight.
We keep everything as locked as possible to reduce complexity. Take a look at the following example:

Look at that, we already start off with making our code tight. There is no functional reason to make the Person class “abstract”.. but it makes sure the Person class itself will never be instantiated.
In the second line of code we use access modifiers to make the SkinTone field publicly gettable, but only this class and derived classes can set it to a new value. Again, there is no functional reason for us to do this – the game would run either way. But we reduce the amount of possibilities and thereby reduce complexity.
The UpdateSkinTone() method is marked as abstract, which forces all derived classes to include an implementation. This, again, is an example of making our code tight.
We force the code to only allow us to do what we want. Private, constant, abstract, readonly, sealed.. they are all hints that allows us to focus our brain power on what matters: making great games!
What makes your code tight? Tell us on facebook