Amidst all the articles that pops up when you subscribe to hacker news telegram channel, this was one of the many that caught my eye.
Liken reading code to be like the journey where you learn how to read before you start writing. As you learn to read, you create new ideas on your expression of words and ideas; While all words strives to convey a message, some structures are more appropriate and easier to comprehend than others.
Much as we can train ourselves to read books more quickly, we can get quicker at reading and comprehending software code.
By first reading words in context, you begin to understand their meaning and appropriate use.
Hard to read code is hard to maintain and can impede the development process. Just as in language, where a poorly constructed paragraph can be confusing and difficult to absorb, code can suffer the same fate. And just as we are equally culpable to writing bad illegible code, learning to write more code can also help improve our writing skills to avoid producing illegible code
Learn from someone else’ mistake saves you a multitude of stumble.
As you seek to improve your own skill, regularly expose yourself to new code is part of a healthy continuous learning cycle. You don’t have to agree with the code for the reading of it to be beneficial. Reading “bad” code can be hugely influential and informative. As you read, you are exposed to different styles of writing - some bad, some are better. Through this process, you find out what you do not like, and wish to avoid in your own writing as well.
You can choose to write code that you are familiar with, you can improve your ‘technical vocabulary’ and your understanding of the mechanics in the libraries you utilise on a daily basis - which is a double win! Similarly, you can also choose to read source code of a different language as how you learning a second or third language has its benefits in communicating with people of different language expertise.
Every code language encapsulate different coding principles, some languages more so than other principles. One other benefit in your attempt to read and understand another code language through reading source code, you find yourself exposed to new principles that are either strictly enforced by its syntax such as Java with their types, or Ruby with their functional programming structure. Either way, as you continue to expose yourself to the unknown, you get to see more; Understand more, and thereupon improve your ability to ‘see’ seemingly confusing pieces of code as implementations of programming constructs.
Food for thought: What are the different principles that different languages encapsulate more comprehensively?
Do not be too worried if you do not understand most of what you read. Isn’t that the intention? You are exposing yourself to new styles of writing, so you can work on your own expression of code and logic; improving your logic execution and probably instill best practices into your craft.
Every code intends to achieve particular goal. [And no, the goal is not to confuse you; Although there are pieces of code created purely for fun - these pieces of code then intend to confuse you]. As you attempt your study on any code, break down the piece of code into smaller chunks.
Run some questions through your own thinking process to facilitate the learning process.
- Why is the code written in this way? What principles does it seek to follow?
- Has the author used an approach in which was not previously considered?
- Has the author used new syntax? Check out the new documentation. Remember your goal is to increase your exposure to new code style and new implementations so you can sharpen your craft
The higher abstracted take-home lesson is to set yourself up for learning. If the goal is to improve your coding ability to produce good, readable, efficient code, source code reading is merely one of many approaches to learn. There are other ways which may include article reading, pair programming (getting your hands dirty), and/or you attempting to just build a product with these new coding practices.
TDLR: do not confine your learning within the boundaries of work. Learning is a lifestyle, that will produce dividends down the road.
Here’s something for you to watch!
Here’s a youtube video about reading source code. Its quite dated but i think it can be quite interesting to see how people actually teaches you how to read code. I guess a lot of insights and thought processes can be unveiled through the way we write; In this case, it is in the way we write our code. Fundamentally, code is merely just words that helps encapsulate logic. Good code helps you to see the logic behind plainly and clearly.