Reading Code

I spent a fair amount of time this week reading other people's code. With releasing the Rails Query Stats plugin, I wanted to learn how other plugins are written so I could be sure to write plugin code the "best" way. While I learned quite a bit about how Modules work in Ruby, I learned many new things on top of that. At first I was concerned with knowing if the code I was reading was "good" code or not. However, it didn't take long until I could recognize this (I started by reading plugin code written by Rails Core members). Reading poorly written code also helps initiate "what would be a better way to do that?" thinking. Just as reading a book can increase vocabulary by coming across words you don't know, reading code helps increase programming vocabulary. Although sifting through documentation can also help, reading code is much more enjoyable, and seeing actual implementations of methods helps more than just reading about a method. It's like the difference between reading about how to do something and actually doing it. Writing a plugin is a great way to learn more, and reading (and understanding) other people's code is a great exercise.

Side note: I had to make a couple bug fixes to Query Stats today, so if you downloaded it yesterday, please update from svn.