<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>has_many :thoughts: Reading code</title>
    <link>http://blog.kineticweb.com/articles/2007/05/18/reading-code</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Musings from a Ruby on Rails development team</description>
    <item>
      <title>Reading code</title>
      <description>&lt;p&gt;Believe it or not there was actually a talk about how to read code. There&amp;#8217;s more to it then I realized and there were some interesting handy tips presented, although there wasn&amp;#8217;t as much actual substance to this talk as I had envisioned. Here&amp;#8217;s some tips:&lt;/p&gt;


	&lt;p&gt;When reading ruby or Rails code beginners often might not even know where to start. Here&amp;#8217;s a pretty good track to follow:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Read the &lt;span class="caps"&gt;URL&lt;/span&gt; of the page in question. In simple apps that aren&amp;#8217;t using fancy routes, the &lt;span class="caps"&gt;URL&lt;/span&gt; will tell you the action/controller.&lt;/li&gt;
		&lt;li&gt;Check out the routes.rb file for any fancy route configurations to find the controller/action.&lt;/li&gt;
		&lt;li&gt;Open the controller and find the method. Read through it.&lt;/li&gt;
		&lt;li&gt;Look for any filters on the controller. Usually declared at the top. Find them and see if there is stuff running before or after your method.&lt;/li&gt;
		&lt;li&gt;See what methods on the model are invoked and read through the model method.&lt;/li&gt;
		&lt;li&gt;Look for callbacks on the model. Stuff like before_create can add functionality that you might not have realized was there.&lt;/li&gt;
		&lt;li&gt;Application controller and application helper files often contain other stuff you should look through before doing any spelunking.&lt;/li&gt;
		&lt;li&gt;Seek out observers. Often declared in environment.rb and residing in the models folder, these are callbacks that often attach themselves to multiple models.&lt;/li&gt;
		&lt;li&gt;Plugins and libraries in /lib are good to look at, too.&lt;/li&gt;
	&lt;/ol&gt;


Some other tidbits about finding the method you&amp;#8217;re looking for:
	&lt;ol&gt;
	&lt;li&gt;Check for normally defined methods&lt;/li&gt;
		&lt;li&gt;Find any method_missing implementation&lt;/li&gt;
		&lt;li&gt;Grep through files for any metaprogramming like define_method.&lt;/li&gt;
	&lt;/ol&gt;</description>
      <pubDate>Fri, 18 May 2007 19:12:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:6280eb26-4bc8-4f0c-ae90-cdbd95ef7ed2</guid>
      <author>Colin A. Bartlett</author>
      <link>http://blog.kineticweb.com/articles/2007/05/18/reading-code</link>
      <category>Rails</category>
      <category>ruby</category>
      <category>RailsConf</category>
      <category>RailsConf07</category>
    </item>
  </channel>
</rss>
