<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">

<channel>
	<title>Kyle Banker</title>
	
	<link>http://kylebanker.com/blog</link>
	<description />
	<pubDate>Thu, 16 Oct 2008 03:29:36 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/KyleBanker" type="application/rss+xml" /><item>
		<title>Design-Build Development</title>
		<link>http://kylebanker.com/blog/2008/10/design-build-development/</link>
		<comments>http://kylebanker.com/blog/2008/10/design-build-development/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 16:35:55 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
		
		<category><![CDATA[The Big Picture]]></category>

		<category><![CDATA[bdd]]></category>

		<category><![CDATA[dbd]]></category>

		<category><![CDATA[design-build development]]></category>

		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://kylebanker.com/blog/?p=36</guid>
		<description><![CDATA[Explanations of BDD often contain much nuance and noise. This FAQ is an attempt to provide a straightforward account of BDD. To do so, it tries to work around the three biggest obstacles to understanding BDD: the main emphasis, the word "test," and the name itself.]]></description>
			<content:encoded><![CDATA[<p><em>Explanations of BDD often contain much nuance and noise. This FAQ is an attempt to provide a straightforward account of BDD. To do so, it tries to work around the three biggest obstacles to understanding BDD: the main emphasis, the word &#8220;test,&#8221; and the name itself.</em></p>
<h5>1.) I&#8217;ve never fully grasped Behavior-Driven Development.  Many highly nuanced descriptions of BDD exist, but none is straightforward.  What&#8217;s the main idea?</h5>
<p>BDD ain&#8217;t easy. But there&#8217;s a good way to hack the learning curve; adopt the following two axioms:</p>
<ol>
<li><strong>BDD is not testing</strong>. Anyone who wants to understand and practive BDD must forget all notions of testing. This can be a challenge since we use the word &#8220;test&#8221; so frequently in reference to BDD (e.g, &#8220;test suite,&#8221; &#8220;test coverage&#8221; etc.). But the word &#8220;test&#8221; puts us in the wrong frame of mind.  This is because:</li>
<li><strong>BDD is a design process</strong>. When practiced correctly, BDD helps developers design a system, from the classes and their interactions down to individual methods and their behaviors. This is what is meant by Behavior-Driven Development. The developer makes decisions about a particular class interface, for example, and then implements.</li>
</ol>
<p>So, again, to begin to understand BDD, first eliminate any reference to testing lingering in your mind. Then, meditate. Here&#8217;s your mantra:</p>
<p><strong>BDD is a design process</strong>.</p>
<h5>2.) But I still find the words &#8220;Behavior-Driven Development&#8221; misleading. I keep thinking of &#8220;Test-Driven Development,&#8221; and, as you say, I should stop thinking about testing.</h5>
<p>Yes, it seems that the words &#8220;Behavior-Driven Development&#8221; have meaning only for the initiated. Let&#8217;s use another term altogether, at least for the remainder of this FAQ. We&#8217;ll call this design process <strong>Design-Build Development</strong>. It keeps the mind on track. First design, then build.</p>
<h5>3.) Ok, so what&#8217;s Design-Build Development?</h5>
<p>Design-Build Development is an iterative four-step design-build-verify process.</p>
<p><strong>Step 1: Design </strong></p>
<p>Using a design-build framework (e.g., <em>RSpec</em>, <em>Shoulda</em>), specify how a some bit of code should behave.</p>
<p>For example, suppose I&#8217;m building a web crawler. I have a <em>Cralwer</em> class, which is somewhat fleshed out, and an <em>Indexer</em> class, which I&#8217;ve yet to work on. The important thing to notice is that as I specify behavior,  I&#8217;m deciding how the crawler will interface with the indexer.  Here&#8217;s my specification (using <em>Shoulda</em>):</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;">context <span class="st0">&quot;A crawler opening a url&quot;</span> <span class="kw1">do</span><br />
&nbsp; setup <span class="kw1">do</span><br />
&nbsp; &nbsp; <span class="re1">@crawler</span> = Crawler.<span class="me1">new</span><span class="br0">&#40;</span>Indexer.<span class="me1">new</span><span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">end</span><br />
<br />
&nbsp; should <span class="st0">&quot;return add the url to the index&quot;</span> <span class="kw1">do</span><br />
&nbsp; &nbsp; <span class="re1">@indexer</span>.<span class="me1">expects</span><span class="br0">&#40;</span><span class="re3">:add_url</span><span class="br0">&#41;</span>.<span class="me1">returns</span><span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="re1">@crawler</span>.<span class="me1">start</span><span class="br0">&#40;</span><span class="st0">'http://sitetoindex.com'</span><span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></div></div>
<p>I mock the method <em>add_url</em> on the indexer. So my thought process is something like, &#8220;Well, let&#8217;s say that we&#8217;ll build a method on the indexer for adding urls. We&#8217;ll call it <em>add_url</em>, and it&#8217;ll return <em>true</em> if the operation is successful.&#8221;</p>
<p><strong>The benefit here is that I get to decide how the <em>Indexer</em> class will behave even before I&#8217;ve written any <em>Indexer</em></strong> <strong>code!</strong></p>
<p><strong>Step 2: Run the design verifier.</strong></p>
<p>I run the design verifier (a.k.a tests) and receive an error saying that @indexer did not receive &#8220;add_url.&#8221;</p>
<p><strong>Step 3: Build</strong></p>
<p>Now, I write the code that satisfies my specification (Note: highly oversimplified).</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">class</span> Crawler<br />
&nbsp; <span class="kw1">def</span> start<span class="br0">&#40;</span>url<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="kw3">open</span><span class="br0">&#40;</span>url<span class="br0">&#41;</span> &amp;&amp; <span class="re1">@indexer</span>.<span class="me1">add_url</span><span class="br0">&#40;</span>url<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">puts</span> <span class="st0">&quot;#{url} successfully indexed.&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></div></div>
<p><strong>Step 4: Verify</strong></p>
<p>I run the verifier again. Now that I&#8217;ve added &#8220;@indexer.add_url&#8221;, I don&#8217;t receive any errors.</p>
<p>By running the verifier, I assure myself that the code conforms to the design.</p>
<p>Then I go back to <em>Step 1</em>,  continuing the design-build process.</p>
<h5>4.) What&#8217;s a design framework?</h5>
<p>Examples include <em>RSpec</em>, <em>Shoulda</em>, <em>Test/Spec</em>, and many others.  A design framework allows the programmer to translate her design into code. It&#8217;s what most of us call a testing framework. But in the case of BDD and DBD, we want to eradicate any reference to testing. Therefore, we call it a design framework.</p>
<h5>5.) So, Design-Build Development doesn&#8217;t require a special framework?</h5>
<p>Not at all. Because DBD is a reframing of BDD, any of the BDD tools can be used to do DBD.</p>
<h5>6.) Why is it important to avoid the word &#8220;test&#8221; when thinking about BDD and DBD?</h5>
<p>Design-Build Development is first, and foremost, a <strong>design process</strong>. When engaging in DBD, we are specifying the design and behavior of code. This must not be confused with writing tests. <strong>To use the word &#8220;test&#8221; is to shift the mindset from &#8220;design, then build&#8221; to &#8220;build, then test.&#8221;</strong></p>
<p>The design mindset says, &#8220;I&#8217;m crafting this system. I&#8217;m creating classes and deciding how they interface with each other. As I design, I implement my specifications little by little.&#8221;</p>
<p>The test mindset says, &#8220;I just wrote a bunch of code; now I&#8217;m gonna write some tests to make sure that everything works like I think it should.&#8221;</p>
<p>In the first case, the mind wields the power; in the second, it&#8217;s the code that rules.  The test mindset puts us at the mercy of the codebase.<br />
<strong><br />
</strong></p>
<h5><strong> </strong>7.) I see. Design-Build Development values the programmer&#8217;s intentions over the whims of a codebase.</h5>
<p>Exactly. Design-Build Development is an intentional approach to writing code. It elevates our frame of mind, focusing our energies on one chunk of the system at a time.</p>
<p>Design-Build Development seeks to counteract what the Pragmatic Programmers call &#8220;programming by coincidence.&#8221; In the worst case, this means unreflectively writing code for weeks on end until we&#8217;ve created a monster.  Once the monster is born, our coding degenerates into a series reactive strategies to keep it in check. Tweak here, bug fix there. Anything to keep the codebase happy (and working).</p>
<p>Programming by coincidence engenders chaos in the mind. Design-build development, by contrast, encourages focus.<br />
<strong><br />
</strong></p>
<h5><strong> </strong>8.) What are some other benefits of Design-Build Development?</h5>
<p>Practicing Design-Build Development, we slowly build up <strong>a wall of [specifications] that cannot break without our immediately knowing about it</strong>&#8221; (paraphrase of Ruby Test::Unit docs). This inspires confidence; it assures us that future changes to the system don&#8217;t break the behavior of any other part of the system.</p>
<p>At the same time, the design-build process produces <strong>a specification of our system in code</strong>, so we get <strong>documentation for free</strong>.</p>
<h5>9.) Why do we need yet another conceptualization of xDD?</h5>
<p>Those who already understand BDD don&#8217;t need this FAQ. My hope is simply that anyone who hasn&#8217;t internalized BDD will gain some insight from the ideas presented here.</p>
<p>There are <strong>three obstacles</strong> preventing a wider adoption and understanding of Behavior-Driven Development:</p>
<ol>
<li><em>Emphasis</em>. BDD is a design process. This is the fundamental insight, but it&#8217;s rarely emphasized.</li>
<li><em>Testing</em>. BDD connotes testing. But this works against (1), that BDD is all about designing a system. The testing mindset and the design mindset do not peacably coexist.</li>
<li><em>Naming</em>. BDD sounds like TDD, and the words &#8220;Behavior-Driven Development&#8221; are not sufficiently precise. I believe that the term &#8220;Design-Build Development&#8221; more accurately indicates what BDD is. These words are a better starting point for the BDD novice.</li>
</ol>
<p>If we introduce BDD as <em>Design-Build Development</em> and then emphasize the value of thinking of BDD in terms of a design process (and not as testing), I believe we can effectively lower the barriers to adoption and understanding.</p>
<h5>10.) Where can I read more?</h5>
<p>For an essay on the importance of thinking in terms of design, read Paul Graham&#8217;s<a href="http://www.paulgraham.com/taste.html"> &#8220;Taste for Makers.&#8221;</a></p>
<p>For a great discussion on the BDD learning process, read the <a href="http://behaviour-driven.org/Introduction">Introduction to Behavior-Driven Development</a> at behavior-driven.org.</p>
]]></content:encoded>
			<wfw:commentRss>http://kylebanker.com/blog/2008/10/design-build-development/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Shoulda Testing Cheat Sheet</title>
		<link>http://kylebanker.com/blog/2008/09/shoulda-testing-cheat-sheet/</link>
		<comments>http://kylebanker.com/blog/2008/09/shoulda-testing-cheat-sheet/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 16:05:08 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Testing]]></category>

		<category><![CDATA[testing rails shoulda]]></category>

		<guid isPermaLink="false">http://kylebanker.com/blog/?p=29</guid>
		<description><![CDATA[Updated 10/1/08: Modified for the release of Shoulda 2.0.
Updated 9/26/08: Fixed some typos and omissions.  Added should_route and should_render_with_layout (Thanks to Dan Croak and Michal Szajbe).
I&#8217;ve created a basic Shoulda cheat sheet.  Along with Topfunky&#8217;s Ruby on Rails Testing Cheat Sheet, it should be a good reference, especially for those migrating from RSpec.
]]></description>
			<content:encoded><![CDATA[<p><strong>Updated 10/1/08: </strong><em>Modified for the release of Shoulda 2.0.</em></p>
<p><strong>Updated 9/26/08:</strong> <em>Fixed some typos and omissions.  Added <strong>should_route</strong> and <strong>should_render_with_layout</strong> (Thanks to Dan Croak and Michal Szajbe</em><em><cite></cite>).</em></p>
<p>I&#8217;ve created a basic Shoulda cheat sheet.  Along with Topfunky&#8217;s <a href="http://nubyonrails.com/articles/ruby-rails-test-rails-cheat-sheet">Ruby on Rails Testing Cheat Sheet</a>, it should be a good reference, especially for those migrating from RSpec.</p>
<div id="attachment_30" class="wp-caption alignnone" style="width: 310px"><a href="http://kylebanker.com/blog/wp-content/uploads/2008/09/shoulda_cheat_sheet.pdf"><img class="size-medium wp-image-30" title="shoulda_cheat_sheet" src="http://kylebanker.com/blog/wp-content/uploads/2008/09/shoulda_cheat_sheet-300x232.jpg" alt="Shoulda Cheat Sheet" width="300" height="232" /></a><p class="wp-caption-text">Shoulda Cheat Sheet</p></div>
]]></content:encoded>
			<wfw:commentRss>http://kylebanker.com/blog/2008/09/shoulda-testing-cheat-sheet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Uniting</title>
		<link>http://kylebanker.com/blog/2008/08/uniting/</link>
		<comments>http://kylebanker.com/blog/2008/08/uniting/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 03:01:20 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
		
		<category><![CDATA[The Big Picture]]></category>

		<category><![CDATA[philosophy engineering design]]></category>

		<guid isPermaLink="false">http://kylebanker.com/blog/?p=19</guid>
		<description><![CDATA[Engineers and designers must collaborate. Whether building a bridge, a commercial jet, or a web application, the most elegant solution will result from an open dialog between design and engineering. Apple understands this. So does Boeing, with its notion of the design/build team.&#160; This sort of cooperation will always be important.&#160; Big Contrarian recently wrote [...]]]></description>
			<content:encoded><![CDATA[<p>Engineers and designers must collaborate. Whether building a bridge, a commercial jet, or a web application, the most elegant solution will result from an open dialog between design and engineering. <a mce_href="http://www.businessweek.com/the_thread/techbeat/archives/2008/03/apples_design_p.html?campaign_id=rss_blog_techbeat" href="http://www.businessweek.com/the_thread/techbeat/archives/2008/03/apples_design_p.html?campaign_id=rss_blog_techbeat">Apple</a> understands this. So does <a mce_href="http://bits.me.berkeley.edu/mmcs/b777/design_build.shtml" href="http://bits.me.berkeley.edu/mmcs/b777/design_build.shtml">Boeing</a>, with its notion of the design/build team.&nbsp; This sort of cooperation will always be important.&nbsp; <a mce_href="http://www.bigcontrarian.com/" href="http://www.bigcontrarian.com/">Big Contrarian</a> <a mce_href="http://www.bigcontrarian.com/2008/08/12/the-great-divide/" href="http://www.bigcontrarian.com/2008/08/12/the-great-divide/">recently wrote</a> about the fallacy of thinking otherwise:</p>
<blockquote><p>Designers running free, creating without concern for the production is nonviable. Designs can become hinged to interactions that will not work, with the compromised result damaged to the point of mediocrity.  Engineers paving the way is just as fruitless. Solutions will lack elegance and beauty. A utilitarian wonderland of marginal design with exquisite engines. Volvo-world.</p>
</blockquote>
<p>To see engineering as divorced from design is to fall prey to an even greater fallacy: that design and engineering are entirely separate disciplines.&nbsp; It is tempting to think of the engineer as mere implementer, as one who mechanically applies the laws of physics to make a design reality.&nbsp; Many also find it convenient to assign all creative control to the designer, as if engineers were somehow devoid of creativity.</p>
<p>This kind of thinking quickly crumbles once we reflect for a moment on elegance.&nbsp; Elegance, as <a mce_href="http://www.amazon.com/Machine-Beauty-Elegance-Technology-Masterminds/dp/046504316X" href="http://www.amazon.com/Machine-Beauty-Elegance-Technology-Masterminds/dp/046504316X">David Gelernter</a> defines it, is the combination of simplicity and power.&nbsp; The human mind, with its innate aesthetic sensibilities, quickly apprehends elegance, and that is why we love Velcro, the iPhone, suspension bridges, object-oriented programming, and the jet engine.</p>
<div class="mceTemp mceIEcenter">
<dl id="attachment_23" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://kylebanker.com/blog/wp-content/uploads/2008/08/velcro.gif" mce_href="http://kylebanker.com/blog/wp-content/uploads/2008/08/velcro.gif"><img src="http://kylebanker.com/blog/wp-content/uploads/2008/08/velcro-300x237.gif" mce_src="http://kylebanker.com/blog/wp-content/uploads/2008/08/velcro-300x237.gif" alt="Velcro" title="velcro" class="size-medium wp-image-23" width="300" height="237"></a></dt>
<dd class="wp-caption-dd">Velcro</dd>
</dl>
</div>
<p>But its not <i>just</i> simplicity and power. These inventions are elegant because, in their design, they fit snugly within the jagged spaces between the laws of the physical world and the modes of human being.&nbsp; Put more colloquially, they are effective and user-friendly.</p>
<p>It should be immediately obvious that cooperation between engineers and designers is only the <i>minimum</i> requirement for such elegance.&nbsp; Even better would be engineers who read Shakespeare and designers who study physics: engineer-designers, as it were.&nbsp; For without creativity, engineers cannot produce elegant solutions.&nbsp; And lacking knowledge of the physical world, designers work against nature.&nbsp; </p>
<p>The ideal, then, is a sort of Leonardo da Vinci, the Renaissance man with a sense for beauty and mystery and a keen understanding of process and physical law.&nbsp; For engineering and design are much more intertwined than they appear.</p>
]]></content:encoded>
			<wfw:commentRss>http://kylebanker.com/blog/2008/08/uniting/feed/</wfw:commentRss>
		</item>
		<item>
		<title>From RSpec to Shoulda</title>
		<link>http://kylebanker.com/blog/2008/08/from-rspec-to-shoulda/</link>
		<comments>http://kylebanker.com/blog/2008/08/from-rspec-to-shoulda/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 04:22:25 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Testing]]></category>

		<category><![CDATA[ruby rails]]></category>

		<guid isPermaLink="false">http://kylebanker.com/blog/?p=14</guid>
		<description><![CDATA[Shoulda
What&#8217;s the best Rails testing framework? The one that makes your testing life most enjoyable, of course.  For me, this has been RSpec, but I&#8217;m beginning to prefer Shoulda.
Shoulda provides an elegant DSL for doing Behavior-Driven Development in Test::Unit.  In addition, Shoulda includes macros for many common tasks in unit and functional tests. Thoughtbot, the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Shoulda</strong><br />
What&#8217;s the best Rails testing framework? The one that makes your testing life most enjoyable, of course.  For me, this has been RSpec, but I&#8217;m beginning to prefer Shoulda.</p>
<p>Shoulda provides an elegant DSL for doing Behavior-Driven Development in Test::Unit.  In addition, Shoulda includes macros for many common tasks in unit and functional tests. Thoughtbot, the company behind Shoulda, has created an excellent <a href="http://thoughtbot.com/projects/shoulda/">tutorial</a>.  I also recommend Tammer Saleh&#8217;s presentation on <a href="http://mtnwestrubyconf2008.confreaks.com/12saleh.html">BDD with Shoulda</a>.</p>
<p><strong>The Trouble with RSpec</strong><br />
Part of my newfound enthusiasm for Shoulda, and Test::Unit in general, stems from a comment made by Saleh in the presentation mentioned above.  He points out that <strong>a change in the implementation of a method should not automatically cause that method&#8217;s tests to fail</strong>.</p>
<p>This was my experience with RSpec, particularly when it came to testing controllers. The RSpec controller testing philosophy favors heavy mocking.  The rationale, as I understand it, is twofold: 1) mocking isolates the testing of the controller from the model, and 2) mocking allows for the testing of a certain kind of behavior, which, in this case, seems to be the explicit expectation that certain methods will call certain objects and return certain other objects.</p>
<p>This test-the-implementation philosophy resulted in brittle tests. Slight changes to a controller method would frequently cause the tests to fail. To repair them, I would spend time tweaking my mocks and stubs so that they would fit the new implementation.</p>
<p>Sure, the religious BDD way would have me adjust my tests first. But if the behavior of the controller hasn&#8217;t changed, does it make sense to go to all the trouble? When I consider controller behavior, I think of which instance variables are populated, what&#8217;s rendered, where the controller redirects, etc. Implementation, it seems to me, is not behavior.</p>
<p><strong>Two notes</strong><br />
First, mocking is a great boon when used judiciously, even when testing controllers.  It&#8217;s beneficial to be able to mock, say, authorization methods.  But ActiveRecord models?  I&#8217;m not so sure; I&#8217;d love to hear any arguments to the contrary.</p>
<p>Second, this is not meant to write off RSpec once and for all; I mostly enjoy it, having recently completed a lengthy project using the framework.</p>
<p><strong>Conclusion</strong><br />
Shoulda&#8217;s clean syntax and time-saving macros are reason enough to check it out. Regardless of where you fall in the mocking debate, you may find Shoulda quite charming.</p>
]]></content:encoded>
			<wfw:commentRss>http://kylebanker.com/blog/2008/08/from-rspec-to-shoulda/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Thinking About Thinking</title>
		<link>http://kylebanker.com/blog/2008/07/thinking-about-thinking/</link>
		<comments>http://kylebanker.com/blog/2008/07/thinking-about-thinking/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 01:39:16 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
		
		<category><![CDATA[Books]]></category>

		<category><![CDATA[The Big Picture]]></category>

		<guid isPermaLink="false">http://blog.kylebanker.com/?p=13</guid>
		<description><![CDATA[I&#8217;m not the first to write about Matthew Frederick&#8217;s 101 Things I Learned in Architecture School. It&#8217;s a series of meditations on design, craftsmanship, and creativity.  The book itself is artfully constructed.  Every entry is accompanied by a clever illustration.  One of my favorites depicts a man thinking, with a thought bubble [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not the first to write about <a href="http://http://www.frederickdesignstudio.com/Bio/Bio.html">Matthew Frederick</a>&#8217;s <a href="http://http://www.amazon.com/101-Things-Learned-Architecture-School/dp/0262062666/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1215653360&amp;sr=8-1">101 Things I Learned in Architecture School</a>. It&#8217;s a series of meditations on design, craftsmanship, and creativity.  The book itself is artfully constructed.  Every entry is accompanied by a clever illustration.  One of my favorites depicts a man thinking, with a thought bubble containing a smaller image of the same man, thinking.  The entry reads as follows:</p>
<blockquote><p>The most effective, most creative problem solvers engage in a process of meta-thinking, or &#8220;thinking about the thinking.&#8221; Meta-thinking means that you are aware of <em>how</em> you are thinking as you are <em>doing</em> the thinking. Meta-thinkers engage in continual internal dialogue of testing, stretching, criticizing, and redirecting their thought processes.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://kylebanker.com/blog/2008/07/thinking-about-thinking/feed/</wfw:commentRss>
		</item>
		<item>
		<title>4 Principles of Object-Oriented Thinking</title>
		<link>http://kylebanker.com/blog/2008/06/4-principles-of-object-oriented-thinking/</link>
		<comments>http://kylebanker.com/blog/2008/06/4-principles-of-object-oriented-thinking/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 02:09:14 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
		
		<category><![CDATA[The Big Picture]]></category>

		<category><![CDATA[OOP]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[Smalltalk]]></category>

		<guid isPermaLink="false">http://blog.kylebanker.com/?p=12</guid>
		<description><![CDATA[Great coding is an art. As with any art, one cultivates it primarily through practice, and only incidentally through instruction and training. Painters don&#8217;t achieve greatness simply by reading books on composition and auditing lectures on technique. They have to paint. Period. Coding is no different.
Still, it doesn&#8217;t hurt to have principles to guide practice. [...]]]></description>
			<content:encoded><![CDATA[<p>Great coding is an art. As with any art, one cultivates it primarily through practice, and only incidentally through instruction and training. Painters don&#8217;t achieve greatness simply by reading books on composition and auditing lectures on technique. They have to paint. Period. Coding is no different.</p>
<p>Still, it doesn&#8217;t hurt to have principles to guide practice. I stated in my <a href="http://blog.kylebanker.com/2008/06/smalltalk-and-ruby/">last post</a> that such principles, while sparse in the Ruby literature, are readily found in the Smalltalk canon.  One example is Alec Sharp&#8217;s concise <a href="http://stephane.ducasse.free.fr/FreeBooks/ByExample/">Smalltalk By Example</a>.  This book is not a manual on Smalltalk, as the title might suggest, but more a series of meditations on good coding.  In a mere six pages, the chapter Object-Oriented Thinking conveys a number of essential principles.  Here are some of my favorites: </p>
<p><strong>1. Write Down the Concepts</strong></p>
<p>Sharp advises us to &#8220;think in conceptual terms rather than worrying about the details.&#8221;  He goes on: &#8220;Someone should be able to easily read the method to see what it&#8217;s doing (short methods, very descriptive names), without actually seeing any of the work done.&#8221; This is the same idea that Kent Beck communicates through his Composed Method pattern (from <a href="http://www.amazon.com/Smalltalk-Best-Practice-Patterns-Kent/dp/013476904X">SBPP</a>). Write methods that read like documentation:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">def</span> start_baseball_game<br />
&nbsp; sing_star_spangled_banner<br />
&nbsp; populate_infield_and_outfield<br />
&nbsp; send_batter_to_plate<br />
&nbsp; pitch<br />
<span class="kw1">end</span></div></div>
</p>
<p><strong>2. Put Off The Work</strong></p>
<p>A related principle is that methods should be short (fewer than seven lines). One way to keep methods short is to put off the work. &#8220;Smalltalk might be considered the procrastination language - procrastinate as long as possible and maybe you won&#8217;t need to do anything.&#8221;  This helps to assure that each method expresses just one concept, leading to a more object-oriented system.</p>
<p><strong>3. Tell, Don&#8217;t Ask</strong></p>
<p>If we want to write good, object-oriented code, we have to focus on sending messages. &#8220;Procedural code gets information then makes decisions. Object-oriented code tells objects to do things.&#8221; Instead of writing this:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">def</span> move<span class="br0">&#40;</span>vehicle<span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">if</span> vehicle.<span class="me1">is_a</span>?<span class="br0">&#40;</span>Car<span class="br0">&#41;</span><br />
&nbsp; &nbsp; vehicle.<span class="me1">drive</span><br />
&nbsp; <span class="kw1">elsif</span> vehicle.<span class="me1">is_a</span>?<span class="br0">&#40;</span>Helicopter<span class="br0">&#41;</span><br />
&nbsp; &nbsp; vehicle.<span class="me1">fly</span><br />
&nbsp; <span class="kw1">elsif</span> vehicle.<span class="me1">is_a</span>?<span class="br0">&#40;</span>Bicycle<span class="br0">&#41;</span><br />
&nbsp; &nbsp; vehicle.<span class="me1">pedal</span><br />
&nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></div></div>
<p>We simply write:</p>
<div class="codecolorer-container ruby" style="height:35px;"><div class="codecolorer" style="font-family: monospace;">vehicle.<span class="me1">travel</span></div></div>
<p>Each vehicle knows how it&#8217;s supposed to move. Each class (Car, Helicopter, Bicycle) defines travel in the appropriate way. We don&#8217;t make decisions <em>for</em> the vehicle; we just tell it what to do.</p>
<p><strong>4. Don&#8217;t Check the Results of Doing Things</strong></p>
<p>Similarly, good object-oriented code should not check the results of sending a message. &#8220;In a Smalltalk OO system, it&#8217;s much more appropriate to just tell an object to do something, then forget about it.&#8221; How do we handle errors, then? Exceptions, of course! Writing code that elegantly raises and handles exceptions is one of the keys to clean, object-oriented code.</p>
<p><strong>Conclusion</strong></p>
<p>Are these observations groundbreaking? No. But they&#8217;re fundamental, and, as I said before, they don&#8217;t often appear in Ruby books. Heeding them will yield readable - even elegant - code. And in the long term, they may help us on our way in the art of coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://kylebanker.com/blog/2008/06/4-principles-of-object-oriented-thinking/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Smalltalk and Ruby</title>
		<link>http://kylebanker.com/blog/2008/06/smalltalk-and-ruby/</link>
		<comments>http://kylebanker.com/blog/2008/06/smalltalk-and-ruby/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 02:42:35 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
		
		<category><![CDATA[The Big Picture]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[Smalltalk]]></category>

		<guid isPermaLink="false">http://blog.kylebanker.com/?p=11</guid>
		<description><![CDATA[I&#8217;ve begun working my way through Kent Beck&#8217;s Smalltalk Best Practice Patterns. Unlike so many techincal books, SBPP packs a punch. In just fifty pages, I&#8217;ve experience several &#8220;ah-hah&#8221; moments; I feel as if my understading of Ruby has grown by an order of magnitude.
Ruby&#8217;s debt to Smalltalk is no secret. So much of what [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve begun working my way through Kent Beck&#8217;s <a href="http://www.amazon.com/Smalltalk-Best-Practice-Patterns-Kent/dp/013476904X/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1212546885&amp;sr=8-1">Smalltalk Best Practice Patterns</a>. Unlike so many techincal books, SBPP packs a punch. In just fifty pages, I&#8217;ve experience several &#8220;ah-hah&#8221; moments; I feel as if my understading of Ruby has grown by an order of magnitude.</p>
<p>Ruby&#8217;s debt to Smalltalk is no secret. So much of what we love about Ruby - pure object orientation, the <a href="http://www.ruby-doc.org/core/classes/Enumerable.html">Enumerable module</a>, <a href="http://martinfowler.com/bliki/Closure.html">closures</a>, and the <a href="http://www.ruby-doc.org/core/classes/Enumerable.html#M001147">inject</a> method - derives from a language twenty years its elder. Rubyists may have much to learn from Smalltalk.</p>
<p>This is especially true given that the Ruby literature, as it stands, consists mostly of syntax and language fundamentals. Books on design, style, and patterns in Ruby are few. In Smalltalk, they seem to abound.</p>
<p>In my relatively superficial survey of a site containing <a href="http://stephane.ducasse.free.fr/FreeBooks.html">free Smalltalk books</a>, I&#8217;ve discovered a significant repository of ideas on object-oriented design and programming.</p>
<p>This is understandable for a least a couple of reasons. Obviously, Smalltalk&#8217;s literature has had more time to mature. But perhaps more importantly, Smalltalk grew up in an age when OOP was not yet the dominant paradigm. Therefore, it would have been important to advocate for the OOP philosophy and coding style.</p>
<p>This advocacy is still important; hence, the continued appeal of Kent Beck&#8217;s SBPP. While the book may be ten years old, and the Smalltalk language somewhat beyond its prime, there&#8217;s much to be gleaned from this gem of a language and its literature.</p>
]]></content:encoded>
			<wfw:commentRss>http://kylebanker.com/blog/2008/06/smalltalk-and-ruby/feed/</wfw:commentRss>
		</item>
		<item>
		<title>5 Core Extension Tips</title>
		<link>http://kylebanker.com/blog/2008/04/5-core-extension-tips/</link>
		<comments>http://kylebanker.com/blog/2008/04/5-core-extension-tips/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 03:37:10 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
		
		<category><![CDATA[Tips &amp; Tricks]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.kylebanker.com/?p=10</guid>
		<description><![CDATA[We&#8217;re all familiar with Rails&#8217; core extensions.  They&#8217;re the Ruby class extensions that allow you do things like:
30.minutes.ago

&#34;octopus&#34;.pluralize

&#91;&#34;Lifeson&#34;, &#34;rocks&#34;, &#34;hard.&#34;&#93;.to_sentence
Now, I often find myself writing Rails helper methods that act on Ruby classes (String, Array, etc.). But to keep my code clean, I like to refactor these helpers as core extensions. This is a [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re all familiar with Rails&#8217; core extensions.  They&#8217;re the Ruby class extensions that allow you do things like:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="nu0">30</span>.<span class="me1">minutes</span>.<span class="me1">ago</span><br />
<br />
<span class="st0">&quot;octopus&quot;</span>.<span class="me1">pluralize</span><br />
<br />
<span class="br0">&#91;</span><span class="st0">&quot;Lifeson&quot;</span>, <span class="st0">&quot;rocks&quot;</span>, <span class="st0">&quot;hard.&quot;</span><span class="br0">&#93;</span>.<span class="me1">to_sentence</span></div></div>
<p>Now, I often find myself writing Rails helper methods that act on Ruby classes (String, Array, etc.). But to keep my code clean, I like to refactor these helpers as core extensions. This is a useful refactoring pattern for Rails applications. We might call it <strong></strong></p>
<ul>
<li><strong>Replace Core Class Helper with Core Extension.</strong></li>
</ul>
<p>I&#8217;m going to show you how to include core extensions in your Rails app.  Then, I&#8217;ll describe four extensions that I commonly use.</p>
<p><strong>1. Write Your Own Core Extensions</strong></p>
<p>First, create a module, name it <strong>core_extensions.rb</strong>, and store it in your /lib folder.</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">module</span> CoreExtensions<br />
<br />
<span class="kw1">end</span></div></div>
<p>Then, at the very end of your <strong>environment.rb</strong> file, require the CoreExtensions module.</p>
<div class="codecolorer-container ruby" style="height:35px;"><div class="codecolorer" style="font-family: monospace;"><span class="kw3">require</span> <span class="st0">'core_extensions'</span></div></div>
<p><strong>2.  Format a string as a possessive.</strong></p>
<p>These two methods extend the String class.  The first returns the last character of a string.  The second produces the possessive (&#8217;s) form.</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">class</span> <span class="kw3">String</span><br />
<br />
<span class="kw1">def</span> last<br />
&nbsp; <span class="kw2">self</span><span class="br0">&#91;</span><span class="kw2">self</span>.<span class="me1">length</span><span class="nu0">-1</span><span class="br0">&#93;</span>.<span class="me1">chr</span><br />
<span class="kw1">end</span><br />
<br />
<span class="kw1">def</span> possessive<br />
&nbsp; <span class="kw2">self</span>.<span class="me1">last</span> == <span class="st0">'s'</span> ? <span class="br0">&#40;</span><span class="kw2">self</span> + <span class="st0">&quot;<span class="es0">\'</span>&quot;</span><span class="br0">&#41;</span> : <span class="br0">&#40;</span><span class="kw2">self</span> + <span class="st0">&quot;<span class="es0">\'</span>s&quot;</span><span class="br0">&#41;</span><br />
<span class="kw1">end</span><br />
<br />
<span class="kw1">end</span></div></div>
<p>Here&#8217;s how it works:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="st0">&quot;Joe&quot;</span>.<span class="me1">last</span><br />
=&gt; <span class="st0">&quot;e&quot;</span><br />
<span class="st0">&quot;Joe&quot;</span>.<span class="me1">possessive</span><br />
=&gt; <span class="st0">&quot;Joe's&quot;</span></div></div>
<p><strong>3. Format Time as Month / Day / Year</strong><br />
Times needs to be formatted in all kinds of ways.  Here&#8217;s just one example:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">class</span> <span class="kw4">Time</span><br />
&nbsp; <span class="kw1">def</span> m_d_y<br />
&nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">strftime</span><span class="br0">&#40;</span><span class="st0">&quot;%B %d, %Y&quot;</span><span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></div></div>
<p>And it works like so:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="kw4">Time</span>.<span class="me1">now</span>.<span class="me1">m_d_y</span><br />
=&gt; <span class="st0">&quot;April 28, 2008&quot;</span></div></div>
<p><strong> 4. Display an array of ActiveRecord objects.</strong><br />
It is often necessary to iterate through an array of ActiveRecord objects, surrounding each with an html tag.  Here&#8217;s an extension to array to automate this:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">class</span> <span class="kw3">Array</span><br />
&nbsp; <span class="kw1">def</span> each_with_tag<span class="br0">&#40;</span>start_tag, end_tag, attribute<span class="br0">&#41;</span><br />
&nbsp; &nbsp; to_display = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">each</span> <span class="kw1">do</span> |element|<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> element.<span class="me1">respond_to</span>?<span class="br0">&#40;</span>attribute<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; to_display &amp;lt;&amp;lt; <span class="br0">&#40;</span>start_tag + element.<span class="me1">send</span><span class="br0">&#40;</span>attribute<span class="br0">&#41;</span> + end_tag<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">raise</span> <span class="kw4">ArgumentError</span>, <span class="st0">&quot;object does not respond to #{attribute}&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw2">return</span> to_display.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&quot;<span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span><br />
<span class="kw1">end</span></div></div>
<p>How does it work?  Say you have a recipe application.  You need to display a list of recipe titles, each within a paragraph element:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="re1">@recipes</span>.<span class="me1">each_with_tag</span><span class="br0">&#40;</span><span class="st0">'&lt;p&gt;'</span>, <span class="st0">'&lt;/p&gt;'</span>, <span class="re3">:title</span><span class="br0">&#41;</span><br />
<br />
=&gt; <span class="st0">&quot;&lt;p&gt;Spinach Lasagna&lt;/p&gt;&quot;</span><br />
<br />
<span class="st0">&quot;&lt;p&gt;Raspberry Tart&lt;/p&gt;&quot;</span></div></div>
<p><strong> 5. Get class name as string.</strong><br />
Here&#8217;s a simple method that comes in handy when using inheritance. Sometimes, you just don&#8217;t know what sort of object you&#8217;re dealing with. The class_name method does just what it says, giving you an easy way to display information about your object.</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">class</span> <span class="kw4">Object</span><br />
&nbsp; <span class="kw1">def</span> class_name<br />
&nbsp; &nbsp; <span class="kw2">self</span>.<span class="kw1">class</span>.<span class="me1">to_s</span>.<span class="me1">downcase</span><br />
&nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></div></div>
<p>Suppose I have a class modeling vegetables in a garden.  If I needed to display a message about a particular vegetable, I could use class_name like so:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="st0">&quot;A &quot;</span> + <span class="re1">@veggie</span>.<span class="me1">class_name</span> + <span class="st0">&quot; should be watered &quot;</span> + <span class="re1">@veggie</span>.<span class="me1">watering_rate</span> + <span class="st0">&quot; times per week.&quot;</span><br />
<br />
=&gt; <span class="st0">&quot;A tomato should be watered two times per week.&quot;</span></div></div>
<p><strong>Summary</strong></p>
<p>Next time you write a helper that acts on a basic Ruby class, consider writing a core extension instead. Using core extensions can help create more elegant, portable, maintainable code.</p>
]]></content:encoded>
			<wfw:commentRss>http://kylebanker.com/blog/2008/04/5-core-extension-tips/feed/</wfw:commentRss>
		</item>
		<item>
		<title>In Medias Res</title>
		<link>http://kylebanker.com/blog/2008/04/in-medias-res/</link>
		<comments>http://kylebanker.com/blog/2008/04/in-medias-res/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 02:06:59 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
		
		<category><![CDATA[Metablog]]></category>

		<guid isPermaLink="false">http://blog.kylebanker.com/?p=9</guid>
		<description><![CDATA[Inspired by the the astonishingly good writing of Paul Graham and 37 Signals (among others), I&#8217;ve been wanting start a blog for some time now.  But I needed an impetus.  Who knew that it would be Ryan Bates and his contest? That will account for the first few entries.
But there&#8217;s no overarching plan [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by the the astonishingly good writing of <a href="http://paulgraham.com/articles.html" target="_self">Paul Graham</a> and <a href="http://www.37signals.com/svn/" target="_self">37 Signals</a> (among others), I&#8217;ve been wanting start a blog for some time now.  But I needed an impetus.  Who knew that it would be <a href="http://railscasts.com/">Ryan Bates</a> and his contest? <em>That</em> will account for the first few entries.</p>
<p>But there&#8217;s no overarching plan for subsequent posts. My hope is that, at least, this blog will give me a chance to improve my writing, examine new ideas (in the world of coding, and elsewhere), and participate in the great dialog afforded by a technology so commonplace that we rarely stop to think just how remarkable it is.</p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://kylebanker.com/blog/2008/04/in-medias-res/feed/</wfw:commentRss>
		</item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.715 seconds -->
