Writing code is cheap. Understanding it, not so much.

Writing code is really cheap! There are three ways to do it, and you can use them all:

  1. Use a code generator (CodeSmith, T4, or your own);
  2. Use a micro code generator (templates in VS, Resharper, CodeRush,…);
  3. Take a touch typing course and get good at it!

Then comes the time we need to change the code. That’s the hard part, right? Well, not necessarily; there are tools that can help with that, too. If the change you need to make is to refactor the code, there are tools that do a wonderful job at that. The problem is understanding the code well enough so we can change it!

We spend little time writing code. We spend a LOT of time reading it. Doing things that can help us understand the code later on down the road is a must. Writing good tests is one of those things. Writing clean code is another.

The quicker you understand the code you’re facing, the more confident you’ll be making the right changes to it.

Code must be written with care. So must be tests. Tests provide a big help in understanding why certain code exists. Tests must be written in a way that they’re easy to understand.

When writing test setups (like setting up mocks and stubs, for examples), consider putting that logic behind a method that explains the intent behind that setup. This will help the reader quickly understand what’s going on, and it’s easy enough to jump into the details when appropriate.

The same goes for production code: consider putting expressions used in an if-block behind a method that describes the question being asked. In other words, instead of writing if (user.Age >= 13 || user.Age <= 19) {}, consider writing if (user.IsTeenager()) {}.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: