Tuesday, October 13, 2015

Why YOU Need to Read Other People's Code

Take a moment to sit back in your chair and think over the past week. How much coding did you do? And of that, how much was actual greenfield development? How much of your past week involved you working with code that was written by someone else or even by yourself but over six months ago (let's face it, if it was written by you six months ago, then it might as well have been written by another person!)?

I believe it's pretty obvious to say that there is more code out there in production than there is being created. What this means is that there's a lot more code that needs to be maintained on a daily basis than there is being created anew. An enterprise developer might get the opportunity to work on something new, but it is more than likely to be a new feature for an existing application. The constraints and API of the current application will determine the architecture of this new feature and this will be determined from either good documentation (how many places have that?) or reading code.

I frequently hear "I'm not sure how that works. I'll have to go through the code" or something similar at where I work. I feel that more time is spent reading code written by another than is actually writing code. If such a large amount of our working day is spent reading code, shouldn't we look to devote some of our "sharpening the saw" time to developing our skill to do this? Writing code is easy but reading code is harder because you have no idea what the programmer was thinking at the time they wrote it! Spending some time sharpening your skills in this area would be both beneficial to yourself and your team.

There are also other benefits from reading code that was written by someone else than you:
  • You get to see how someone else approached a problem: this insight could help you the next time you face a similar problem
  • You will more than likely learn something: we don't know everything so this could be something to do with the programming language, framework, business domain, or coding style of the author.
  • Reading other people's code will make you more aware that someone else might read your code in the future
Where to go from here?

With open source, it couldn't be easier to start reading code written by someone else. There is lot of code out there (both good and bad) so it shouldn't be hard to find a project that interests you. Jumping straight into the Angular code base probably isn't the best place to start and I would recommend starting with a something smaller that aims to solve a very simple and narrow problem. 

Something to keep in mind is just because you don't understand the code, that doesn't necessarily mean the author is smarter than you so don't let this discourage you! A section of difficult to understand code is a potential opportunity to refactor. I doubt you are alone so making it easier to understand would be a great way to contribute to the project.

And remember the next time you start writing some code, it's probably going to be someone else who is going to have to maintain it!

//Code, rinse and repeat