Editorials

Code Balance

Expanding on the topic of balance I wanted to consider balance when writing custom software. There are a number of things we balance when writing code. We need our code to be understandable to ourselves and others that follow. We need the code to accurately reflect the system requirements. We need our code to be SOLID as much as is reasonable. And, we need to write code quickly. Many practices help is balance these goals.

For me, unit testing is the cornerstone. It validates that the code is doing what it is supposed to do, from a system requirement perspective, or from the perspective of the method being tested. The amount of unit testing must be balanced with the amount of code written. At some point, you have to write code. So, how much of your code should be tested?

That is a controversial question. I have found that the answer, for me, is not a static one. I don’t like to always fall back on, “That Depends:” But it does. For sure I leave out properties, unless they have a lot of logic included. I don’t find it helpful to test the design of an object and its properties. That feels like noise generated by striving to have 100% code coverage, with little benefit. However, I have found that spending a lot of time on unit tests pays off in the long run.

Unit tests document your code. It tells the next person working with your code what it was intended to do, and how you implemented it. It can also be automated, so the design of your code is constantly validated.

Comments and documentation are areas the agile community has a tendency to ignore for practical reasons. However, when you are new to a mature system, how do you know where to start? Yes, your unit tests tell you how methods work within modules. But how do you know where to start? Sometime, if it aids understanding, it makes sense to create documentation (as little as possible). Too, a timely comment is not without rewards.

Share your thoughts on balance in comments or by email to btaylor@sswug.org.

Cheers,

Ben

PS. In case you missed my poor math (should have written a unit test), 10 pounds does not equal 22 kilos, as hkealy share in comments from yesterday. However 10 Kilos does equal 22 Pounds 