Standing on the shoulders of giants
|
|
Anthony reminded me to post more information about the code reading talk that I went to at RailsConf ‘07. The name of the talk was “Standing on the shoulders of giants”, by Adam Keys. The talk was one of the best that I went to there, but of course that means that the slides by themselves aren’t particularly helpful (although they are funny sometimes). Here’s his blog post about the talk: http://mvm.therealadam.com/articles/2007/05/23/... and here’s a PDF of the slides: http://therealadam.com/presentations/standing_o… To summarize, here are the projects that he recommends as outstanding examples of Ruby and Rails programming, along with my notes from the talk:
When trying to track down behavior, look at the URL, and then use config/routes.rb to find the controller. Then grok the controller filters. Then grok the controller actions. Then start to grok the methods and models called by the actions. Pre-reading homework on a new application:
For workflow, when you find a method to investigate while reading code, use your editor to leave a bookmark there, then go “dive down the rabbit hole” and then use the bookmark to pop back up again so that you can come back to where you were. When trying to figure out method declaration and dispatch, there are a few possibilities for how something could have been implemented:
Don’t forget about the Ruby magic global variable $_, which some methods use if they’re not supplied with an argument (e.g. shift). This isn’t used very frequently, but you’ll see it sometimes, and it’s confusing when you have methods that seem to be operating on nothing. It’s used in Dwemthy’s Array, for example. Make sure you read Err the Blog, and The Rails Way (they’re both in the feeds that I posted earlier). Check out activesupport in the rails source code (under /usr/lib/ruby/gems/1.8/gems/activesupport…) for many tiny examples of extending the Ruby language. This is where they define things that let you say things like:
The last one would return all of the comments from the first person, sorted by creation time. The activesupport addition is the “&:” notation, also called “symbol to proc”. Be sure to post when you find something really cool, or really confusing! |