The Fear of Reading Code
By Adrian Sutton
From yield thought – On The Fear of Reading Code:
When I was learning to program someone told me that I should try to read as much code as possible. Budding genius that I was, I thought this was advice for stupid people who needed to learn from their betters. I thought the only reason to read code was to pick up tricks from it.
How wrong I was. The real reason to read code has nothing to do with learning from the programmer who wrote it.
Far too many programmers fail to take the time to read and understand other people’s code and it’s a great loss. Much like history, if you don’t take the time to read and truly understand other people’s code, you’re doomed to repeat their mistakes. It’s not just learning from old code either, sometimes that old messy, “unmaintainable” code, is actually just battle hardened and bug-free. As the referenced post mentions, it’s all too common for developers to find a bug in someone else’s code, not really read and understand the code and decide to reimplement.
It’s only after years and years of repeating this pattern that it has begun to dawn on me that each time I do this I’m really just wasting precious, precious time on something that doesn’t improve the product at all. What’s worse, I’m only doing it because I can’t face the thought of reading somebody else’s code. If I spent one fraction of the time reading and understanding it then I’d learn a lot more about the problem it’s trying to solve and would be in a great place to tweak or refactor it to suit my needs. So perhaps the next time you want to improve your coding skills, try taking someone else’s code and improving it in some way. You’ll learn far more from doing that than from any new code you might write.