Why reading code is important

One of the biggest problems with programmers today is that few have mastered the art of reading code. Read code? *Why* would you want to do that?

The reality is that the ability to read code is just as important as the skill of writing code. The main reason is to gain a better understanding of how a language works, and to improve writing skills. In this way it is no different to reading and writing a human language. The more you read, the better writer you become. It is the subliminal intake of word-craft, and writing style that makes this happen. It is no different with programming.

Reading a program helps improve quality, and style – and hence readability. It also helps absorb information about how things work. How many programmers look towards a piece of example code when trying to determine how things work? A description of a function findBlob() is fine, but seeing how it works is better for understanding how it can be used. Sometimes, as in the case of existing programs, you have to read it to comprehend what it does – there is no guarantee that it is well documented. The ability to port a piece of code, or make improvements to a program rely on good comprehension skills – the ability to look beyond what is printed on paper, and try and understand what the code is doing. Understanding a program is also a major linchpin in providing effective software maintenance, and evolution of systems.

Take for example, a piece of code written in Fortran:

There are of course many ways of reading code. Viewing on the screen works, but if the code is inherently long, then this becomes an issue. Large programs are hard to read. An alternative, and likely not very 21st century is to print out the code. This allows it to be annotated in a manner that probably will make it easier to understand. It can also be marked up with colours. It allows you to explore way more than looking at the code on a screen.

Now look at the same code from above printed out and annotated.

This allows a flowchart to be created. A visual representation often helps in analyzing code.

Now this can be used to re-engineer the code by migrating it to a newer version of Fortran, or translating it to C, Julia??

Reading code will help become a better programmer.

* Code and flowchart from “Introduction to Digital Computing and Fortran IV with MTS Applications”, (1971).


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s