<?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"
	>

<channel>
	<title>ronin coder</title>
	<atom:link href="http://rcoder.net/feed" rel="self" type="application/rss+xml" />
	<link>http://rcoder.net</link>
	<description>paraliteracy has its perks</description>
	<pubDate>Fri, 10 Oct 2008 23:57:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>Registration, ACORN, and fraud</title>
		<link>http://rcoder.net/content/registration-acorn-and-fraud</link>
		<comments>http://rcoder.net/content/registration-acorn-and-fraud#comments</comments>
		<pubDate>Fri, 10 Oct 2008 23:57:42 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=257</guid>
		<description><![CDATA[I&#8217;ve twittered about this already, but I think that it&#8217;s worth repeating: collecting redundant and invalid voter registration cards is not the same thing as fraudulent voting. I repeat: by registering people multiple times, or even submitting invalid registration cards, ACORN (and every other voter reg group) is not committing voting fraud. They are simply [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve <a href="http://twitter.com/rcoder/statuses/953447311">twittered</a> about this already, but I think that it&#8217;s worth repeating: collecting redundant and invalid voter registration cards is not the same thing as fraudulent voting. I repeat: by registering people multiple times, or even submitting invalid registration cards, ACORN (and every other voter reg group) is <em>not committing voting fraud</em>. They are simply doing a bad job of actually registering voters.</p>
<p>The whole reason that voter registration is required before you&#8217;re allowed to vote is so that the local and state election boards can have a chance to verify your eligibility. If you submit more than one registration, it may cost them a few minutes of work to update or reject your registration records, but it won&#8217;t allow you to vote more than once.</p>
<p>So, if it doesn&#8217;t let people &#8220;vote early and often,&#8221; why in the hell would ACORN, as an organization, have such a poor record regarding bad registrations? It&#8217;s simple: they <em>require their workers to meet a certain quota in order to get paid</em>. I&#8217;ve done a bit of volunteer voter registration, and while it&#8217;s easier than many other types of direct-contact political work &#8212; fundraising and candidate canvassing are both harder, if only because of their inherent partisan focus &#8212; you still have good days and bad days out on turf.</p>
<p>Try to imagine yourself in the following position: you&#8217;re a high school or college student trying to make a little money over the summer, while still doing something a bit more proactive than flipping burgers. Furthermore, your meager paycheck is dependent on hitting your quota each and every week, and you&#8217;ve heard horror stories of the poor-performing workers who got canned just last month.</p>
<p>Now, imagine you&#8217;re two registrations short of your quota for the week. Would you be even a little bit tempted to fake one, or press that nice stranger who insisted they were already registered to do so again, in order to save your job? I suspect that most people, if they&#8217;re being honest with themselves, would answer at the very least that they might be at least a little bit tempted. I know that I would, which is part of the reason that I&#8217;m not very interested in doing any <em>paid</em> political work &#8212; as a volunteer, the temptation to cheat goes away.</p>
<p>(Please note that I&#8217;m not trying to defend this sort of behavior as <em>ethical</em>, but it is at least <em>understandable</em>.)</p>
<p>Personally, I think the interesting argument isn&#8217;t even about whether ACORN does a good or bad job of supervising their staff, or encouraging the right behaviors. The real debate we should be having is whether paid voter registration does more harm than good. The same question extends to signature-gathering, an especially hot issue in Oregon given the recent flood of bad ballot measures.</p>
<p>I personally haven&#8217;t decided one way or the other, but I think that a much more constructive discussion is there, waiting to be had, once we get past the current baseless accusations being leveled at ACORN and its partner groups.</p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/registration-acorn-and-fraud/feed</wfw:commentRss>
		</item>
		<item>
		<title>Why we need universal health coverage</title>
		<link>http://rcoder.net/content/why-we-need-universal-health-coverage</link>
		<comments>http://rcoder.net/content/why-we-need-universal-health-coverage#comments</comments>
		<pubDate>Thu, 09 Oct 2008 00:17:10 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=254</guid>
		<description><![CDATA[&#60;political-rant&#62;
I had surgery to repair my broken ankle this sumer. I also have fairly good health insurance through my employer. So, when the pre-billing statements from the hospital, surgeon, and anasthesiologist started showing up, I didn&#8217;t panic, even though the total bill (>$15K) would have been pretty tough for me to pay out-of-pocket.
When all was [...]]]></description>
			<content:encoded><![CDATA[<p><b>&lt;political-rant&gt;</b></p>
<p>I had surgery to repair my broken ankle this sumer. I also have fairly good health insurance through my employer. So, when the pre-billing statements from the hospital, surgeon, and anasthesiologist started showing up, I didn&#8217;t panic, even though the total bill (>$15K) would have been pretty tough for me to pay out-of-pocket.</p>
<p>When all was said and done, and my insurance had been fully invoked, I ended up owing a little under $1500. Seems pretty good, right? 90% coverage is good enough for all but the most expensive medical issues, and even significantly more expensive bills might be manageable under some sort of payment structure.</p>
<p>However, of that more than $13,000 that was &#8220;covered,&#8221; my insurance company actually only paid about $4000. That&#8217;s because they drive down the cost of everything else via contracts held with the hospitals, along with a healthy dose of strong-arming of doctors and specialists. (&#8221;If you want us to cover any of your patients, you&#8217;re going to have to accept 30 cents on the dollar for this procedure.&#8221;)</p>
<p>While that doesn&#8217;t directly affect me, it does mean that prices have to be that much higher for everyone without insurance. Without the insurance companies to negotiate on their behalf, they&#8217;re stuck paying extra to cover the gap between the real cost of care and what the insurers will pay.</p>
<p>We need a comprehensive Federal health plan that covers <em>everyone</em> if we&#8217;re going to have any chance of getting a handle on the cost of health care. Leaving those with the least all on their own to try to negotiate for care is neither fair nor sustainable.</p>
<p><b>&lt;/political-rant&gt;</b></p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/why-we-need-universal-health-coverage/feed</wfw:commentRss>
		</item>
		<item>
		<title>Contrasting the iPhone and Android development kits</title>
		<link>http://rcoder.net/content/contrasting-the-iphone-and-android-development-kits</link>
		<comments>http://rcoder.net/content/contrasting-the-iphone-and-android-development-kits#comments</comments>
		<pubDate>Thu, 25 Sep 2008 20:34:26 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=245</guid>
		<description><![CDATA[Since the Android phone announcement on Tuesday, there has been a decent amount of wild speculation going around the &#8216;tubes about the differences in &#8220;developer experience&#8221; between the iPhone and Android platforms. While my opinions on Apple&#8217;s legal and business restrictions on iPhone developers are pretty clear, I haven&#8217;t really written much about the technical [...]]]></description>
			<content:encoded><![CDATA[<p>Since the Android phone announcement on Tuesday, there has been a decent amount of <a href="http://weblog.infoworld.com/fatalexception/archives/2008/09/sdk_shootout_an.html">wild speculation</a> going around the &#8216;tubes about the differences in &#8220;developer experience&#8221; between the iPhone and Android platforms. While <a href="http://rcoder.net/content/thank-you-steven-frank">my opinions</a> on Apple&#8217;s legal and business restrictions on iPhone developers are pretty clear, I haven&#8217;t really written much about the technical underpinnings.</p>
<div style="indent-left: 2em;">Caveat: I won&#8217;t sign the iPhone SDK NDA, so my comments about that development environment are  based on my experience with the normal OS X development toolchain, articles by developers working only with jailbroken iPhones, and limited use of iPhone apps on friends and colleagues&#8217; devices. On the other hand, that also means I can actually write this without violating any legal agreements, so gimme a break, ok?</div>
<p>Generally, both platforms mostly abstract away the underlying UNIX-y system, and heavily sandbox 3rd-party applications to limit their ability to corrupt or expose the user&#8217;s data. Android gives users more options to replace or augment core applications, but the underlying sandbox mechanisms remain in place &#8212; i.e., an app can&#8217;t access your contact list unless you explicitly grant it that privilege at install time.</p>
<p>Also, both platforms rely heavily on code signing. You can&#8217;t distribute an iPhone app through the App Store unless it&#8217;s been signed with an Apple-issued certificate; The Android OS, on the other hand, allows developers to use the certificate of their choice to sign apps. (Carriers could lock this down further, of course, but there&#8217;s been no indication that such a lock will be in place for the G1.)</p>
<p>In terms of the actual toolchain, there are some major differences. While the iPhone uses a simple cross-compiler to build Objective-C projects, the Android tools are designed to support compilation to VM bytecodes, which are then transferred to the mobile device and JIT-ed in place. The XCode/Eclipse distinction is really one of personal preference, and both systems provide first-class support for command-line compilation and packaging, so you could configure Emacs/Vim/TextMate/etc. to handle project build tasks.</p>
<p>I also have the sense (and this is where my lack of access to the full iPhone SDK becomes a problem) that that the iPhone tends to package shared services as Framework libraries (ala OS X) while Android relies on a high-level IPC framework and reusable sub-processes (called Activities) to allow applications to invoke each other to perform common tasks.</p>
<p>Of course, one of the biggest distinctions to my mind is that Android projects can make use of multithreading and background daemons (Services in Android-speak) to handle long-running and GUI-less tasks. The notification APIs provided in the iPhone may cover a lot of asynchronous messaging use cases, but having full use of threads opens  up a lot of other interesting possibilities.</p>
<p>Overall, both platforms offer an interesting environment to work with. iPhone apps are likely to be less inter-dependent, with better protections against any one badly-authored app causing the phone&#8217;s performance or battery life to suffer. However, iPhone developers will struggle much more than their Android-targeting-colleagues to find ways to integrate their applications, both due to their inability to coordinate between simultaneously-running threads, and due the the NDA&#8217;s restrictions on information-sharing amongst themselves.</p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/contrasting-the-iphone-and-android-development-kits/feed</wfw:commentRss>
		</item>
		<item>
		<title>TPC XXI</title>
		<link>http://rcoder.net/content/tpc-xxi</link>
		<comments>http://rcoder.net/content/tpc-xxi#comments</comments>
		<pubDate>Tue, 23 Sep 2008 00:00:26 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=243</guid>
		<description><![CDATA[
We rocked it. Oh yes we did.
]]></description>
			<content:encoded><![CDATA[<p align="center"><a href="http://www.flickr.com/photos/rcoder/2879967487/" title="DSCN0197 by rcoder, on Flickr"><img style="border: 2px solid black;" src="http://farm4.static.flickr.com/3242/2879967487_904cf8931a.jpg" width="500" height="375" alt="DSCN0197" /></a></p>
<p>We rocked it. Oh yes we did.</p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/tpc-xxi/feed</wfw:commentRss>
		</item>
		<item>
		<title>Gone coding</title>
		<link>http://rcoder.net/content/gone-coding-2</link>
		<comments>http://rcoder.net/content/gone-coding-2#comments</comments>
		<pubDate>Thu, 18 Sep 2008 04:29:27 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[photos]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=240</guid>
		<description><![CDATA[


You wanna know how lame I am? I didn&#8217;t even take this picture. That&#8217;s how much I&#8217;ve been slacking on the blogging and photographic fronts.
]]></description>
			<content:encoded><![CDATA[<p align="center">
<a href="http://www.flickr.com/photos/rcoder/2866458169/" title="DSCN0140 by rcoder, on Flickr"><img style="border: 2px solid black;" src="http://farm4.static.flickr.com/3195/2866458169_bf71a964ea.jpg" width="500" height="375" alt="DSCN0140" /></a>
</p>
<p>You wanna know how lame I am? I didn&#8217;t even take this picture. That&#8217;s how much I&#8217;ve been slacking on the blogging and photographic fronts.</p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/gone-coding-2/feed</wfw:commentRss>
		</item>
		<item>
		<title>Erlang warts</title>
		<link>http://rcoder.net/content/erlang-warts</link>
		<comments>http://rcoder.net/content/erlang-warts#comments</comments>
		<pubDate>Thu, 04 Sep 2008 00:59:56 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[code]]></category>

		<category><![CDATA[erlang]]></category>

		<category><![CDATA[rant]]></category>

		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=234</guid>
		<description><![CDATA[After more than a year of complaining about the syntax, I&#8217;m forcing myself to finally sit down and learn some Erlang. Between CouchDB, EjabberD, and all the other interesting projects people are implementing in Erlang, I would be remiss as a systems engineer to not at least pick up the basics.
Unfortunately, I&#8217;m still chafing a [...]]]></description>
			<content:encoded><![CDATA[<p>After more than a year of complaining about the syntax, I&#8217;m forcing myself to finally sit down and learn some <a href="http://erlang.org">Erlang</a>. Between <a href="http://couchdb.org">CouchDB</a>, <a href="http://ejabberd.im">EjabberD</a>, and all the <a href="http://tsung.erlang-projects.org/">other interesting projects</a> people are implementing in Erlang, I would be remiss as a systems engineer to not at least pick up the basics.</p>
<p>Unfortunately, I&#8217;m still chafing a bit at a number of little annoyances:</p>
<ul>
<li>The REPL is basically crippled since you can&#8217;t define functions. Being forced to think in terms of compilation units (rather than simple expressions) pisses me off.</li>
<li>Why oh why do I need to explicitly list the module name in my file header if I&#8217;m also bound by the restriction that filenames and module names have to be the same? The old Java package/file path ties were always a big annoyance when I was stuck in that environment.</li>
<li>For a functional language, there&#8217;s an awful lot of syntactic vinegar for basic operations like <code>map</code> and <code>fold</code>. I appreciate having a concise syntax for lambdas, but writing <code>fun my_function/2</code> smells a bit.</li>
<li>Records (as syntactic sugar for tuples) are a poor substitute for a real type system. Both tutorial and real-world Erlang code I&#8217;ve seen is basically full of tagged tuples, which means you get the verbosity of a strongly-typed language without any of the ability of real type checking to catch errors at compilation time.</li>
</ul>
<p>I want to stick with it long enough to find the real gems underneath all this noise. I mean, if I can sit through extended sessions reading and writing Perl, I should be able to find something to love about Erlang. Furthermore, most of the complaints I make above are inapplicable to mainstream languages &#8212; i.e., C and Java dont have an REPL or lambdas, and Ruby and Perl don&#8217;t have anything resembling a traditional compiler &#8212; not miraculously better.</p>
<p>I definitely think that learning a new language should make you feel a little bit uncomfortable. Unfortunately, right now Erlang leaves me feeling uncomfortable in all the wrong ways: I <em>understand</em> everything that&#8217;s going on with the language, and <em>just don&#8217;t like it</em>.</p>
<p>I&#8217;m going to keep plugging away for at least a little bit longer, though. Next up: reading the source to EJabberD to (hopefully) get a sense for idiomatic language use in a context where its unique features (lightweight concurrency + distributed computing) are a real advantage.</p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/erlang-warts/feed</wfw:commentRss>
		</item>
		<item>
		<title>&#8217;tis the season&#8230;</title>
		<link>http://rcoder.net/content/tis-the-season</link>
		<comments>http://rcoder.net/content/tis-the-season#comments</comments>
		<pubDate>Sun, 31 Aug 2008 01:08:38 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=232</guid>
		<description><![CDATA[&#8230;for voting! (Well, for trying to convince people to vote, anyway.)

]]></description>
			<content:encoded><![CDATA[<p>&#8230;for voting! (Well, for trying to convince people to vote, anyway.)</p>
<p align="center"><a title="DSC_0111 by rcoder, on Flickr" href="http://www.flickr.com/photos/rcoder/2812697120/"><img style="border: 2px solid black;" src="http://farm4.static.flickr.com/3125/2812697120_0cae7e6c4b.jpg" alt="DSC_0111" width="335" height="500" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/tis-the-season/feed</wfw:commentRss>
		</item>
		<item>
		<title>New Hardware</title>
		<link>http://rcoder.net/content/new-hardware</link>
		<comments>http://rcoder.net/content/new-hardware#comments</comments>
		<pubDate>Wed, 27 Aug 2008 02:08:54 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=230</guid>
		<description><![CDATA[I just go a slick new work machine: a Lenovo ThinkPad X300. It&#8217;s got loads of RAM (4GB), a 60GB solid-state disk in place of a hard drive, and it all weighs in at just under 3 lbs. It&#8217;s the best laptop I&#8217;ve ever used, and if it&#8217;s anything like the other ThinkPads I&#8217;ve owned, [...]]]></description>
			<content:encoded><![CDATA[<p>I just go a slick new work machine: a Lenovo ThinkPad X300. It&#8217;s got loads of RAM (4GB), a 60GB solid-state disk in place of a hard drive, and it all weighs in at just under 3 lbs. It&#8217;s the best laptop I&#8217;ve ever used, and if it&#8217;s anything like the other ThinkPads I&#8217;ve owned, it should be with me for a while.</p>
<p>The nicest surprise has actually been just how well Ubuntu worked out of the box. Wireless, video, webcam, and both pointing devices worked right off the bat. One well-documented config tweak later, and I had suspend/resume (and <em>fast</em>, too &#8212; just about as good as my MBP). Audio took a bit more work, mainly because Ubuntu distributed an older ALSA snapshot. Once I re-compiled the audio drivers from the latest ALSA release and moved the Ubuntu versions aside, I had loud, clear sound.</p>
<p>I do mean <em>loud</em>, too &#8212; the built-in speakers on this thing is significatly louder than my MacBook Pro, or any other X-series ThinkPad I&#8217;ve tried (X24, X41, X60). Since music + video are a big part of what I do with a laptop, that&#8217;s actually really nice to have.</p>
<p>Overall, this is a machine I can highly recommend. The 1.2 GHz processor and integrated graphics chip <em>should</em> feel poky compared to my year-old but faster-on-paper Mac, but the solid-state disk helps quite a bit, and certain key applications (Firefox in particular) just feel faster under Linux than they do on OS X.</p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/new-hardware/feed</wfw:commentRss>
		</item>
		<item>
		<title>Thank you, Steven Frank</title>
		<link>http://rcoder.net/content/thank-you-steven-frank</link>
		<comments>http://rcoder.net/content/thank-you-steven-frank#comments</comments>
		<pubDate>Mon, 18 Aug 2008 21:58:51 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[apple]]></category>

		<category><![CDATA[rant]]></category>

		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=227</guid>
		<description><![CDATA[For those who don&#8217;t already know, Steven Frank (a.k.a. stevenf on many sites) is a developer at Panic, Inc., a multiple-award-winning Mac software shop here in Portland. He (and his firm) are unapologetic Mac boosters, and have based their entire business around producing applications which appeal in large part to the aesthetic and functional preferences [...]]]></description>
			<content:encoded><![CDATA[<p>For those who don&#8217;t already know, <a href="http://stevenf.com/">Steven Frank</a> (a.k.a. stevenf on many sites) is a developer at <a href="http://www.panic.com/">Panic, Inc.</a>, a multiple-award-winning Mac software shop here in Portland. He (and his firm) are unapologetic Mac boosters, and have based their entire business around producing applications which appeal in large part to the aesthetic and functional preferences of the most die-hard Apple fans.</p>
<p>I&#8217;m unlikely to work as a proprietary desktop software developer any time soon, given that I haven&#8217;t tried to write a desktop GUI application in about five years, but I do appreciate the work that Panic puts into polishing their user experience, and have a great deal of respect for them as a development team. And so, it was extremely refreshing to me to see many of the fears and frustrations I&#8217;ve expressed about the iPhone/App Store platform lock-in as an outside <a href="http://stevenf.com/archive/on-the-app-store.php">being echoed</a> by someone who is working within that ecosystem.</p>
<p>One realization I had early on in my IT career was that almost any two firms could easily become competitors. Given the rate at which a competent team can develop most any class of application on the planet, and the generality of the platforms on which our code runs, it is entirely conceivable that your platform vendor of choice today (or your client buying your tools or OS) could become a direct competitor tomorrow. For that very reason, trusting the future of your business to the continuing benevolence of a vendor is a very risky decision.</p>
<p>Every developer working on applications for the iPhone/iTouch platform is in exactly that precarious position right now. Those innovative applications that drive sales of the platform could easily be incorporated into the next release of the OS, since Apple has more than enough resources to re-implement any 3rd-party app without breaking a sweat. (There is certainly precedent for this: just ask the developers of <a href="http://www.karelia.com/watson/">Watson</a> what it&#8217;s like to one-up Apple in the system utility space.) Even worse, truly disruptive applications that offer capabilities beyond Apple&#8217;s comfort zone (or that of one or more of their mobile network providers) could find themselves <a href="http://www.engadget.com/2008/08/01/netshare-iphone-tethering-app-reappears-in-the-app-store/">summarily dropped</a> from the App Store, effectively strangling any business the developer hoped to build around the product.</p>
<p>This is, to me at least, an unacceptable bargain, and I&#8217;m surprised that so many other developers seem to have no problem with the arrangement. (Have I mentioned how much I <a href="http://blogs.zdnet.com/mobile-gadgeteer/?p=676">can&#8217;t wait</a> for <a href="http://code.google.com/android/">Android</a>?)</p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/thank-you-steven-frank/feed</wfw:commentRss>
		</item>
		<item>
		<title>Mixins without monkeypatching</title>
		<link>http://rcoder.net/content/mixins-without-monkeypatching</link>
		<comments>http://rcoder.net/content/mixins-without-monkeypatching#comments</comments>
		<pubDate>Thu, 14 Aug 2008 18:43:06 +0000</pubDate>
		<dc:creator>lennon</dc:creator>
		
		<category><![CDATA[code]]></category>

		<category><![CDATA[hack]]></category>

		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://rcoder.net/?p=221</guid>
		<description><![CDATA[Anyone who&#8217;s done much Ruby metaprogramming (or even just skimmed the source code to Rails) should be intimately familiar with the following idiom:
klass = Foo::Bar
# ...
klass.extend(Some::Module)
This is a programmatic mixin &#8212; it adds the methods defined in Some::Module to the class Foo::Bar for the duration of the current Ruby process. It also does so for [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone who&#8217;s done much Ruby metaprogramming (or even just skimmed the source code to Rails) should be intimately familiar with the following idiom:</p>
<pre>klass = Foo::Bar
# ...
klass.extend(Some::Module)</pre>
<p>This is a programmatic mixin &#8212; it adds the methods defined in <code>Some::Module</code> to the class <code>Foo::Bar</code> for the duration of the current Ruby process. It also does so for <em>all</em> instances of <code>Foo::Bar</code>, whether defined in some scope known to the caller of <code>extend</code> or not.</p>
<p>If may not look like it, but this is yet another case of <a href="http://en.wikipedia.org/wiki/Monkey_patch">monkeypatching</a>. The only reason you don&#8217;t see it being denounced up and down the &#8216;tubes like, say, <a href="http://rcoder.net/content/monkeypatching-sometimes-considered-harmful">overriding <code>method_missing</code> on <code>NilClass</code></a> is that it&#8217;s usually confined to an application or framework-specific class, like <code>ActiveRecord::Base</code>.</p>
<p>Now, I&#8217;m all for the judicious use of powerful language constructs like open classes, but they can be a problem for large-scale projects, or those where collaboration between team members is less-than-perfect. The global and persistent scope of a class-level <code>#extend</code> call like the above can cause unexpected side-effects, too.</p>
<p>As an alternative, I humbly propose the use of instance-scoped extensions. In cases where not all instances of a class may need the additional functionality provided by the mixin, try calling <code>#extend</code> on <em>just that instance</em>. It keeps your namespace clean, doesn&#8217;t introduce as many potential pitfalls for code in other scopes, and is reversible: just <code>nil</code> your current reference to the object, and re-create it without the mixin.</p>
<p>Here&#8217;s an example, cribbed from some refactoring I&#8217;m doing of a web service implementation:</p>
<pre>def change_password
  token = AuthToken.find(params[:token])
  active_user = Account.find(token.identity)
  password = params[:password]

  raise ArgumentError, "passwords did not match" unless password = params[:confirm_password]

  if token.has_privilege?(:password_reset)
    active_user.extend(PrincipalManagement)
    active_user.change_password(password)
  end

  render :xml =&gt; Account.to_xml
end</pre>
<p>One reason this is expecially handy for me is that I can re-use the same model core model classes (like <code>Account</code>) in different applications, only some of which may have the privileges necessary to change passwords, delete accounts, etc.</p>
<p>By limiting the mixin to a single model instance within the scope of a single request, I also protect myself from coding errors that might expose dangerous mutators to untrusted callers. Any attempt to call <code>change_password</code> (or a similarly-restricted method) from outside a scope which explicitly included the mixin will raise a <code>MethodNotFound</code> error, without any additional access-control checks on my part.</p>
]]></content:encoded>
			<wfw:commentRss>http://rcoder.net/content/mixins-without-monkeypatching/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
