Friday: Standing on the Shoulders of Giants

By Adam Keys

“If I have seen a little further it is by standing on the shoulders of Giants.” -Isaac Newton

“Borrow strength from demonstrated excellence..don’t get it original, get it right.” -Edward Tufte

why stand on shoulders

  • to see further
  • read the music, listen the music, perform the music
  • control your destiny
    • Programmers spend 5 times more effort to read the code than write it.
  • we all write legacy code
  • protect yourself from yourself, five days ago
  • you’re surrounded by idiots

why is reading code hard?

  • languages that aren’t ruby
  • unfamiliar idioms
  • code written by non-heroes

tips for reading code

  • entry points and hooks
  • use tools like find and grep
  • don’t chase rabbits into their holes
  • navigating the call stack
  • find in project
  • don’t go chasing waterfalls
  • method missing

beast (an example of a readable project)

He talked through how to track stuff down in rails. Showed navigating from routes to controller to view to controller to model to find where things are happening.

adam’s rails spelunking recipe

  • look at url, cross reference with routes.rb
  • check out the controller or skip directly to the view
  • grok any controller filters
  • grok the controller action
  • grok any methods in action calls
  • check the template and any helpers it might use

the spelunking preface

  • filters defined in application controller or helpers in application helper
  • observers, validations, callbacks, etc. defined in models
  • code in lib or plugins

Demonstrated how to dig through an old school ruby lib. Used rake as an example and how rake creates a dsl using ruby’s built in stuff.

Going through acts_as_versioned and showing how he looks through plugin code to figure out what is happening.

  • class_eval to manipulate class at runtime
  • const_get and const_set to get class and modules

0 Comments

Sorry, comments are closed for this article to ease the burden of pruning spam.

About

Authored by John Nunemaker (Noo-neh-maker), a programmer who has fallen deeply in love with Ruby. Learn More.

Projects

Flipper
Release your software more often with fewer problems.
Flip your features.