Skip to main content

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.

Comments

Popular posts from this blog

Architecture Complexity

Here are the items to consider: Coding to an interface Service Oriented Architecture Automated Testing Domain Driven Design Custom Data Access Layer Layered architecture Complexity is relatively equal the number of lines of code. Note that complexity is not bad. It must be justified.

Repair Windows 7 System Files

8 out of 10 average PC users have their box’s system files altered by malwares, viruses, etc. We usually reinstall the OS if the antivirus and anti malware software did not perform their job well. Here’s one way to fix the corrupted system files without the need of restarting your Windows 7 box. 1. Run the Command Prompt as Administrator 2. Type the following command C:\Windows\system32\> sfc /scannow 3. After the verification phase, you will receive a message about your system files’ integrity Windows Resource Protection did not find any integrity violations.

Android Studio:Unknown Host Error

After installing Android Studio, I got the following error: Unknown host 'services.gradle.org'. Please ensure the host name is correct. If you are behind an HTTP proxy, please configure the proxy settings either in Android Studio or Gradle. Consult IDE log for more details (Help | Show Log) Solution File --> Settings --> HTTP Proxy --> Auto-detect proxy settings