Code Quality Week part 7 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 7: Quality Code is Soft

Code that has high quality means that it is soft; it’s easy to tweak because values are set outside of any algorithmic code.

Let’s do a quick scan over the following example:

PART 7: Quality Code is Soft Code that has high quality means that it is soft; it’s easy to tweak because values are set outside of any algorithmic code.  Let’s do a quick scan over the following example:

So we have an inventory that we can add items to. It can contain a limited amount of items and its items are rendered in a grid layout using the relatively complex algorithm in the Render() method. This code is soft because all tweakable values are set outside of the algorithmic code.

We can easily tweak the amount of columns that are rendered by simply changing the COLUMN_AMOUNT constant in the top of the class. Likewise we can increase the item capacity by changing the associated constant without having to dive into the complex algorithms.

Soft code is great for a lot of reasons. To tweak a value in soft code, we won’t have to read up into complex code, won’t have to change the value in multiple places and won’t have to deal with any magic values (values without a name to make it make sense).

What makes your code soft? Tell us on facebook