At the Rails Way blog, Koz has posted an example of refactoring Ruby code to make it more “human” readable. He states this opinion:

It’s far more important for code to be human readable than incredibly concise.

I agree with the statement, but think its important to define “human readable”. In the example, both the before and after are clearly human readable by the human developer who wrote it. In fact, at the time of writing any piece of code the developer clearly is able to read it, or would not be able complete it.

The reason to create more readable code is not for the benefit of reading it easier at the time of development, it is so you can more easily dive back into it six months later, after you’ve forgotten why you did it the way you did it. There are so many solutions to every development situation, and six months from now you might not being using the same patterns for your development as you were then. Or, a different developer, with different preferences for coding style and patterns, may need to read your code and understand it very quickly.

It’s not that the future developer can’t understand it either way, but simply the reduced time to jump right to the matter at hand and focus in on the solution. As I said in the comment on the post, this particular example shows how to break up the various tasks of the activity of validating this Expense object, so that you can jump right to the validation issue that may be causing the problem. You don’t have to weed through a possibly very lengthy validate method, reading every single line until you find the one that might be at issue. Instead, you can read the descriptions of each validation step at the top (the pseudo code method names serve as descriptions) and thin pinpoint the validation step or steps that need a fix or expansion.

Taking the time to do this type of code refactoring at the point of original development, when you understand what is going on because you are fully involved in it, will save you and/or other future developers massive amounts of time and grief when readdressing the code months from now.