<?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>8th Light Blog: Want clean code?  Stop using the editor.</title>
    <link>http://blog.8thlight.com/articles/2007/12/21/want-clean-code-stop-using-the-editor</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>In the minds of the craftsmen...</description>
    <item>
      <title>Want clean code?  Stop using the editor.</title>
      <description>&lt;p&gt;Recently I was adding some accessors to a ruby class on the fly, and I kept getting confused by this block:&lt;/p&gt;

&lt;pre&gt;
eval &lt;&lt;-EOF
def #{mode.underscore.gsub(' ', '_')}
  return self.additional_fields[:payment_modes]["#{mode.underscore.gsub(' ', '_')}".to_sym]
end
EOF
&lt;/pre&gt;

&lt;p&gt;The code isn&amp;#8217;t particularly complicated, just creating a quick accessor to get at the underlying hash.  Yet I had a couple bugs simply because without the editor to give me hints, the code was that much harder to follow.  This turns out to be a blessing in disguise, as I am forced to write extremely clean code just to keep from confusing myself.   Opening up the String class cleans this up a bit, and removes duplication:&lt;/p&gt;

&lt;pre&gt;
eval &lt;&lt;-EOF
def #{mode.rubify}
  return self.additional_fields[:payment_modes]["#{mode.rubify}".to_sym]
end
EOF
&lt;/pre&gt;

&lt;p&gt;There much better.  So the next time you think your code isn&amp;#8217;t as clear as it could be, or maybe if you think it&amp;#8217;s perfect, try reading it without any syntax highlighting.  If you can still follow it quickly and easily, then maybe it doesn&amp;#8217;t entirely suck.&lt;/p&gt;</description>
      <pubDate>Fri, 21 Dec 2007 23:19:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:2770959d-7f10-4fb9-b778-422ba637d6f1</guid>
      <author>Eric</author>
      <link>http://blog.8thlight.com/articles/2007/12/21/want-clean-code-stop-using-the-editor</link>
      <category>Coding</category>
      <category>Eric</category>
    </item>
    <item>
      <title>"Want clean code?  Stop using the editor." by Matt S Trout</title>
      <description>&lt;p&gt;I&amp;#8217;m not sure I understand why you need string eval for this - in perl I&amp;#8217;d be writing something like&lt;/p&gt;

&lt;pre&gt;
*{$mangled_mode} = sub {
  my $self = shift;
  $self-&gt;additional_fields
          -&gt;{payment_modes}
          -&gt;{$mangled_mode};
};
&lt;/pre&gt;

&lt;p&gt;and the $mangled_mode variable would be lexically captured by the sub {} block - can&amp;#8217;t you use a similar closure trick to clean up the ruby?&lt;/p&gt;</description>
      <pubDate>Tue, 25 Dec 2007 01:26:15 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:4cf30994-ba0d-4c89-8107-1c71ab6db839</guid>
      <link>http://blog.8thlight.com/articles/2007/12/21/want-clean-code-stop-using-the-editor#comment-466</link>
    </item>
  </channel>
</rss>
