<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Josh Staiger</title>
<link>http://www.joshstaiger.org/</link>
<description>My name is Josh Staiger and this is my personal website. Here I write about whatever happens to interest me at the moment, including technical matters on occasion.</description>
<language>en-us</language>
<copyright>Copyright 2008</copyright>
<lastBuildDate>Mon, 30 Apr 2007 23:25:36 -0500</lastBuildDate>
<pubDate>Tue, 13 May 2008 07:07:23 -0500</pubDate>
<generator>http://www.movabletype.org/?v=3.15</generator>
<docs>http://blogs.law.harvard.edu/tech/rss</docs> 

<item>
<title>Reboot</title>
<description><![CDATA[<p><a href="http://www.flickr.com/photos/joshstaiger/147349438/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/49/147349438_d818250e7a_m.jpg" width="180" height="240" alt="san_francisco129.jpg" /></a></p>

<p>I apologize if I've been distant lately;  right now I'm in the process of rebooting my life.</p>

<p>Friday will be my last day with IBM.  </p>

<p>Over the next few weeks I'll be relocating to the Bay Area to work for <a href="http://google.com">Google</a>.  </p>]]></description>
<link>http://www.joshstaiger.org/archives/2007/04/reboot.html</link>
<guid>http://www.joshstaiger.org/archives/2007/04/reboot.html</guid>
<category>General</category>
<pubDate>Mon, 30 Apr 2007 23:25:36 -0500</pubDate>
</item>
<item>
<title>Jazz.net goes live</title>
<description><![CDATA[<p><a href="http://www.flickr.com/photos/joshstaiger/184750146/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/56/184750146_eee0279136_m.jpg" width="240" height="154" alt="paris.jpg" /></a></p>

<p>If you'd like a peek at what I've been up to at work for the past eight months, head over to <a href="http://jazz.net">jazz.net</a>, which just went live.</p>

<p>The details are still kinda sketchy, but expect more real soon now :)</p>]]></description>
<link>http://www.joshstaiger.org/archives/2007/02/jazznet_goes_li.html</link>
<guid>http://www.joshstaiger.org/archives/2007/02/jazznet_goes_li.html</guid>
<category>Technology and Software</category>
<pubDate>Wed, 07 Feb 2007 23:44:00 -0500</pubDate>
</item>
<item>
<title>Eclipse is a dead system</title>
<description><![CDATA[<p><a href="http://www.flickr.com/photos/joshstaiger/47349364/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/27/47349364_55d2402904_m.jpg" width="240" height="160" alt="dead_fish.jpg" /></a></p>

<p>(<a href="/images/DontPanic_1024.jpg">DON'T PANIC!</a> I probably don't mean what you think I mean.)</p>

<p><em>On a long enough timeline, the survival rate for everyone <a href="http://www.theonion.com/content/node/39236">drops to zero</a>.</em></p>

<p>Steve Yegge has a thought-provoking essay on <a href="http://steve-yegge.blogspot.com/2007/01/pinocchio-problem.html">living systems vs. dead systems</a>, in essence: systems that can be modified at runtime vs. systems that you have to stop (kill) first to modify.</p>

<p>In this context <a href="http://www.eclipse.org/">Eclipse</a> is a "dead system" (or "hardware" as Stevey says).  And this makes me sad :(  </p>

<p>In fact, it's saddened me for a while, though I've never framed the issue in these terms.</p>

<p>Even though Eclipse has a <a href="http://www.eclipse.org/equinox/">world-class extension system</a>, we have to go through an onerous process of launching and relaunching Eclipse instances to make the slightest change to a plugin.</p>

<p>In contrast, a "living" system like Emacs doesn't have this problem.  In Emacs we can evaluate s-expression, set variables, rewrite functions, and swap code on the fly without having to relaunch - which is why writing Emacs extensions is an order of magnitude easier (and more fun) than writing Eclipse extensions.</p>

<p>Stevey also draws a parallel between how long a system can stay running without reboot, and how long people will continue to use the system.</p>

<p>*shrug*</p>

<p>I think it has more to do with how close your system gets to hitting the best solutions to the problems people are trying to solve on any given day.  But here's the thing: the problems of today aren't necessarily the problems of tomorrow, nor the problems of ten years from now.</p>

<p>The more malleable your system is, the better its chance of solving the problems of 2007, <em>and</em> 2008, <em>and</em> 2017, <em>and</em> 2027.  And as it happens, systems that can be modified without a reboot are <em>much</em> easier to modify and <em>far</em> more malleable than systems that can't.</p>

<p>Eclipse has many advantages over Emacs (mostly in terms of gooeyness), but as ugly as Emacs looks on the outside, it's definitely the more malleable of the two.  So, if I had to choose pick which one is more likely to be around in 100 years, my money would be on Emacs.  And if history is any guide, that's probably <a href="ttp://en.wikipedia.org/wiki/Emacs">not a bad bet</a>. </p>

<p>UPDATE:  </p>

<p>Hehe, as Bill points out in the comments, I do feel like kind of a <a href="http://www.joshstaiger.org/archives/2007/01/eclipse_is_a_de_1.html#comment803">bastard</a> for writing this post (especially the inflammatory title).  But my aim  isn't to disparage Eclipse.  I love Eclipse.  It's a great platform, and it's very good at what it does.  </p>

<p>And no... it's certainly not "dying" :)</p>

<p>My aim is to point out that there are other kinds of extensibility out there that we don't typically get with Eclipse... at least not <em>right now</em>, and it's the kind of extensibility I'd very much like to see.</p>

<p>And just for full disclosure, I <a href="http://www.joshstaiger.org/about/">work for the company</a> that originally founded the <a href="http://en.wikipedia.org/wiki/Eclipse_%28software%29">Eclipse project</a>.  All views expressed here are my own and not those of my employer.</p>]]></description>
<link>http://www.joshstaiger.org/archives/2007/01/eclipse_is_a_de_1.html</link>
<guid>http://www.joshstaiger.org/archives/2007/01/eclipse_is_a_de_1.html</guid>
<category>Technology and Software</category>
<pubDate>Thu, 18 Jan 2007 18:05:53 -0500</pubDate>
</item>
<item>
<title>Raleigh bloggers meetup tonight @ Helios Coffee</title>
<description><![CDATA[<p>Though it's been a while since I've advertised it here, the Raleigh area blog meetup is still going strong.</p>

<p>We meet twice a month:  the first and third Tuesday, 6:30PM at the <a href="http://www.helioscoffee.com/frames.htm">Helios Coffee Company</a>.</p>

<p>Details at the <a href="http://joshstaiger.org/raleighbloggers/index.php?title=Main_Page">wiki</a>.</p>

<p>Tonight will be our first meetup of the year.  If you live in Raleigh or around Raleigh, please join us!  I'd love to meet you in person.</p>

<p>(<a href="http://rollerweblogger.org/roller/entry/raleigh_blogger_meetup_tuesday_at">Dave</a> even has Helios photos)</p>]]></description>
<link>http://www.joshstaiger.org/archives/2007/01/raleigh_blog_me_4.html</link>
<guid>http://www.joshstaiger.org/archives/2007/01/raleigh_blog_me_4.html</guid>
<category>Blogging</category>
<pubDate>Tue, 16 Jan 2007 09:00:42 -0500</pubDate>
</item>
<item>
<title>links for 2007-01-16</title>
<description><![CDATA[<ul class="delicious">
	<li>
		<div class="delicious-link"><a href="http://blog.outer-court.com/archive/2007-01-14-n21.html">Details of Google's Latest Security Hole</a></div>
		<div class="delicious-extended">"I was able to create a page that was hosted on a google.com domain, which is something that should never be allowed to happen."</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/google">google</a> <a href="http://del.icio.us/joshstaiger/security">security</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://blog.whatfettle.com/2007/01/11/good-web-apis-are-just-web-sites/">Paul Downey » Blog Archive » Web APIs Are Just Web Sites</a></div>
		<div class="delicious-extended">A great "nutshell" overview of writing a RESTful web service.</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/web">web</a> <a href="http://del.icio.us/joshstaiger/http">http</a> <a href="http://del.icio.us/joshstaiger/rest">rest</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://ftrain.com/trope-guilty-pleasure.html">Trope (Ftrain.com)</a></div>
		<div class="delicious-extended">"Justin Timberlake is not a guilty pleasure. Putting oven cleaner in your daughter's Similac is a guilty pleasure, or smearing birdseed on your balls and visiting an aviary."</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/humor">humor</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://www.stampandshout.com/shop/bumper-stickers/we-have-fossils.php">We Have Fossils Bumper Sticker</a></div>
		<div class="delicious-extended">Yay for Darwin :D</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/sience">sience</a> <a href="http://del.icio.us/joshstaiger/evolution">evolution</a> <a href="http://del.icio.us/joshstaiger/humor">humor</a> <a href="http://del.icio.us/joshstaiger/religion">religion</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://smg.photobucket.com/albums/v141/jumaduke/notmykids.jpg">notmykids.jpg</a></div>
		<div class="delicious-extended"> Why You Shouldn't Leave A Gallon Of Paint With Unsupervised Toddlers</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/humor">humor</a> <a href="http://del.icio.us/joshstaiger/photos">photos</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://englishrussia.com/?p=575">PDA, Cellphone and Laptop 90 Years Ago</a></div>
		<div class="delicious-extended">It can be clearly seen that Communist’s coup was so successfull due to the help of time travelers who had come from the future equipped with PDAs, cell phones and laptops.</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/humor">humor</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://weblog.raganwald.com/2006/10/why-are-local-variables-bad.html">Raganwald: Why are local variables bad?</a></div>
		<div class="delicious-extended">This is a blog post I've been wanting to write for a while.</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/programming">programming</a> <a href="http://del.icio.us/joshstaiger/functional">functional</a>)</div>
	</li>
</ul>
]]></description>
<link>http://www.joshstaiger.org/archives/2007/01/links_for_20070_1.html</link>
<guid>http://www.joshstaiger.org/archives/2007/01/links_for_20070_1.html</guid>
<category></category>
<pubDate>Tue, 16 Jan 2007 00:29:26 -0500</pubDate>
</item>
<item>
<title>How to install bzr on Dreamhost</title>
<description><![CDATA[<a href="http://www.flickr.com/photos/joshstaiger/273593468/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/116/273593468_46f543cdec_m.jpg" width="160" height="240" alt="hot_dog_stand_05.jpg" /></a>

<p><a href="http://bazaar-vcs.org/">Bazaar</a> or <code>bzr</code> is a Python-based source code management system that I've noticed is becoming increasingly popular amongst small open-source projects.</p>

<p>Right now I'm not sure what advantages <code>bzr</code> might have over other SCM systems such as Subversion (I suspect it's more light-weight), but it's handy to have when you want to grab the source for a project like <a href="http://intertwingly.net/code/venus/">Planet Venus</a>.</p>

<p>Here's how I installed <code>bzr</code> on my <a href="http://www.dreamhost.com/rewards.cgi?joshstaiger">Dreamhost</a> shell account.</p>

<p>(note: There's not anything special here.  This is all pretty standard Unix tarball installation fair.  In fact, there's little here that isn't already in the <code>bzr</code> installation guide.  I'm providing this as a confidence cushion for other Dreamhost users.)</p>

<h4>Fetch it</h4>

<p>Downloads of <code>bzr</code> are available here: <a href="http://bazaar-vcs.org/Download">http://bazaar-vcs.org/Download</a></p>

<p>Fetch the tarball install into a directory of your choice:</p>

<pre class="code">
~$ cd ~/incoming
~/incoming$ wget http://bazaar-vcs.org/releases/src/bzr-0.13.tar.gz
</pre>

<h4>Unzip it</h4>

<pre class="code">
~/incoming$ tar -zxvf bzr-0.13.tar.gz
</pre>

<h4>Install it</h4>

<pre class="code">
~/incoming$ cd bzr-0.13
~/incoming/bzr-0.13$ python2.4 setup.py install --home ~
</pre>

<p>No problem...</p>

<h4>Adjust environmental variables</h4>

<p>... except one hiccup when we try to run <code>bzr</code>:</p>

<pre class="code">
$ bzr
bzr: ERROR: Couldn't import bzrlib and dependencies.
Please check bzrlib is on your PYTHONPATH.

Traceback (most recent call last):
  File "/home/joshstaiger/bin/bzr", line 62, in ?
    import bzrlib
ImportError: No module named bzrlib
</pre>

<p>Because we installed <code>bzr</code> in our home directory, the Python code behind <code>bzr</code> is living in a nonstandard location that Python can't see.  We add this location to our Python library path by setting the <code>PYTHONPATH</code> environmental variable in our <code>.bashrc</code>.</p>

<p>Modify <code>.bashrc</code> as follows:</p>

<pre class="code">
echo "export PYTHONPATH=/home/joshstaiger/lib/python" >> ~/.bashrc
</pre>

<p>(replace "joshstaiger" with your shell login name)</p>

<p>We'll also want the <code>bzr</code> manual to be in our <code>MANPATH</code> if it isn't already, so we can read about <code>bzr</code> in our spare time instead of picking up women:</p>

<pre class="code">
echo 'export MANPATH=$MANPATH:/home/joshstaiger/man' >> ~/.bashrc
</pre>

<p>Source .bashrc (or relogin) to pick up our changes:</p>

<pre class="code">
. ~/.bashrc
</pre>

<h4>Run it</h4>

And we're set:

<pre class="code">
~$ bzr
Bazaar -- a free distributed version-control tool
http://bazaar-vcs.org/

Basic commands:

  bzr init           makes this directory a versioned branch
  bzr branch         make a copy of another branch

  bzr add            make files or directories versioned
  bzr ignore         ignore a file or pattern
  bzr mv             move or rename a versioned file

  bzr status         summarize changes in working copy
  bzr diff           show detailed diffs

  bzr merge          pull in changes from another branch
  bzr commit         save some or all changes

  bzr log            show history of changes
  bzr check          validate storage

  bzr help init      more help on e.g. init command
  bzr help commands  list all commands
  bzr help topics    list all help topics
</pre>
]]></description>
<link>http://www.joshstaiger.org/archives/2007/01/bzr_on_dreamhos.html</link>
<guid>http://www.joshstaiger.org/archives/2007/01/bzr_on_dreamhos.html</guid>
<category>Technology and Software</category>
<pubDate>Mon, 15 Jan 2007 22:54:47 -0500</pubDate>
</item>
<item>
<title>links for 2007-01-13</title>
<description><![CDATA[<ul class="delicious">
	<li>
		<div class="delicious-link"><a href="http://scarletlambda.org/">hello, world. meet scarlet.</a></div>
		<div class="delicious-extended">ecdysis: a lisp-like syntax for python</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/programming">programming</a> <a href="http://del.icio.us/joshstaiger/python">python</a> <a href="http://del.icio.us/joshstaiger/lisp">lisp</a> <a href="http://del.icio.us/joshstaiger/webdev">webdev</a> <a href="http://del.icio.us/joshstaiger/web">web</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://withoutane.com/rants/2007/what-python-looks-like-naked">without an e: What python looks like naked [01/10/2007 14:35:29]</a></div>
		<div class="delicious-extended">"Although this code is ugly, writing it gave me a feel for the real power of a language like lisp."</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/python">python</a> <a href="http://del.icio.us/joshstaiger/programming">programming</a> <a href="http://del.icio.us/joshstaiger/computerScience">computerScience</a> <a href="http://del.icio.us/joshstaiger/functional">functional</a> <a href="http://del.icio.us/joshstaiger/lambda">lambda</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://blog.outer-court.com/archive/2007-01-12-n73.html">Google Security Hole Allows Account Hijacking</a></div>
		<div class="delicious-extended">all Tony needed to do was make a user who&rsquo;s logged into their Google Account visit a page of his, which happened to be on a &ldquo;trustworthy&rdquo; google.com sub-domain</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/google">google</a> <a href="http://del.icio.us/joshstaiger/security">security</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://webkit.org/blog/?p=88">Surfin&rsquo; Safari - Blog Archive &raquo; CSS3 Multi-Column Support</a></div>
		<div class="delicious-extended">WebKit now has some very basic support for multiple columns from CSS3.</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/webdesign">webdesign</a> <a href="http://del.icio.us/joshstaiger/webdev">webdev</a> <a href="http://del.icio.us/joshstaiger/css">css</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://www.applegazette.com/weird/steven-colbert-flacid-with-rage-over-iphone/">  Stephen Colbert &ldquo;Flaccid with Rage&rdquo; over iPhone by Apple Gazette</a></div>
		<div class="delicious-extended">The iPhone has given the nerd community it's hardest collective wood since Princess Leia wore a bronze bikini.</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/mac">mac</a> <a href="http://del.icio.us/joshstaiger/iPhone">iPhone</a> <a href="http://del.icio.us/joshstaiger/Humor">Humor</a> <a href="http://del.icio.us/joshstaiger/Video">Video</a>)</div>
	</li>
	<li>
		<div class="delicious-link"><a href="http://freenet-homepage.de/schnubelken/bunnys/">Bunny suicides</a></div>
		<div class="delicious-extended">Ripped from Andy Riley's excellent "The Book of Bunny Suicides" and "Return of the Bunny Suicides".</div>
		<div class="delicious-tags">(tags: <a href="http://del.icio.us/joshstaiger/cartoon">cartoon</a> <a href="http://del.icio.us/joshstaiger/humor">humor</a> <a href="http://del.icio.us/joshstaiger/cute">cute</a>)</div>
	</li>
</ul>
]]></description>
<link>http://www.joshstaiger.org/archives/2007/01/links_for_20070.html</link>
<guid>http://www.joshstaiger.org/archives/2007/01/links_for_20070.html</guid>
<category>General</category>
<pubDate>Sat, 13 Jan 2007 23:29:04 -0500</pubDate>
</item>
<item>
<title>The iPhone is NOT a platform</title>
<description><![CDATA[<p><a href="http://www.flickr.com/photos/joshstaiger/284232682/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/121/284232682_a136530f48_m.jpg" width="240" height="160" alt="apple-store-times-square-02.jpg" /></a></p>

<p>Ok, I was wrong.</p>

<p>Looks like they <em>will</em> be fighting us <a href="http://rollerweblogger.org/roller/entry/iphone_don_t_think_of">every step of the way</a>.</p>

<p>*shrug*</p>

<p>Steve just lost my willingness to give him $599 and put my balls in a vice grip with his carrier (which I otherwise would have done gladly, just to play in the new sandbox).</p>

<p>I will, however, continue to write webapps that <em>incidentally</em> work well on his phone, safe in the knowledge they'll no longer have to be crippled to be mobile.</p>]]></description>
<link>http://www.joshstaiger.org/archives/2007/01/the_iphone_is_n.html</link>
<guid>http://www.joshstaiger.org/archives/2007/01/the_iphone_is_n.html</guid>
<category>Technology and Software</category>
<pubDate>Fri, 12 Jan 2007 03:51:03 -0500</pubDate>
</item>
<item>
<title>The iPhone as a platform</title>
<description><![CDATA[<p><a href="http://www.flickr.com/photos/joshstaiger/284232979/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/116/284232979_dcb1375e8f_m.jpg" width="240" height="160" alt="apple-store-times-square-07.jpg" /></a></p>

<p>Tonight, every nerd I know is salivating over the <a href="http://www.apple.com/iphone/">iPhone</a>.</p>

<p>Obviously people are <a href="http://stevenf.com/2007/01/a_special_post_live_from_macworld.php">orgasmic</a> over the sexyness: the form-factor, the fluid touch-screen, the (for serious!) smart calling software, the media apps, and the internet connectivity.</p>

<p>But I think the real story here is we finally have a <em>real</em> platform for mobile application development, complete with <em>real</em> OS, <em>real</em> apis, and a <em>real</em> web browser capable of running <em>real</em> web applications - all delivered by a company that <em>isn't</em> going to fight us every step of the way.</p>

<p>And the sexyness ensures it's going to be <em>very</em> popular.  </p>

<p>It almost sounds like the mobile platform we've been waiting for for the past ten years!</p>

<p>This is going to be big :)</p>]]></description>
<link>http://www.joshstaiger.org/archives/2007/01/the_iphone_as_a.html</link>
<guid>http://www.joshstaiger.org/archives/2007/01/the_iphone_as_a.html</guid>
<category>Technology and Software</category>
<pubDate>Tue, 09 Jan 2007 21:47:48 -0500</pubDate>
</item>
<item>
<title>Metaprogramming method closures in Ruby</title>
<description><![CDATA[<a href="http://www.flickr.com/photos/joshstaiger/251935422/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/85/251935422_912ba7eaf7_m.jpg" width="240" height="180" alt="night01.jpg" /></a>

<p>In my previous post, <a href="http://www.joshstaiger.org/archives/2006/12/of_closures_met_1.html">Of Closures, methods, procs, scope, and Ruby</a>, I discussed how blocks and procs are <a href="http://en.wikipedia.org/wiki/Closure_(computer_science)">closures</a> in Ruby while methods are not.</p>

<p>To review, this won't work:</p>

<pre class="code">
class MyClass
    @friend

    hello_string = "Hello"

    def initialize
        @friend = "Kitty"
    end

    def say_hello
        puts hello_string + " " + @friend  # Bzzt!  hello_string is not in scope
    end
end

my_object = MyClass.new

my_object.say_hello # Bzzt!
</pre>

<p>And neither will this (at the toplevel):</p>

<pre class="code">
hello_string = "Hello, world!"

def say_hello
    puts hello_string  # Bzzt!  hello_string is not in scope
end

say_hello # Bzzt!
</pre>

<p>In response <a href="http://www.joshstaiger.org/archives/2006/12/of_closures_met_1.html#comment758">Kurt hypothesized</a> we could get method closures in Ruby with a bit of metaprogramming.</p>

<p>And he's right.</p>

<p>As <a href="http://www.joshstaiger.org/archives/2006/12/of_closures_met_1.html#comment760">Bryce points out</a>, Ruby's <code>Module</code> class has a private method nammed <code>define_method</code> that defines a new method given a symbol representing its name, and a block representing its body.</p>

<p>Because the second parameter is a block, and blocks can be closures, this gives us the key to defining method closures.</p>

<p>Within the context of a class definition:</p>

<pre class="code">
class MyClass
    @friend
    hello_string = "Hello"

    def initialize
        @friend = "Kitty"
    end

    define_method(:say_hello) { puts hello_string + " " + @friend }
end

my_object = MyClass.new  

my_object.say_hello # Hello Kitty
</pre>

<p>Yay!</p>

<p>But suppose we want to define one-off methods from the top-level instead.</p>

<p>Because <code>define_method</code> is private, normally we wouldn't be able to call it outside a class definition, but we can get around this using the <a href="http://www.joshstaiger.org/archives/2006/12/the_ruby_send_h.html">send hack</a>.</p>

<p>Let's define a convenience method:</p>

<pre class="code">
def lexdef(method_symbol, &block) 
    self.class.send :define_method, method_symbol, &block
end
</pre>

<p>And now we can define method closures from the toplevel:</p>

<pre class="code">
hello_string = "Hello"

lexdef :say_hello do |friend|
    puts hello_string + " " + friend
end

say_hello "Kitty" # Hello Kitty
</pre>

<p>Voil&agrave;!  An unobtrusive syntax for defining method closures!</p>

<p>I like it :)</p>

<p>As of Ruby 1.8, blocks don't yet support Ruby's first-class syntax for receiving block arguments.  So this won't work:</p>

<pre class="code">
hello_string = "Hello"

lexdef :say_hello do |friend, &formalize|   # Bzzt!  Syntax error
    puts hello_string + " " + yield(friend)
end

say_hello("Kitty") { |friend| "Ms. " + friend }
</pre>

<p>But <a href="http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l11">word on the street</a> is &block arguments to blocks <em>will</em> be supported in Ruby 1.9.</p>]]></description>
<link>http://www.joshstaiger.org/archives/2006/12/metaprogramming.html</link>
<guid>http://www.joshstaiger.org/archives/2006/12/metaprogramming.html</guid>
<category>Technology and Software</category>
<pubDate>Fri, 29 Dec 2006 18:34:05 -0500</pubDate>
</item>
<item>
<title>The Ruby send hack: how to gain access to an object&apos;s privates</title>
<description><![CDATA[<a href="http://www.flickr.com/photos/joshstaiger/241157627/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/92/241157627_5923f9faeb_m.jpg" width="240" height="180" alt="lady_liberty01.jpg" /></a>

<p>I stumbled across an interesting Ruby hack that doesn't seem to be written down anywhere.</p>

<p>It turns out that private methods in Ruby aren't entirely private, and with a bit of indirection you can gain access to them as though they were public methods.</p>

<p>In Ruby 1.8 all we have to do is use the <code>Object#send</code> method.</p>

<p>To demonstrate:</p>

<pre class="code">
class MyClass
    private
    def say_hello(name)
        puts "Let's go back to my place, #{name}."
    end
end

my_object = MyClass.new
</pre>

So we get smacked if we try:

<pre class="code">&gt; my_object.say_hello
Nomethoderror: private method `say_hello' called for #&lt;MyClass:0x820b4&gt;
	from (irb):8
	from :0</pre>

but instead:

<pre class="code">&gt; my_object.send :say_hello, "world"
Let's go back to my place, world.</pre>

<p>Touch&eacute;!</p>

<p>Now, honestly, this strikes me as odd.  Conceptually, I don't see why <code>send</code> should function differently from an ordinary method call with respect to access control.</p>

<p>The <a href="http://www.rubycentral.com/book/ref_c_object.html#Object.send">rubydoc for <code>send</code></a> says nothing of this, and there is <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/7404">some debate on the mailinglist</a> as to whether Ruby 1.9's <code>send</code> will maintain this behavior.</p>

<p>But for now this can be very useful if you disagree with a class designer's method access choices.</p>]]></description>
<link>http://www.joshstaiger.org/archives/2006/12/the_ruby_send_h.html</link>
<guid>http://www.joshstaiger.org/archives/2006/12/the_ruby_send_h.html</guid>
<category>Technology and Software</category>
<pubDate>Thu, 28 Dec 2006 13:06:06 -0500</pubDate>
</item>
<item>
<title>Of closures, methods, procs, scope, and Ruby</title>
<description><![CDATA[<p><a href="http://www.flickr.com/photos/joshstaiger/285083229/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/122/285083229_12a8a33efb_m.jpg" width="160" height="240" alt="giant-piano-06.jpg" /></a></p>

<p>One thing I hate about Ruby is that Ruby methods aren't <a href="http://en.wikipedia.org/wiki/Closure_(computer_science)">closures</a>.</p>

<p>For instance, this blows up:</p>

<pre class="code">hello_string = "Hello, world!\n"

def say_hello
    puts hello_string # bzzt! hello_string isn't in scope
end

say_hello # bzzt!</pre>

<p>Which is a little odd because Ruby <em>does</em> support closures on procs:</p>

<pre class="code">hello_string = "Hello, world!\n"

say_hello = Proc.new do
    puts hello_string
end

say_hello.call # Hello, world!</pre>

<p>It kinda sucks that every time I want to create a closure I'm forced to use the less succinct ".call" syntax.</p>

<p>So why can procs be closures while methods cannot?</p>

<p>After a bit of thinking I realized this comes down to a design tradeoff on whether or not we have to type "self" or "this" all over the place when writing methods as we do in Python and JavaScript.</p>

<p>In Ruby we <em>don't</em> have to do this, and Ruby accomplishes this by making procs and methods two different things with different scoping rules.</p>

<p>Proc bodies have a <a href="http://en.wikipedia.org/wiki/Scope_(programming)#Static_scoping">lexical scope</a> like functions in Lisp and JavaScript, meaning that when Ruby encounters a <a href="http://en.wikipedia.org/wiki/Free_variables_and_bound_variables">free variable</a> inside a proc body, its value is resolved within the context the proc was defined.  This is what makes closures possible.</p>

<p>Methods are different, however.  A method's context is the object to which they are bound.  When Ruby encounters a free variable inside a method body, it assumes the variable refers to another method on the object, and this is what saves us from having to prefix same-object methods with "this" or "self".</p>

<p>To demonstrate:</p>

<pre class="code">irb(main):171:0> hello_string = "Hello, world!"
=> "Hello, world!"
irb(main):172:0> def say_hello
irb(main):173:1>     puts hello_string
irb(main):174:1> end
=> nil
irb(main):175:0> say_hello
NameError: undefined local variable or method `hello_string' for #<Object:0x359e4>
	from (irb):173:in `say_hello'
	from (irb):175
	from :0
irb(main):176:0> def hello_string
irb(main):177:1>     "Hello, world!"
irb(main):178:1> end
=> nil
irb(main):179:0> say_hello
Hello, world!
=> nil</pre>

<p>Personally, I'm not sure I like this tradeoff.</p>

<p>Procs and methods are conceptually very similar.  They are both composed of a list of arguments, a block of code, and a context in which the block is evaluated.  I'm not sure they should be different things.</p>

<p>The way I see it, a method should just be a special case of proc that happens to have an implicit "self" parameter.  In this case methods would inherit the proc scoping rules and therefore <em>could</em> be used as closures.</p>

<p>If this means we have to be verbose and type "self" to call other methods on the same object, I'm fine with that.</p>

<p>And in fact, this is how things work in JavaScript:</p>

<pre class="code">var helloString = "Hello";

var myObject = { 
    friend: "Kitty",
    sayHello: function() { 
        print(helloString + " " + this.friend);
    }
};

myObject.sayHello(); // Hello Kitty</pre>

<p>Matz clearly <a href="http://www.rubyist.net/~matz/slides/rc2003/mgp00010.html">recognizes</a> that there are issues with Ruby's current scoping implementation, so maybe this is one of them.</p>

<p>But, hey, this kind of tradeoff may just be a Rubyish thing to do, and I probably dig closures more than most.</p>]]></description>
<link>http://www.joshstaiger.org/archives/2006/12/of_closures_met_1.html</link>
<guid>http://www.joshstaiger.org/archives/2006/12/of_closures_met_1.html</guid>
<category>Technology and Software</category>
<pubDate>Tue, 26 Dec 2006 17:54:08 -0500</pubDate>
</item>
<item>
<title>Real life search</title>
<description><![CDATA[<p>I love how whenever I lose something in my house, my first instinct is:</p>

<p><em>Oh, no problem.  I'll just do a search.</em></p>

<p>And a short instant later...</p>

<p><em>Goddammit!</em></p>]]></description>
<link>http://www.joshstaiger.org/archives/2006/12/real_life_searc.html</link>
<guid>http://www.joshstaiger.org/archives/2006/12/real_life_searc.html</guid>
<category>Technology and Software</category>
<pubDate>Wed, 20 Dec 2006 20:39:03 -0500</pubDate>
</item>
<item>
<title>Five things you didn&apos;t know about me</title>
<description><![CDATA[<p><a href="http://www.flickr.com/photos/joshstaiger/74323959/" title="Photo Sharing"><img src="http://static.flickr.com/38/74323959_1a72092a81_m.jpg" width="240" height="180" alt="starfish_dance01.jpg" /></a></p>

<p>There's a massive game of tag going around the blogosphere. I've been tagged by <a href="http://www-03.ibm.com/developerworks/blogs/page/BillHiggins?entry=five_things">Bill</a> and <a href="http://rollerweblogger.org/roller/entry/five_things">Dave</a>.</p>

<p>So here goes.  Five things you didn't know about me:</p>

<ol>
<li>I all but gave up Computer Science in favor of law my junior year of college.  I even convinced my friend <a href="http://evanperry.org/">Evan</a> to do the same... except he actually did :)</li>
<li>I've been to London, Paris, Amsterdam, and Zurich, but only set foot west of the Mississippi in <a href="http://www.joshstaiger.org/archives/2006/05/my_trip_to_cali_1.html">May of this year</a>.</li>
<li>I scored higher on the language portion of the SAT than the math portion.</li>
<li>I play piano.</li>
<li>I've been skydiving... <em>twice</em>.</li>
</ol>

<p>I tag <a href="http://www.ryanirelan.com/">Ryan</a>, <a href="http://uncledirtae.vox.com/">Jeff</a>, <a href="http://kurtiss.org/">Kurt</a>, <a href="http://www.vinnie.net/">Vinnie</a>, and <a href="http://mistersugar.com/">Anton</a>.</p>]]></description>
<link>http://www.joshstaiger.org/archives/2006/12/five_things_you.html</link>
<guid>http://www.joshstaiger.org/archives/2006/12/five_things_you.html</guid>
<category>Matters that are otherwise worthwhile</category>
<pubDate>Mon, 18 Dec 2006 22:30:31 -0500</pubDate>
</item>
<item>
<title>On Variable Naming in Code</title>
<description><![CDATA[<p><a href="http://www.flickr.com/photos/joshstaiger/261107921/" title="Photo Sharing"><img src="http://static.flickr.com/89/261107921_1f988e31ce_m.jpg" width="160" height="240" alt="night" /></a></p>

<p>Much is made of the pain of typing long variable names (or function names or class names), but code is usually read more often than it's typed. And when I'm reading code (even if it's my own), I'm grateful for names that err on the side of descriptiveness.</p>

<p>This means:</p>

<ul>
<li><code>navigationElement</code> instead of <code>navigation</code> or <code>nav</code></li>
<li><code>queryString</code> instead of <code>query</code>, <code>queryStr</code>, <code>string</code>, or <code>str</code></li>
<li><code>libraryLookupUrl</code> instead of <code>libraryLookup</code> or <code>url</code>
</ul>

<p>The exceptions are common language idioms which any programmer could reasonably be expected to know (ie: cons in Lisp, def in Python, x as an index into array loops). These should be abbreviated as their meaning is more intrinsic and independent of the name.</p>]]></description>
<link>http://www.joshstaiger.org/archives/2006/12/on_variable_nam.html</link>
<guid>http://www.joshstaiger.org/archives/2006/12/on_variable_nam.html</guid>
<category>Technology and Software</category>
<pubDate>Fri, 15 Dec 2006 08:37:30 -0500</pubDate>
</item>


</channel>
</rss>