I'm Reading Source Code to be a Better Developer

When I heard about Ruby and Rails a couple of years ago, I looked at a couple of books on the subject and promptly bought them. I spent a couple of hours a week  trying out things with Ruby and building a couple of applications using Rails. As informative as these books were, I always felt as if I was still missing something.

The problem was that books could only tell you so much. Books often give you basic code to learn the feature of a language or framework. This isn't a bad thing, but I wanted to progress more. I wanted to move from just having beginner Ruby code to a higher level.

In order to achieve a higher level of understanding Ruby (and Rails and Sinatra too!), I have started to read the code of other Ruby applications out there. Having spent enough time following developers in the community through RSS feeds and Twitter, I'm informed enough to make a decision on what source code would make interesting reading.

For this month I have been looking at the retweet application on Github by Nick Plante. Retweet is an application template for building simple Twitter applications. 

It's a fully featured Sinatra application from a developers point of view with rake tasks and specs. For myself this is great because I have failed in the past with rake tasks for my Sinatra applications and having looked through the source code for retweet, I now understand where I went wrong and how to correctly implement rake tasks.

Now, before you go off and start reading through the source code of projects yourself, remember this:

Reading source code isn't about just looking at the code and saying "I'll have that!"

Reading source code means that you have to understand what the code is doing. You can do a couple of things to understand what the code is doing:
  1. Put your own comments in the code - Start with a class in your chosen project and start from there. When you've read through some code and understand how it works, stick some comments in it to remind yourself of what it does. You'll then have some notes that you can refer back to when your reading further code from your chosen project.
  2. Write some tests - In order to gain a further understanding of the source code your reading, write some tests for it. We all (I hope) use tests to ensure our applications are working correctly, but tests are also a great way of understanding how code works without having to run the whole application.
I'm going to continue with this exercise once a month, alternating between a Sinatra application and a Rails application. At the end of each month, I'll do a small summary post of interesting things I have found within each project. Hopefully this will lead to me having a better level of knowledge of Ruby and also allow me to write better code.

Filed Under // Programming