Tips on how to read code?

Jeremy's asking:

So how do you teach people this “art” of digging deep very quickly into unfamilar code that you had no hand in writing? I myself, I come from a very traditional process of learning how to code.. by sitting down and writing it. I am struggling with how to tailor a delivery to focus on reading vs. writing source code. To me the only way you can be truely efficient in this process is by having written code yourself.

Comments (4)

  1. Anonymous says:

    Familiar Ground

  2. Capt. Jean-Luc Pikachu says:

    If the documentation for the code doesn’t help you read it, find the person who originally wrote the code and fire him. If he’s no longer w/ the company, track him down and puncture his tires.

  3. Richard Callaby says:

    To read code you must first understand what the code does. This means you must understand the purpose of the block of code you are reading. Essentially it would help if their were some comments on how the particular function or class operated and what was its purpose. If a programmer needs more than that to understand what it does they should be taken out back and beaten with a rubber hose. We teach this stuff to undergraduates in college and if the person has a college degree then there should be no problem with actually reading the code. It was expected before you graduate that you had at the very least the ability to do this task.

  4. John Murray says:

    Assuming the original developer and documentation are not available, I find that stepping through the code in a debugger is helpful, adding my own comments is helpful. Beyond that, depending on the code you are working with, using a UML modeling tool to generate a static structure can give you a better picture of the structure of the application and give you a better place to start than from nowhere. Finally, if you are trying to do something more than just ‘understand’ the code, there are some other tools that can be helpful, including calculating cyclomatic complexity to identify risky procedures, or timing tools (like True Time ..etc.. to identify bottlenecks.)

Skip to main content