Digital Stronghold - Software Engineering Blog

November 25, 2009

Tips for Reading Source Code

Reading time is longer than the writing time and most programmers will lose focus along the way (some even fall asleep) especially if they are reading monstrous legacy code. There are several reasons why, in no particular order,

1. Procrastination
Programmer: [Wandering mind… Facebook… Twitter…] “Oh man, I have a brilliant idea, I’m going to read more on that… I’ll set aside this crap first and try to come up something innovative.”

2. Impatient
Programmer: “I hate this crap, ugly legacy code, it sucks! Can I just have the documents and rewrite everything from scratch?”
Project Manager: “Unfortunately, the source code is the only document we have.”

3. Interruptions
Team mate: “Hey! Can I have 5 seconds from you? I’m getting a NullPointerException, this is weird, I had everything initialized!”
Programmer: “Are you sure? Hold on, let me check that, you might have some methods returning null.”

4. Discontented -
Programmer: “What is this elementary code? This isn’t challenging, I want more challenge!”

etc.

You need to know what your goals are before reading the code. Start by asking these questions to your self and if you find out that you are losing focus along the way, just ask these questions again, it will help you get back on track.

1. Am I going to fix a bug?
2. Is this code implementing an API?
3. Am I going to add a new feature?
4. Am I just being curious to know the logic behind the code and nothing special?

Often times, you will be able to grasp the logic behind the code by running the program first. Consider the diagram below.

INPUT -> PROCESS -> OUTPUT

Being able to understand the INPUT and the OUTPUT, the PROCESS part will follow easily.

5 Comments »

The URI to TrackBack this entry is: http://eradicus.blogsome.com/2009/11/25/tips-for-reading-source-code/trackback/

  1. Another quality a programmer should always have while writing code is -

    To be dedicated of what he is doing. If he is just doing for the sake of it, there’s nothing good is gonna come out of it.

    Well read.

    Comment by Saj — November 25, 2009 @ 9:30 pm

  2. I agree man.

    Comment by Joset Anthony Zamora — November 26, 2009 @ 6:21 am

  3. 5) make someone else read and consequently, explain the code to you. (totally my style!)

    Comment by west coast marine — November 26, 2009 @ 10:03 pm

  4. Many time i have faced such problem in searching the source page. Here i got perfect solution.
    Cheap Car Hires Adelaide

    Comment by Rogger — December 28, 2009 @ 3:19 pm

  5. Hi ,

    I found your website perfect for my needs. It contains wonderful and helpful posts. I have read most of them and it was informative for all.

    Your blog is excellent and very informative to our visitors. Post was very nicely written and it contains useful facts. I am happy to find your distinguished way of writing the post.

    You can get all free Industrial software and downloads

    Comment by Don Fitchett — February 8, 2010 @ 7:19 pm

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Theme designed by Joset Anthony Zamora


Digital Stronghold

↑ Get Headline Animator