<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Travis Dunn &#187; Quotidian</title>
	<atom:link href="http://www.travisdunn.com/tag/quotidian/feed" rel="self" type="application/rss+xml" />
	<link>http://www.travisdunn.com</link>
	<description>There is neither speech nor language but their voice is heard among them</description>
	<lastBuildDate>Tue, 26 Jan 2010 19:47:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tools of the Trade 2009</title>
		<link>http://www.travisdunn.com/tools-of-the-trade-2009</link>
		<comments>http://www.travisdunn.com/tools-of-the-trade-2009#comments</comments>
		<pubDate>Tue, 13 Oct 2009 11:44:10 +0000</pubDate>
		<dc:creator>Travis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Quotidian]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://www.travisdunn.com/?p=898</guid>
		<description><![CDATA[Mike Gunderloy posted his <a href=" http://afreshcup.com/2009/10/11/my-tools-of-the-trade-2009/" target="_blank">annual roundup of development tools</a>, prompting Ruby Inside's Peter Cooper to issue a <a href=" http://rubyflow.com/items/2865" target="_blank">call</a> for field reports from the rest of the Rubyist operatives out there. Here's my contribution to this reasonable meme.
]]></description>
			<content:encoded><![CDATA[<p>Mike Gunderloy posted his <a href=" http://afreshcup.com/2009/10/11/my-tools-of-the-trade-2009/" target="_blank">annual roundup of development tools</a>, prompting Ruby Inside&#8217;s Peter Cooper to issue a <a href=" http://rubyflow.com/items/2865" target="_blank">call</a> for field reports from the rest of the Rubyist operatives out there. Here&#8217;s my contribution to this reasonable meme.</p>
<p>
<h3><b>Hardware</b></h3>
<p></p>
<p><strong>13&#8243; 4GB Macbook Pro, circa Oct 2009 </strong>– running Snow Leopard and Windows 7, this aluminum savior is the anointed godhead of my development world. </p>
<p><strong>17&#8243; SAGER NP9262 (Clevo D901C) </strong>– the Apollo to the Macbook&#8217;s Adonis, this serves as my &#8220;power incarnate&#8221; machine. It wears Windows 7 handsomely, and will happily execute any resource intensive tasks I send to its gallows.</p>
<p><strong>Dell 24&#8243; Widescreen Monitor </strong>– Has saved more alt/tab keys than I care to calculate.</p>
<p><strong>Mobile Edge Alienware Deluxe Backpack </strong>– it took a lot of restraint to put down my loathing for the garish-boutique-markup-vendor of a company and pick up their product, but Alienware carries one of the nicest laptop bags for bending spacetime to accommodate my 17&#8243; Sager, complete with a bivouac&#8217;s worth of pouches and harnesses. </p>
<p><strong>Dell XPS M170 </strong>– a venerable hero of bygone days, XPS remains in active service running Windows XP SP3 to surprisingly good effect. Trustworthy and redoubtable, measured as the balance of power and portability, and bearing a warranty that allows me to summon field medics!</p>
<p><strong>24&#8243; iMac </strong>– Media and not much else. Media and testing. </p>
<p>
<h3><b>Backups</b></h3>
<p></p>
<p><strong>External 1TB Seagate drives</strong> &#8211; Handles everything from automated backups to disc images to source control. Almost as reassuring as RAID, with a bit more administrative overhead.</p>
<p><strong>Various cloud-hosted SVN/Git repositories</strong> &#8211; Source control repositories are in my opinion the most natural location to &#8220;backup&#8221; and &#8220;restore&#8221; from, be it locally or in magical clouds dappled with unicorn glitter.</p>
<p><strong>Synch between machines</strong> &#8211; An informal but nonetheless practical backup that comes as a consequence of frequently switching computers.</p>
<p>
<h3><b>Software</b></h3>
<p></p>
<p><strong>Firefox</strong> – I don&#8217;t think I use as many FF plugins as most developers, but those I do I find to be indispensible. </p>
<ul>
<li><strong>FireBug </strong>– Especially with all the Javascript development I&#8217;ve been doing in the last year, FireBug continues to reaffirm itself as one of the most important tools at a web developer&#8217;s disposal, and has attained a damn-near-ubiquitous presence in our community.</li>
<li><strong>Adblock Plus</strong> –It turns out that nobody wants to look at ads, no matter how important they are to a stranger&#8217;s business model.</li>
<li><strong>ColorZilla </strong>– Pure convenience plugin for ganking color schemes from attractive pages.</li>
<li><strong>CSSValidator </strong>– First step in CSS bug hunting, conveniently in plugin form.</li>
<li><strong>PageValidator </strong>– Another convenience plugin, helps with developing on FF and testing outwards.</li>
<li><strong>JSONView </strong>– Beautifully formatted JSON output a la the colored, indented XML we&#8217;re accustomed to.</li>
<li><strong>FireFTP </strong>– Integrated FTP for convenience, though I usually run FileZilla.</li>
<li><strong>YSlow </strong>– I can guess a site&#8217;s YSlow score in my head with reliable accuracy now, but it&#8217;s still an effective sanity check.</li>
<li><strong>Greasemonkey </strong>– Testing in the browser is *painful* and Greasemonkey eases this pain.</li>
</ul>
<p><strong>XCode </strong>– Getting better with every release, and the 10.6 build made some huge improvements.</p>
<p><strong>Visual Studio 2008</strong> – I don&#8217;t do enough .NET work these days to upgrade to 2010 yet, but VS remains my favorite IDE on account of its richness and excellent debugger. I still open it on a weekly basis for the Javascript debugger alone.</p>
<p><strong>NetBeans </strong>– Probably the most used and abused software on my system after the browsers, NetBeans is a like a whole pantheon of gods for platforms I&#8217;m working with and has rightfully become my daily place of worship.</p>
<p><strong>TextMate </strong> – A solid &#8220;DE&#8221;, it&#8217;s proven itself quite serviceable for Rails development with a earnest, supportive community striving to ensure, say, that we never run out of attractive color coded themes.</p>
<p><strong>Mac Terminal</strong>– CLI power is liberating and arcane and productive like six days of God!</p>
<p><strong>Photoshop CS4</strong> – as only an amateur digital artist, I gravitate to Photoshop not for its power but because of the wealth of instructional information available. I started using Photoshop 4 in high school and the mostly awful Adobe has kept me as an impressionable customer since then.</p>
<p><strong>Paint.NET/GIMP</strong> – Perfectly serviceable alternatives to Photoshop that I&#8217;m starting to come around to more and more. My GFX program of choice now depends on whatever computer I happen to be using.</p>
<p><strong>MS Excel</strong> – The best software ever published by Microsoft and consummate spreadsheet tool. I use it daily in one sundry capacity or another.</p>
<p><strong>Cygwin </strong>– For terminal goodness on Windows.</p>
<p><strong>HeidiSQL </strong>– Stable, quick, lightweight database interface that just works and never hangs. </p>
<p><strong>FileZilla </strong>– I&#8217;ve been using this for longer than I can remember for all my FTP transferring needs. If it&#8217;s not the best of breed, I wouldn&#8217;t know because I&#8217;ve never had a complaint that pushed me toward its rivals.</p>
<p><strong>Git/msysGit</strong> – The DVCS of the gods; and mortals too, since this is probably one of the biggest software influences on how I work that I&#8217;ve adopted in the last few years.</p>
<p><strong>SVN/Tortoise</strong> – And yet I also maintain a lot of older and perfectly operable Subversion repos, for which Tortoise is winning interface, though I find myself using SVN more for document management these days than code versioning.</p>
<p><strong>TiddlyWiki</strong> – A potent cocktail of brain map, getting things done, project management, scratch paper, and other assorted miscellany that I&#8217;ve tried everything from MS Notes to .txt files to manage. TiddlyWiki is my ideal implementation of this bizarre, nebulous workspace. </p>
<p><strong>KeePass </strong>– Everyone has a password manager, and KeePass is ever-sagacious gatekeeper to whom I entrust the keys to my world.</p>
<p><strong>Truecrypt </strong>– Excellent security, and comforting fixture of my life the more and more I find myself traveling abroad.</p>
<p><strong>PuTTY </strong>– For when I must adventure into the frightful lands of Telnet.</p>
<p><strong>Growl </strong>– Eternally straddling that line between informative and intrusive.</p>
<p><strong>Jing/Camtasia</strong> – For recording demos, screencasts, tutorials, whatever.</p>
<p><strong>Adium/Digsby </strong>– Covers 99% of my communication needs.</p>
<p><strong>Skype</strong> – And of course, Skype is the other 1%.</p>
<p>
<h3><b>Hosting</b></h3>
<p></p>
<p><strong>Dreamhost </strong>– A compelling balance between affordability and &#8220;unterrible&#8221; support, even if the servers are habitually slow. Serves this blog and some other middle-ground needs of mine.</p>
<p><strong>1and1</strong> – Still hosting here due the uncompromising mediocrity of a company whose servers have never been worse or better than &#8220;okay&#8221;.</p>
<p><strong>Pair.com </strong>– Most responsive technical support I&#8217;ve ever received from a hosting company. </p>
<p><strong>Heroku</strong> – I&#8217;ve taken to pushing all new Rails applications I&#8217;m building over to heroku, both professional and personal. So far I&#8217;ve been very, very, very happy with everything from one-click deployments to their knowledgeable staff.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.travisdunn.com/tools-of-the-trade-2009/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming at Full Speed: Accelerating the Central Nervous System, Reducing Brain Resistance</title>
		<link>http://www.travisdunn.com/programming-at-full-speed-accelerating-the-central-nervous-system-reducing-brain-resistance</link>
		<comments>http://www.travisdunn.com/programming-at-full-speed-accelerating-the-central-nervous-system-reducing-brain-resistance#comments</comments>
		<pubDate>Thu, 24 Sep 2009 15:29:52 +0000</pubDate>
		<dc:creator>Travis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Quotidian]]></category>
		<category><![CDATA[Study & Practice]]></category>

		<guid isPermaLink="false">http://www.travisdunn.com/?p=786</guid>
		<description><![CDATA[I'm talking LoC, WPM, and eleventh hours. I'm ignoring productivity, management, and conscientiousness. Write code quicker when you need it now, and gallop through a backlog with habitual speed during downtimes.]]></description>
			<content:encoded><![CDATA[<p>The winner of the Netflix million dollar prize contest was <a href=" http://bits.blogs.nytimes.com/2009/09/21/netflix-awards-1-million-prize-and-starts-a-new-contest/"  target="_blank">announced this month</a>. The two finishers, BellKor and The Ensemble, submitted their final entries 20 and 4 minutes before the deadline, respectively, securing BellKor the win by a harrowing 16 minute difference. I can only imagine the feverish pandemonium that must have erupted from both teams as the appointed hour approached. They must have been hurridly iterating to the very end, and whether ultimately through personal heroism or resourceful team support, the victory blow was delivered by programmers who have no doubt brought intensity and speed into their skill sets as a decisive advantage. </p>
<p>It&#8217;s that speed which can be worth a million dollars, or at least perhaps, seek and destroy eleventh hour bugs, ship a feature that&#8217;s been dropped for time, or make weekend projects feasible. High level productivity gains come from engineering and design decisions and are sustained through appropriate project management. The subject has earned the thoughtful analysis of countless technologists and programmers, but it usually stops short of the visceral fact that the sheer intensity of relentless programming can – in brute, anarchic glory – make more of an impact at the end of the day than any defensive design and planning. Code must be written, and no architectural optimizations can abstract that away.</p>
<p>I don&#8217;t want to dovetail into a blissfully approving flight path of crunch times or task-mandates that doing it right now is more important than doing it right. But that&#8217;s no reason not to celebrate a corner skill in our profession which everyone seems to possess at a demonstrably different level. And that&#8217;s certainly no reason to avoid overexerting ourselves in exercise, given that once we&#8217;ve grown accustomed to a hurried pace it becomes easier to apply in everyday affairs, to enter rush mode at will, to let the mind drift to planning while the fingers type the work.</p>
<p>So what are some ways to become a faster programmer? </p>
<p>
<h3>Programming Competitions</h3>
</p>
<p></p>
<p>More of a strategy than a tactic, willfully committing yourself to short, intense programming sessions over the weekend where you&#8217;re galvanized by the thrill of competition and the taste of an immediate product has got to be one of the best (albeit unscientific) ways to improve your programming speed. It&#8217;s not so much about learning tricks or practice, but personally acquainting yourself with a philosophy of frantic, obsessive concentration on publishing a small deliverable. </p>
<p>The scope is about right for these competitions to allow for focused programming with little worry of feature creep, reevaluations of design as complexities are uncovered, or the many other thoughtful distractions which constitute the larger role of development.
</p>
<p>
<h3>Words per Minute</h3>
</p>
<p></p>
<p>The core virtue of fast programmers is lightning typing speed. You can&#8217;t peck aloofly at the keyboard, but must violently hammer away as if <a href="http://en.wikipedia.org/wiki/The_Typing_of_the_Dead" target="_blank">zombies were attacking your office</a> and your life depended on completing a block of code before the barricades break. Youthful vigor counts for a lot, but so does unrelenting discipline.</p>
<p>
<h3>Snippets and Generators</h3>
</p>
<p></p>
<p>Most IDEs now have tools for managing code snippets and/or powerful template generators. Identify the handful of code you&#8217;re repeating most often – say, accessor methods – and write a snippet for it. I&#8217;ve only found myself writing perhaps 2-5 snippets at most, almost always to make up for shortcomings in the syntax and idioms of the platform I&#8217;m working on. </p>
<p>
<h3>Hotkeys and Text Expansion</h3>
</p>
<p></p>
<p>Similarly, dedicate yourself to learning the hotkeys of the environments you&#8217;re working with; print up cheat sheets and forbid yourself from using the mouse to perform actions with a known hotkey. Embrace <a href=" http://weblogs.asp.net/jgalloway/archive/2006/06/14/Mouseless-Computing.aspx" target="_blank">mouseless computing</a>.</p>
<p>Text expansion/intellisense/code completion is a special subset of productivity located in the mouseless computing paradigm, and the quicker you can type through heavily parameterized function calls the further you&#8217;ve risen above the limitations of verbose languages, libraries, APIs.</p>
<p>
<h3>Head Programming</h3>
</p>
<p></p>
<p>
The quickest way to program is to embark with firm goals and implementation plans, programming the project in your head before you ever touch the keyboard. Formal specs take too long and impulsive programming leads to wasteful back-stepping, so the idea is to develop a balanced mental tour that gives you just enough context and boundaries so that, at any given point as you code, you&#8217;ll know what precisely what the next step should be.</p>
<p>
<h3>Sub-Machine Guns</h3>
</p>
<p></p>
<p>Prolonged white-knuckled programming is an unsustainable weapon in the developer&#8217;s arsenal, and must be used properly. By properly I mean &#8220;like a sub-machine gun&#8221;: sustained fire in short, controlled bursts. With ass on seat and fingers on the keys, dump as much code as possible onto the screen, but stop periodically to cool down and re-aim. The pause is only to gather your resolve for another assault and it mustn&#8217;t last long, merely long enough to ensure that you&#8217;re hitting your target and to crack your knuckles.</p>
<p>
<h3>Mock Code</h3>
</p>
<p></p>
<p>Building and propelling momentum is at the heart of fast programming (and, for that matter, entering the fabled &#8220;zone&#8221;). Anything that kills this momentum, even as a necessary evil, should be avoided. If an implementation detail is threatening to arrest your speed, abstract the offending code and push if off into some stub to be revisited later, preferably while waiting for a compile or test suite to run.</p>
<p>Working code is paramount when you&#8217;re racing the clock, and if you can defer some unexpected analysis until later, so much the better. My assumption is that a mocked feature now with full supporting code is better than uniformly functional but incomplete code. Yes, even magic numbers are better than putting on the brakes.</p>
<p>
<h3>Code on the Side</h3>
</p>
<p></p>
<p>Every second is precious, and we regularly endure brief moments of inopportune downtime while we compile the code, deploy it, launch the environment, run tests, transfer files, and so on. Always keep some code on the side to jump to and from during these lags. It must, of course, be the sort of code amenable to quick modifications, and requiring only minimal effort to mentally reorientate to and resume. There are always edges of a project like this, however, and the trick is strategically saving them to fill in otherwise unproductive gaps. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.travisdunn.com/programming-at-full-speed-accelerating-the-central-nervous-system-reducing-brain-resistance/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails: Param-Laden Conditional Finder Methods</title>
		<link>http://www.travisdunn.com/rails-params-laden-conditional-finder-methods</link>
		<comments>http://www.travisdunn.com/rails-params-laden-conditional-finder-methods#comments</comments>
		<pubDate>Tue, 11 Aug 2009 13:56:49 +0000</pubDate>
		<dc:creator>Travis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Quotidian]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.travisdunn.com/?p=339</guid>
		<description><![CDATA[ActiveRecord associations are magical, and if you embrace the sundry offerings of finder plugins the world of parameterized queries becomes a vast and wondrous landscape indeed. So how do Rails developers typically organize and build dynamic queries without drenching their code in switch blocks, multiplying filter methods on the model, or contriving vestigial routes for search- and report- like GETs?]]></description>
			<content:encoded><![CDATA[<p>ActiveRecord associations are magical, and if you embrace the sundry offerings of finder plugins the world of parameterized queries becomes a vast and wondrous landscape indeed. So how do Rails developers typically organize and build dynamic queries without drenching their code in switch blocks, multiplying filter methods on the model, or contriving vestigial routes for search- and report- like GETs?</p>
<p>My sense from reading various blog posts and git repos is that most people factor such logic out of the controller, which at least consolidates the complexity further upstream, and then resort to a variety of Ruby syntax and Rails convenience methods as required by the query. This is the approach I&#8217;ve always taken, and because I don&#8217;t think there is a better way to generalize the solution that isn&#8217;t already represented in the framework, I&#8217;m posting an example finder method as a sort of syntax reference.</p>
<p>What follows is a pretty typical case. This method is using <a href="http://github.com/binarylogic/searchlogic/tree/master">searchlogic</a>, <a href="http://github.com/andre/geokit-gem/tree/master">geokit</a>, and <a href="http://github.com/mbleigh/acts-as-taggable-on/tree/master">acts-as-taggable-on</a>, as well as named_scope and some basic pagination. Ruby&#8217;s Hash is the real hero here and gives us most of the tools needed to keep such methods readable. </p>
<pre class="brush: rails">
class &lt;&lt; self
   def find_with_options(opt={})
   opt = opt.slice(:tags, :search, :sw_lat, :sw_lng, :ne_lat, :ne_lng, :limit, :offset)
   conditions = {}

   unless opt[:sw_lat].blank? || opt[:sw_lng].blank? || opt[:ne_lat].blank? || opt[:ne_lng].blank?
            sw_point = GeoKit::LatLng.new(opt[:sw_lat],opt[:sw_lng])
            ne_point = GeoKit::LatLng.new(opt[:ne_lat],opt[:ne_lng])
            conditions[:bounds] = [sw_point,ne_point]
   end

   conditions[:limit] = opt[:limit] ||= 50
   conditions[:offset] = opt[:offset] ||= 0

   scope = MyModel.include_an_associated_model
   scope = scope. associated_model _name_like(opt[:search]) unless opt[:search].blank?
   scope = scope.tagged_with(opt[:tags], :on =&gt; : tags) unless opt[:tags].blank?
   scope.all conditions
   end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.travisdunn.com/rails-params-laden-conditional-finder-methods/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails: polymorphic belongs_to associations with accepts_nested_attributes_for</title>
		<link>http://www.travisdunn.com/rails-polymorphic-belongs_to-associations-with-accepts_nested_attributes_for</link>
		<comments>http://www.travisdunn.com/rails-polymorphic-belongs_to-associations-with-accepts_nested_attributes_for#comments</comments>
		<pubDate>Fri, 31 Jul 2009 17:54:50 +0000</pubDate>
		<dc:creator>Travis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Quotidian]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.travisdunn.com/?p=274</guid>
		<description><![CDATA[If there is a combinatorial way to bring aspects of a framework together in a breaking edge case, I will find that way and take that step. It’s a destiny one follows gladly; an instinct useful in defining the boundaries of an application’s logical complexities as they accumulate on the brain like bit patterns.]]></description>
			<content:encoded><![CDATA[<p>If there is a combinatorial way to bring aspects of a framework together in a breaking edge case, I will find that way and take that step. It’s a destiny one follows gladly; an instinct useful in defining the boundaries of an application’s logical complexities as they accumulate on the brain like bit patterns. It makes you wade through limitations, leading to unexpectedly serviceable workarounds.</p>
<p>The problem for me, at least, is that I can’t turn the compulsion off. It sits right below my consciousness, urging the brain, when given a system, to seize upon the most elegant paradox it detects for solving the problem at hand. Take, for example, polymorphic belongs_to associations with accepts_nested_attributes_for in Rails. Any two of these keywords in combination will turn up tales in the SERPs of bewilderment and errors, but the effort to solve a data modeling problem brought these three elements together in a perfect storm that would punish me for my inspiration.</p>
<p>So I’ve one model, which then belongs_to another, polymorphic, model. The belongs_to model was the workhorse of the pair, and therefore needed to accepts_nested_attributes_for in order to initialize its counterpart as required.</p>
<pre class="brush: rails">
class BelongsToModel &lt; ActiveRecord::Base
   belongs_to :polymorph_model, :polymorphic =&gt;true
   accepts_nested_attributes_for :polymorph_model
end
</pre>
<p>Unfortunately, what appears to happen when one puts this design into practice is that a NoMethodError is thrown whenever the belongs_to model receives the nested attributes hash, e.g.</p>
<pre class="brush: rails">
params = {
   :name =&gt; “blah”,
   :parent_type =&gt; “polymorph_obj_class”,
   :polymorph_model_attributes =&gt; {
      :info =&gt; “blah”,
      :details =&gt; “blah”
   }
}

@belongsToModel = BelongsToModel.new(params)
</pre>
<p>In the example, polymorph_model_attributes is constructed with the attributes “info” and “details” because I personally have the domain knowledge to know that those attributes belong to the polymorph model and should be provided. To process nested attributes, however, Rails needs to know this also so it can use that knowledge to add an appropriate build method (called something like ‘build_polymorph_model ‘) to the belongs_to model, and initialize the nested object whenever the belongs_to model is initialized.</p>
<p>The paradox arises because Rails cannot dynamically create a “build_polymorph_model” method without first knowing the class of the polymorph. Even passing in a parent_type or equivalent attribute will not provide the model with the foreknowledge it needs to build this helper method.</p>
<p>Any alteration to my data model would be enough to escape the conflict, but this uncomfortable relationship with belongs_to and the need to instantiate my objects from the direction of the belongs_to model came about because it really does best represent the schema behind the scenes, and so I was loathe to surrender it to the apparent constraints.</p>
<p>The solution was as simple as possible. I took a literalist approach, and went ahead and defined the build_polymorph_model explicitly myself, adding in the appropriate logic to initialize any one of the several possible polymorphic models that could be associated.</p>
<pre class="brush: rails">
class BelongsToModel &lt; ActiveRecord::Base
   belongs_to :polymorph_model, :polymorphic =&gt;true
   accepts_nested_attributes_for :polymorph_model

   def build_polymorph_model(params)
      # build any supported polymorphic relationships here
   end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.travisdunn.com/rails-polymorphic-belongs_to-associations-with-accepts_nested_attributes_for/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Named Branches: Logic to the Word</title>
		<link>http://www.travisdunn.com/named-branches-logic-to-the-word</link>
		<comments>http://www.travisdunn.com/named-branches-logic-to-the-word#comments</comments>
		<pubDate>Thu, 23 Jul 2009 19:21:54 +0000</pubDate>
		<dc:creator>Travis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Quotidian]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://www.travisdunn.com/?p=207</guid>
		<description><![CDATA[Comments and self-documenting code are like brandy and cigars, the first illuminating your source (meaning both the gentleman’s soul and the source code into which he pours it), and the second imparting a blazing instance of clarity where you can taste the meaning.

Adherents debating the styles travel parallel roads in the direction of improving maintainability, [...]]]></description>
			<content:encoded><![CDATA[<p>Comments and self-documenting code are like brandy and cigars, the first illuminating your source (meaning both the gentleman’s soul and the source code into which he pours it), and the second imparting a blazing instance of clarity where you can taste the meaning.</p>
<p><img class="size-medium wp-image-217" style="float:right;" title="Brandy and Cigars" src="http://www.travisdunn.com/wp-content/uploads/2009/07/brandy-and-cigars-200x300.jpg" alt="Brandy and Cigars" width="200" height="300" /></p>
<p>Adherents debating the styles travel parallel roads in the direction of improving maintainability, but take opposing paths (and tend to toss aspersions across the median). Comments depart from reality over time and are perhaps redundant by nature, while self-documenting code is a frequent vanity and incapable of reflecting the many levels of abstraction that constitute design. I think a good way of realistically traveling these issues is by practice, and naming your branch conditionals (the subject I raise this very moment!) is a modest but noble idiom suitable for any lounge in solitude or with a cordial in hand.</p>
<p>Branch conditionals are important thing to name right because they’re all but the core flow of your code and you’ll be reading them over and over again in the repetitive quest for understanding, and its more senile relative, recollection. Branch conditionals (usually) look like this:</p>
<pre class="brush: js">
If (x &amp;&amp; (y = (d  ? a : b) || y &lt; e.p() ) )
{
blah();
}
else if (t.F() &amp;&amp; g == q[0])
{
meh();
}
</pre>
<p>A far more readable and self-documenting way to formulate the code would simply be:</p>
<pre class="brush: js">
var isThisThingAndAlsoSomethingElse = (y = (d  ? a : b) || y &lt; e.p() );
var butThatCouldAlsoBe = t.F() &amp;&amp; g == q[0];
If (isThisThingAndAlsoSomethingElse )
{
doThis();
}
else if (butThatCouldAlsoBe)
{
doThat();
}
</pre>
<p>I find the separation of the comparisons from their consequences to save hundreds of milimoments of thought when working with code. Like most advice, it’s quite simple, and nobody follows it. The highest value can come from small optimizations like this, and collectively, when I scroll through source code with a lot of named booleans I read it that much faster than short files with pithy dents of anonymous conditionals.</p>
<p>In fact, I find this simple idiom useful enough that if I were granted one wish about all the code I’m to read before I die, well, named branches would be the second after the simple demand for thoughtful, verbose variable names, of which named branches is a like subset to begin with so it’s reasonable several times over.</p>
<p>A fortunate byproduct this practice is that naming branch conditionals can sometimes be hard, a fact you should use as a chance to articulate your logic. Choosing a name can also be a useful secondary measure of code smell, or suggest method refactoring, or reveal problems with business logic, and what’s more it’s a further refinement in this world of programming where nouns and verbs are given descriptive titles yet filled with murky details.</p>
<p>So what you have is self-documenting code because it reads like a comment, and it must read like a comment in order to express a more or less complex branch conditional.  At a higher level, idioms like this are showing up in a lot of other places like Domain-Specific Languages and advice on naming tests, which are arguably just a branch conditional at heart themselves. What that suggests to me is that it’s a useful detail for programmers to orientate to.</p>
<p>Benefits: readability; passive analytical tool; DRY.<br />
Costs: verbose; antagonizes our instinct for quick and clever over clear.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.travisdunn.com/named-branches-logic-to-the-word/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
