Joset Anthony Zamora: Tips for Reading Soure Code

Joset Anthony Zamora: Tips for Reading Soure 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.

"