yield the dog

The Lost Art of Reading Source Code

| Comments

In my old programming days reading source code of libraries that I used was often a hard task. Either the code was closed source or only in binary format.

Today we live in a world in which programmers like to share their code and have the tools to do so. We could not be more lucky. To solve a certain task we can choose from many different solutions that may vary in quality and functionality. If one does not fit the purpose we just use the next one.

When unsolvable problems arise

Most open source solutions have a solid documentation, otherwise they could not compete with the high standard. Still from times to times I am confronted with problems that are not covered in the documentation and can not be solved with the help of Google. Sometimes a colleague asks me a question, sometimes I find a question on StackOverflow with a problem that the person was not able to solve.

When such a problem arises I like to open the library and dig in the source code. I have found many solutions by reading and debugging the code of a library (even of libraries I did not use or know until then). It’s fantastic. You find yourself in a different, uncomfortable zone and can learn so much by just reading. You can uncover hidden gems or APIs inside your library that where not supposed to be directly visible for the public, or you can find details that are missing in the documentation. In the latter case it should be a good coder’s duty to help and update the documentation. And you can learn how others try to solve problems which may give you new perspectives.

But, you can also get terrified by what you are looking at. It happens rather rarely to me. Once in a while I trip over code that is a mess, is horrible to read or debug, or was just written by an unskilled person. Do not get me wrong here. I have deep respect for everyone who is open sourcing a project, but I do not want to use code that is below my standards. I appreciate these moments, because they help me to form an environment in which I can develop at a steady pace. I do not want to get stuck because of library code.

What you need to start

Nothing, you do not need anything but curiosity. That’s the fun part. Most stable open source projects have a fantastic code base that is easy to understand and read. In my opinion this has a rather simple reason: If they do not care for code quality, they soon suffer a painful death in the vicious circle of unmanageable code.

You do not need to understand the whole thing at once but most projects have modules or other encapsulated logic that makes it easy to understand a part of the whole.

So what are you waiting for? Head over to the Github and check out some of those great projects. And the next time you are stuck within a library or framework crack it open and look under the hood.

Want to recommend a good code read? Just leave a comment!

Comments