How to read source code
In the world where code leads the revolution, reading thousands of lines of source code is a cumbersome task, especially if you are a beginner. For a programmer, reading source code is essential in two ways — first, it helps you to get a first-hand look at better coding styles, and second, it helps to develop yourself as a programmer overall as the more source code you read, the more the good habits of coding get inculcated in you.
So in this article, I propose some ways to work your way through reading the source code.
I’ll start by mentioning some sources that will keep you motivated throughout:
Start by reading this How To Become A Hacker by Eric Steven Raymond. In this article, Raymond talks about the hacker culture and the hacker mindset and how to incline yourself to be one. It’s quite inspiring and a great post to jumpstart your journey.
- Coding Horror — Coding Horror is a blog run by Jeff Atwood, one of the two founders of Stack Overflow, the go-to site for every programmer. In this blog, Atwood basically talks about the philosophical and the recent trends in technology. It’s quite fun to read
- Joel on Software — Joel Spolsky, the co-founder of Stack Overflow, runs this blog and the talks about the IT industry, best practices, the culture, and much other interesting stuff. It’s quite an interesting insight into the real life of an IT professional
- Techlead — Patrick Shyu, an ex-Google tech lead, and now ‘The Techlead’, in this YouTube channel talk about basically two things — Computers and Philosophy — and his sarcastic touches to everything is quite fun!
- Paul Graham’s essay — Paul Graham is one of the founders of Y Combinator and his essays are quite inspiring, to say the least. Give them a read whenever you are feeling out-of-track.
From How To Become A Hacker by Eric Steven Raymond, I’d like to quote a Zen poem to inspire you to consider yourself a hacker —
To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.
Here are some ways to deal with it -
Start small — aim for some particular modules, understand it and then work your way around it. Remember, it’s your first time around with this much of plethora of code and you are never going to understand it if you aim to chunk up the whole code at once! So, pick out a module, for instance, I like to start with reading the models, and then work your way up.
Write — this might sound stupid but writing down the main functionality of the code you just read helps you in two ways — one, you are able to make yourself sure that you understand the code you just read, two, it helps you to summarize it in words so that you can explain it to someone else, just like the Feynman technique.
Google the code you don’t understand — there is going to be a lot of syntax or inbuilt functions or typical boilerplates of different frameworks that you won’t be able to comprehend. It’s better to Google these things than invest hours to read the documents from scratch.
Replicate the code — Just like Jeff Atwood said in his blog, you won’t become a better coder just by reading the code. Instead, if there is something particular about the code that you don’t understand or something that you found interesting, use the same in some practice project of yours to make sure you know your way around it.
You don’t need to understand the whole code — in a project, you are going to work with some specific technology or either in the backend or in the frontend. So you don’t need to get yourself accustomed with every intricacy in both the ends. Sure, knowing your way around both the ends is great, and you should in order to become better, but for starters aim for a particular end and then gradually progress towards the other.
Take breaks — reading code for beginners is an exhaustive task. To stay focussed while reading, make sure you start by reading the code for 90 mins, then take a 15 minutes break and then continue with the reading. As you become efficient, you won’t be needing this little break.
Don’t give up! — when a thousand lines of code burst up in your screen, it’s quite demotivating. I’ve faced it, you’ll face it, but you don’t have to give up! You should never give up. Be a stubborn little kid that gets whatever he wants because he is so adamant on it! In the end, the self-satisfaction that you get is more than anything :)
Reading code is just like reading books; at first, you can’t even sit through a single page but after you force yourself into reading the whole book, and then gradually develop a habit of reading books, your reading speed increases and you are able to finish a book in a single day. Same is with reading code. The more you read, the more good you become at reading code and the more better programmer you become.
Remember this paragraph from Thinking, a poem by Walter D. Wintle
Life’s battles don’t always go
To the stronger or faster man;
But sooner or later the person who wins
Is the one who thinks he can!