<?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>Joshua Lockwood&#039;s Blog</title>
	<atom:link href="http://lostechies.com/joshualockwood/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/joshualockwood</link>
	<description>Just another LosTechies site</description>
	<lastBuildDate>Thu, 29 Oct 2009 00:55:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Did you mamma raise you in a barn?</title>
		<link>http://lostechies.com/joshualockwood/2009/10/29/did-you-mamma-raise-you-in-a-barn/</link>
		<comments>http://lostechies.com/joshualockwood/2009/10/29/did-you-mamma-raise-you-in-a-barn/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 00:55:00 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2009/10/28/did-you-mamma-raise-you-in-a-barn.aspx</guid>
		<description><![CDATA[That&#8217;s a question that I was confronted with numerous times while in the Army.&#160; I was always irritated and refused to use it myself when I because a non-commissioned officer because I found it a bit ridiculous (apparently barn-raised children&#160;&#8230; <a href="http://lostechies.com/joshualockwood/2009/10/29/did-you-mamma-raise-you-in-a-barn/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s a question that I was confronted with numerous times while in the Army.&nbsp; I was always irritated and refused to use it myself when I because a non-commissioned officer because I found it a bit ridiculous (apparently barn-raised children aren&#8217;t careful to roll their t-shirts in 6-inch rolls, fail to catch scuff marks in polished floors, leave dirt in the rifle&#8217;s forward sights, etc).&nbsp; Lately, however, I&#8217;ve asked that question repeatedly to long-gone coders while working on their large legacy system.&nbsp; I&#8217;m puzzled by the degree to which obsolete code has been left in the code base.&nbsp; I&#8217;ve coined the phrase &#8220;Found another finger bone on a whale&#8221; to express just how bewildering it is to find various vestigial oddities while attempting to tame legacy software systems.</p>
<p>As I accrue experience in repairing and improving legacy systems I find myself approaching code-cleaning efforts with increasing urgency.&nbsp; Many developers seem to understand the value of producing well-formatted and organized code, but it seems few comprehend the danger keeping unused code.&nbsp; This is especially true when your system heavily uses reflection and declarative code.</p>
<p>&ldquo;Code <em>is your house</em>, and you must live in it.&rdquo; &#8211; Michael Feathers</p>
<p>As I accrue more experience</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2009/10/29/did-you-mamma-raise-you-in-a-barn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting my dual display setup to work on Ubuntu 9.0.4</title>
		<link>http://lostechies.com/joshualockwood/2009/09/23/getting-my-dual-display-setup-to-work-on-ubuntu-9-0-4/</link>
		<comments>http://lostechies.com/joshualockwood/2009/09/23/getting-my-dual-display-setup-to-work-on-ubuntu-9-0-4/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 15:59:00 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[ATI]]></category>
		<category><![CDATA[DELL]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[dual display]]></category>
		<category><![CDATA[Jaunty]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubtunu]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2009/09/23/getting-my-dual-display-setup-to-work-on-ubuntu-9-0-4.aspx</guid>
		<description><![CDATA[My Macbook Pro recently died and I decided to stage a new development desktop using Ubuntu 9.0.4.&#160; I&#8217;ve had colleages complain in the past about poor support for ATI graphics cards and was a bit concerned aboout getting the hardware&#160;&#8230; <a href="http://lostechies.com/joshualockwood/2009/09/23/getting-my-dual-display-setup-to-work-on-ubuntu-9-0-4/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My Macbook Pro recently died and I decided to stage a new development desktop using Ubuntu 9.0.4.&nbsp; I&#8217;ve had colleages complain in the past about poor support for ATI graphics cards and was a bit concerned aboout getting the hardware that I had handy work correctly.&nbsp; Well, I suppose I got lucky.&nbsp; I decided to pass on what I learned with the hopes that it would help others in the same situation (namely Mr. Meridth).</p>
<p>First off, here&#8217;s the hardware I am working with: Dell Optiplex 755 (love that model #, use it all the time with chmod), ATI Radeon HD 3450, Dell E170Sb 17&#8243; monitor, Dell E228WFPc 22&#8243; monitor.</p>
<p>I first tried to install Ubuntu from a live CD, but the image disappeared after the splash screen&#8230;sad times.&nbsp; So, disconnected the monitors from the ATI card and used the onboard video to get through the install.&nbsp; Once done with the install, I started researching into problems with ATI cards such as mine.&nbsp; Fortunately, I found a super-helpful site here: https://help.ubuntu.com/community/RadeonDriver.&nbsp; I found that there were problems with the proprietary drivers, so I elected to use an open source variant.&nbsp; It looks like there&#8217;s no 3D acceleration for my card, but what do I care (I&#8217;m not using it for games or animation).</p>
<p>On the community site I&#8217;d read, &#8220;You can often just take away your xorg.conf and it will run fine.&#8221;&nbsp; So, this is what I did on my first run.&nbsp; I followed the site&#8217;s instructions for installing the new drivers.&nbsp; Here they are in short:</p>
<pre>1. Get your graphics card info: lspci -nn | grep VGA<br />1.1. Should return info including the BusID, device type, and card model.  If you get "None known." you are stuck with the "fglrx" driver.<br />2. Remove the "fglrx" driver if it's already installed: sudo apt-get remove --purge xorg-driver-fglrx<br />2.1. If anything was removed, reboot after removal.<br />3. Check to see if libGL.so from ATI is still in /usr/lib ( ignored this and went ahead with the reinstall in 3.1.1.): glxinfo | grep vendor<br />3.1 If you see ATI under the 'OpenGL vendor string" then you'll need to reinstall the OpenGL libs.<br />3.1.1. To reinstall: sudo apt-get install --reinstall libgl1-mesa-glx libgl1-mesa-dri<br />4. Ensure that "fglrx" is not listed in /etc/modules: sudo cat /etc/modules<br />5. Ensure that "fglrx" is not listed in /etc/X11/xorg.conf<br />5.1. On my first from, I just renamed xorg.conf to bu.xorg.conf to remove and backup.</pre>
<p>After all this, I was able to get my dual monitor setup to work with my card.&nbsp; This was awesome, but since my 22&#8243; monitor&#8217;s resolution was throttled and looked ugly.&nbsp; I was stuck at 1280&#215;1024.&nbsp; This was ugly encough to have a go at the X11 config, which turned out to be far simpler than I had thought.&nbsp; Now everything is working like a charm!</p>
<p>Following is what I ended up with in xorg.conf:</p>
<p>Section &#8220;Monitor&#8221;<br />&nbsp;&nbsp; &nbsp;Identifier&nbsp;&nbsp; &nbsp;&#8221;Configured Monitor&#8221;<br />EndSection</p>
<p>Section &#8220;Screen&#8221;<br />&nbsp;&nbsp; &nbsp;Identifier&nbsp;&nbsp; &nbsp;&#8221;Default Screen&#8221;<br />&nbsp;&nbsp; &nbsp;Monitor&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&#8221;Configured Monitor&#8221;<br />&nbsp;&nbsp; &nbsp;Device&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&#8221;Configured Video Device&#8221;<br />&nbsp;&nbsp; &nbsp;SubSection &#8220;Display&#8221;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Virtual&nbsp;&nbsp; &nbsp;2960 1050<br />&nbsp;&nbsp; &nbsp;EndSubSection<br />EndSection</p>
<p>Section &#8220;Device&#8221;<br />&nbsp;&nbsp; &nbsp;Identifier&nbsp;&nbsp; &nbsp;&#8221;Configured Video Device&#8221;<br />EndSection</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2009/09/23/getting-my-dual-display-setup-to-work-on-ubuntu-9-0-4/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Yet Another Java Decompiler</title>
		<link>http://lostechies.com/joshualockwood/2009/08/05/yet-another-java-decompiler/</link>
		<comments>http://lostechies.com/joshualockwood/2009/08/05/yet-another-java-decompiler/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 18:23:00 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2009/08/05/yet-another-java-decompiler.aspx</guid>
		<description><![CDATA[I&#8217;ve used JAD for years, but it has been abandoned and doesn&#8217;t support the newer versions of Java well.&#160; If you still want to use JAD, soemone was kind enough to set up a new mirror for the last version:&#160;&#8230; <a href="http://lostechies.com/joshualockwood/2009/08/05/yet-another-java-decompiler/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve used JAD for years, but it has been abandoned and doesn&#8217;t support the newer versions of Java well.&nbsp; If you still want to use JAD, soemone was kind enough to set up a new mirror for the last version: http://www.varaneckas.com/jad.&nbsp; </p>
<p>Fortunately, there&#8217;s an even better alternative, JD: http://java.decompiler.free.fr/.&nbsp; JD is available as either a standalone UI or a plugin for Eclipse (which is a bummer since I only use Intellij).&nbsp; This simple little tool has been pretty useful, but I still wish the Java world had something like the Lutz Reflector.</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2009/08/05/yet-another-java-decompiler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Awesome Code Analysis Plugin for Java</title>
		<link>http://lostechies.com/joshualockwood/2009/04/15/awesome-code-analysis-plugin-for-java/</link>
		<comments>http://lostechies.com/joshualockwood/2009/04/15/awesome-code-analysis-plugin-for-java/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 21:59:00 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2009/04/15/awesome-code-analysis-plugin-for-java.aspx</guid>
		<description><![CDATA[I was browsing the plugins available for Intellij and came across this gem: http://findbugs.sourceforge.net/. Hats off to University of Maryland for this nifty little tool (does not require Intellij).&#160; Findbugs does static analysis of your projects and identifies patterns for&#160;&#8230; <a href="http://lostechies.com/joshualockwood/2009/04/15/awesome-code-analysis-plugin-for-java/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was browsing the plugins available for Intellij and came across this gem: http://findbugs.sourceforge.net/.</p>
<p>Hats off to University of Maryland for this nifty little tool (does not require Intellij).&nbsp; Findbugs does static analysis of your projects and identifies patterns for bad code.&nbsp; General categories it includes are malicious code vulnerabilities, performance issues, &#8220;dodgy&#8221; code (dead code, abuse of statics, etc), correctness issues, experimental (not totally sure what this one is yet), security issues, and threading issues.&nbsp; The integration with Intellij is pretty slick and I expect to get a fair bit of milage out of this tool (plugins also exists for NetBeans and Eclipse).</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2009/04/15/awesome-code-analysis-plugin-for-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&quot;I don&#8217;t have time to test!&quot;</title>
		<link>http://lostechies.com/joshualockwood/2009/04/13/quot-i-don-t-have-time-to-test-quot/</link>
		<comments>http://lostechies.com/joshualockwood/2009/04/13/quot-i-don-t-have-time-to-test-quot/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 21:55:00 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2009/04/13/quot-i-don-t-have-time-to-test-quot.aspx</guid>
		<description><![CDATA[Please pardon me while I rant a bit&#8230; How many times have we heard this response when we press our co-workers to test the code they are writing.&#160; This argument is often made when the team is up again tight&#160;&#8230; <a href="http://lostechies.com/joshualockwood/2009/04/13/quot-i-don-t-have-time-to-test-quot/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Please pardon me while I rant a bit&#8230;</p>
<p>How many times have we heard this response when we press our co-workers to test the code they are writing.&nbsp; This argument is often made when the team is up again tight deadlines and excessive pressure from management for delivery.&nbsp; I&#8217;ve even made the argument myself before, but find it increasingly harder to say it with a straight face.</p>
<p>Way back in 2000 I was given a copy of &#8220;Extreme Programming Explained&#8221; as a going-away present.&nbsp; I was leaving a research organization here in San Antonio to cut my teeth with a local start-up.&nbsp; Our shop was reasonably mature (rated CMM-3) and I had learned quite a bit about Software Engineering in a relatively short period of time.&nbsp; That said, the ideas in this books really got me thinking&#8230;and it seemed to help sate my hunger for a more lightweight process that would better fit my now environment.</p>
<p>Among the first practices that I started to grapple with was testing.&nbsp; I had experience with SilkTest, but I wanted tests that were closer to individual units.&nbsp; I first started with my own home-made test fixtures and had limited success&#8230;a few years later I was using VBUnit and NUnit..and I was becoming test infected.&nbsp; In spite of my love for working with tested code, I still found myself arguing that I didn&#8217;t have time to test when under the gun.&nbsp; It was about the 4 year mark that I began to shift my view.</p>
<p>Now, I think that abandoning testing due to time constraints is reckless and irresponsible.&nbsp; I sometimes catch myself thinking that I don&#8217;t have time for test writing, but I soon find myself proving this argument wrong.&nbsp; Often people who don&#8217;t have time to test will waste hours debugging code that they are desperately trying to force into production.&nbsp; This code ends up being brittle and costly to produce anyway.&nbsp; Corners cut on testing ultimately translate into a more costly investment in debugging and code fixes.&nbsp; When recently confronted with a peer who claimed that they didn&#8217;t have time to test, I angrily responded that I spent two days trying to get code working that was breaking due to a careless mistake in their code (which I then had to help debug).&nbsp; They didn&#8217;t have time not to test!</p>
<p>Granted, learning to test adequately is not a trivial task and can sometimes take years to really get right.&nbsp; This effort (and investment) is well worth the trouble as it will not only produce better code, but will most often transform how the programmer sees code.&nbsp; Although I sometimes have to work pretty hard to &#8220;tame&#8221; legacy code, the investment rarely proves to be wasteful&#8230;rather it saves time and money.&nbsp; Testable code is maintainable code.&nbsp; Maintainable code is cheaper code.&nbsp; As developer teams become better at testing they also become better at producing quality code.</p>
<p>Ultimately, I don&#8217;t believe that anyone doesn&#8217;t have time to not test.&nbsp; Degrees of coverage may vary due to time constraints, but the value of tests remain constant regardless of deadlines.&nbsp; A simple test for a possible exceptional case can avoid days of fretting over a rare NullPointerException in production.&nbsp; Tests have saved me countless hours of time while writing C, C#, Java, JavaScript, and LISP code.&nbsp; Tests have girded me with incredible confidence in the code I was delivering (within reason, of course&#8230;lol).&nbsp; Everyone should have time to test (the complex code at the least).</p>
<p>After about over a decade of coding professionally I&#8217;ve settled on the credo: &#8220;No tests, no trust&#8221;.</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2009/04/13/quot-i-don-t-have-time-to-test-quot/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>QUnit: Almost just what I was looking for&#8230;</title>
		<link>http://lostechies.com/joshualockwood/2009/03/11/qunit-amost-just-what-i-was-looking-for/</link>
		<comments>http://lostechies.com/joshualockwood/2009/03/11/qunit-amost-just-what-i-was-looking-for/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 23:20:00 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[Unit Tests]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2009/03/11/qunit-amost-just-what-i-was-looking-for.aspx</guid>
		<description><![CDATA[I started using QUnit a few months back and have really enjoyed it.&#160; That said, I was irked by a few minor features of QUnit and finally got irritated enough to make some changes. First off, what&#8217;s with adding &#8220;module:&#160;&#8230; <a href="http://lostechies.com/joshualockwood/2009/03/11/qunit-amost-just-what-i-was-looking-for/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I started using QUnit a few months back and have really enjoyed it.&nbsp; That said, I was irked by a few minor features of QUnit and finally got irritated enough to make some changes.</p>
<p>First off, what&#8217;s with adding &#8220;module: &#8221; as a delimiter for the module name and the test?&nbsp; It used to be &#8220;$&#8221;.&nbsp; Well, I&#8217;ve been using it with a BDDish convention and this feature finally got under my skin.&nbsp; I checked the current version of testrunner.js and it seems to be unchanged. </p>
<p>Simple change:</p>
<pre>function test(name, callback) {<br />	if(config.currentModule)<br />		name = config.currentModule + " module: " + name;<br /><br /></pre>
<p>became:</p>
<pre><br />function test(name, callback) {<br />	if(config.currentModule)<br />		name = config.currentModule +<b> " : "</b> + name;<br /></pre>
<p>Next, I was a little dismayed that we had ok() but no not_ok() and equals() but no not_equals().  There was also no assertion for is_null, not_null,  is_undefined and not_undefined (strict for both).<br />To fix this, I first created the functions I wanted in testrunner.js (I re-used ok for most of these&#8230;may do something more intelligent with the messages in the future, ok just sends (no message) if none is specified):</p>
<pre>function not_ok(a, msg) {<br />    ok(!a, msg);<br />}<br />function not_equals(actual, expected, message) {<br />    push(expected != actual, actual, expected, message);<br />}<br />function is_null(a, msg) {<br />	ok(a === null, msg);<br />}<br />function not_null(a, msg) {<br />	ok(a !== null, msg);<br />}<br />function is_undefined(a, msg) {<br />	ok(a == undefined, msg);<br />}<br />function not_undefined(a, msg) {<br />	ok(a !== undefined, msg);<br />}</pre>
<p>** This was all done in the function test(name, callback) in testrunner.</p>
<p>Then, I had to add this to the section where the &#8216;window&#8217; object is extended (see code follofing comment: // public API as global methods):</p>
<pre>$.extend(window, {<br />   test: test,<br />   module: module,<br />   expect: expect,<br />   ok: ok,<br />   <b>not_ok: not_ok,</b><br />   equals: equals,<br />   <b>not_equals: not_equals,<br />   is_null: is_null,<br />   is_undefined: is_undefined,<br />   not_null: not_null,<br />   not_undefined: not_undefined,</b><br />   ...<br /></pre>
<p>Now I got the assertion methods that I wanted in the first place!  I hate mucking with the internals on the testrunner.js file, but the symbol &#8220;config&#8221; is hidden so I couldn&#8217;t define not_equals externally.  It would require mucking with the internals in any case.</p>
<p>Well, hope that&#8217;s of interest to someone out there.  It was simply too much fun not to share.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Oooh, and I&#8217;d be remiss if I didn&#8217;t include my tests, right?</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(document).ready(function() {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; module(&#8220;when using assertion extensions&#8221;);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; test(&#8220;should support not_ok&#8221;, function() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not_ok(true == false, &#8220;contradiction, should be not_ok&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; equals(true, false);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; test(&#8220;should support is_null&#8221;, function() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var testVal = null;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; is_null(testVal, &#8220;should be null&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; test(&#8220;should support not_null&#8221;, function() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var testVal = &#8220;null&#8221;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not_null(testVal, &#8220;should not be null&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not_null(undefined, &#8220;undefined is strictly not null&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; test(&#8220;should support is_undefined&#8221;, function() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function testFunc() {}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; is_undefined(undefined, &#8220;obviously undefined&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; is_undefined(testFunc.method1, &#8220;also undefined&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; test(&#8220;should support not_undefined&#8221;, function() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function testFunc() {}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; testFunc.method1 = function() {};<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not_undefined(null, &#8220;null is not undefined&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not_undefined(testFunc.method1, &#8220;also undefined&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2009/03/11/qunit-amost-just-what-i-was-looking-for/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Selenium and Fitnesse (WebTest) with Firefox 3</title>
		<link>http://lostechies.com/joshualockwood/2008/11/13/selenium-with-firefox-3/</link>
		<comments>http://lostechies.com/joshualockwood/2008/11/13/selenium-with-firefox-3/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 11:56:00 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[Acceptance Testing]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Fitnesse]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[WebTest]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/11/13/selenium-with-firefox-3.aspx</guid>
		<description><![CDATA[Just wanted to pass something on&#8230; I&#8217;ve been using WebTest on Fitnesse for a while but had issue when trying to use it on my Mac.&#160; I found that the problem was with the Selenium server jar.&#160; You have to&#160;&#8230; <a href="http://lostechies.com/joshualockwood/2008/11/13/selenium-with-firefox-3/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just wanted to pass something on&#8230;</p>
<p>I&#8217;ve been using WebTest on Fitnesse for a while but had issue when trying to use it on my Mac.&nbsp; I found that the problem was with the Selenium server jar.&nbsp; You have to hack the jar to get it up and running, but the hack is pretty simple.&nbsp; Here&#8217;s a URL detailing what must be done:</p>
<p><a target="_blank" href="http://www.spacevatican.org/2008/9/27/selenium-and-firefox-3">http://www.spacevatican.org/2008/9/27/selenium-and-firefox-3</a></p>
<p>For my own benefit, I&#8217;ll reiterate what the other blog stated.&nbsp; First off, here&#8217;s the symptom.&nbsp; When you try to bring up an instance of Firefox 3 through WebTest (or Selenium test via Fitnesse) you&#8217;ll notice that the running Selenium server instance freezes.&nbsp; If you are running the Selenium server in a Console/Terminal window, you&#8217;ll see the following:<i></i></p>
<p><i>Preparing Firefox profile&#8230;</i></p>
<p>The source of the problem is in the *.rdf files inside the jar.&nbsp; The Selenium (0.9.2) folks hardcoded a version ceiling for Firefox at version 2.0.0.*.&nbsp; This was a bit of a rude discovery, but I&#8217;m ever grateful to the referenced blogger for pointing this out.&nbsp; I thought it was a Mac thing, but once I finally got a Windows VM running I saw the same behaviour.&nbsp; The fix is really simple.</p>
<p><b>Step 1: Extract the files needing change (from the directory where you have the jar).</b></p>
<pre>jar xf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFFCHROME/extensions/readystate@openqa.org/install.rdf<br />jar xf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFFCHROME/extensions/{538F0036-F358-4f84-A764-89FB437166B4}/install.rdf<br />jar xf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFFCHROME/extensions/<span class="Constant">{</span>503A0CD4-EDC8-489b-853B-19E0BAA8F0A4<span class="Constant">}</span>/install.rdf <br />jar xf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFF/extensions/readystate<span class="Constant">@</span>openqa.org/install.rdf <br />jar xf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFF/extensions/<span class="Constant">{</span>538F0036-F358-4f84-A764-89FB437166B4<span class="Constant">}</span>/install.rdf<br /></pre>
<p><b>Step 2: Change the max version in the rdf (Resource Description Framework) files.</b></p>
<p>The line of interest looks like this: &lt;em:maxVersion&gt;2.0.0.*&lt;/em:maxVersion&gt;</p>
<p><i>* you can change this to 4.*, should buy some time.</i></p>
<p><b>Step 3: Update the jar with your changes.</b></p>
<pre>jar uf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFFCHROME/extensions/readystate@openqa.org/install.rdf<br />jar uf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFFCHROME/extensions/{538F0036-F358-4f84-A764-89FB437166B4}/install.rdf<br />jar uf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFFCHROME/extensions/<span class="Constant">{</span>503A0CD4-EDC8-489b-853B-19E0BAA8F0A4<span class="Constant">}</span>/install.rdf <br />jar uf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFF/extensions/readystate<span class="Constant">@</span>openqa.org/install.rdf <br />jar uf selenium-server.jar <span class="Constant"></span>customProfileDirCUSTFF/extensions/<span class="Constant">{</span>538F0036-F358-4f84-A764-89FB437166B4<span class="Constant">}</span>/install.rdf<br /></pre>
<p>That&#8217;s it, once that&#8217;s changed you should be good to go for testing against Firefox 3!</p>
<p>Now getting (0.9.2) to work with Safari&#8230;I&#8217;m still figuring that one out.&nbsp; I tried using {*safari} for the browser, but it hangs.&nbsp; I may need to try to use the 1.0 version of Selenium server once it&#8217;s released.</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2008/11/13/selenium-with-firefox-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just wanted to share something that made my day.</title>
		<link>http://lostechies.com/joshualockwood/2008/09/28/just-wanted-to-share-something-that-made-my-day/</link>
		<comments>http://lostechies.com/joshualockwood/2008/09/28/just-wanted-to-share-something-that-made-my-day/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 07:27:00 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/28/just-wanted-to-share-something-that-made-my-day.aspx</guid>
		<description><![CDATA[Sniff&#8230;sniff&#8230;I think I&#8217;m in love&#8230; &#160;http://www.youtube.com/watch?v=T3iryBLZCOQ &#160; Post Footer automatically generated by Add Post Footer Plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<p><P>Sniff&#8230;sniff&#8230;I think I&#8217;m in love&#8230;</P><br />
<P>&nbsp;<A href="http://www.youtube.com/watch?v=T3iryBLZCOQ">http://www.youtube.com/watch?v=T3iryBLZCOQ</A></P><br />
<P>&nbsp;</P>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2008/09/28/just-wanted-to-share-something-that-made-my-day/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Seeking Closures</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/</link>
		<comments>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 00:03:00 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[Functional Languages]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[LISP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx</guid>
		<description><![CDATA[So, what&#8217;s a closure and why should I care? As Bob Dylan said, &#8220;&#8230;the times they are a changin&#8217;.&#8221;&#160;&#160; The strange world of functional programming, once restricted to more esoteric languages such as LISP, Erlang and Haskell, is now invading&#160;&#8230; <a href="http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><H1>So, what&#8217;s a closure and why should I care?</H1><br />
<P>As Bob Dylan said, &#8220;&#8230;the times they are a changin&#8217;.&#8221;&nbsp;&nbsp; The strange world of <A href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</A>, once restricted to more esoteric languages such as LISP, Erlang and Haskell, is now invading the mainstream.&nbsp; Languages such as C# and Java are now incorporating concepts once unique to functional programming languages.&nbsp; These changes should bring simplicity to these more mainstream languages, but I find they are often misunderstood (by myself for certain) and thereby misused or not taken advantage of.&nbsp; I&#8217;ve had a fair understanding of closures for a while, but wanted to develop a more solid understanding, ergo this post.</P><br />
<P>One aspect of functional languages, called <A href="http://en.wikipedia.org/wiki/Closure_(computer_science)">closures</A>, have been talked about since .Net 2.0 came on the scene.&nbsp; Of course, what many presented as <A href="http://eclipsezone.com/forums/thread.jspa?messageID=92099076">closures in 2.0 really weren&#8217;t</A> &#8212; for a number of reasons that I don&#8217;t care to get into at this time.&nbsp; More recently with the 3.0 framework (and the same will hopefully be true with Java 7), we see the introduction of lambda expressions; and finally have true support for closures (remember, not all anonymous functions are closures).&nbsp; You may ask, however, what the heck are closures anyway?&nbsp; Well, I&#8217;ll do my best to give an accurate illustration.</P><br />
<P>First off, what are they.&nbsp; As the Wikipedia link above stated, &#8220;a closure is a function that is evaluated in an environment containing one or more bound variables.&#8221;&nbsp; <A href="http://gafter.blogspot.com/">Neal Gafter</A>, during a <A href="http://video.google.com/videoplay?docid=4051253555018153503">Google Talk given in January 2007</A>, put it another way by saying that a closure is &#8220;a function that refers to free variables in its lexical context.&#8221;&nbsp; We all should know what <A href="http://en.wikipedia.org/wiki/Function_(programming)">functions</A> are&#8230;they are constructs that take a number of parameters and return a result (this includes more than just returning void).&nbsp; A free variable (or bound variable) is defined as a name (or symbol) that has a definition outside of the closure itself.&nbsp; The &#8220;lexical context&#8221; can be thought of as the context of the caller.&nbsp; I&#8217;ll give an example later.</P><br />
<P>One thing that I found particularly interesting about Gafter&#8217;s presentation was how he helped define closure by describing what they should support.&nbsp; Among other things, he mentioned that closures should have access to private members of the &#8220;lexical context&#8221; in which they are used.&nbsp; In C# and Java, they can also access the &#8220;this&#8221; instance of the caller.&nbsp; They should also support return values and support throwing exceptions (the latter is more of a Java concern).&nbsp; He also pointed out that although they are executed within the context of the caller, they can only return control to the caller (and not force the caller to return).&nbsp; </P><br />
<P>Gafter also pointed out that closures &#8212; as proposed in Java at least &#8212; are methods that act as new statements in the language and can be used to extend the native API (he calls these &#8220;control abstraction&#8221;).&nbsp; He described them as &#8220;concise function literals&#8221; that should behave as built-in statement, such as constructs such as for, while, lock, using, etc. in C# but without the problems associated with anonymous delegates and the like.&nbsp; Again, they are not anonymous class instances (such as delegates, which are not pointers to methods, but rather classes used to box methods).</P><br />
<P>Okay, so we have at least a rudimentary definition of closures; now let&#8217;s see how they can be useful.&nbsp; To again steal from Gafter&#8217;s presentation, I&#8217;ll use a couple of his examples that I found useful.&nbsp; </P><br />
<P>First off, what&#8217;s one of the problems closures can address?&nbsp; Gafter was describing a bit of code that was used repeatedly throughout an application at Google to gather run-time performance metrics on various operations.&nbsp; He argued that closures could be used to extend the native API and offer a more elegant syntax.&nbsp; Here&#8217;s what the code looked like:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_8.png"><IMG height="230" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_3.png" width="789" border="0"></A> </P><br />
<P>Granted this is only 8 lines of code, but only one of the 8 lines relates to the business logic of the application.&nbsp; The additional code (the other 7 lines) ends up cluttering the code and thereby obscures the surrounding business code.&nbsp; It would be nice if this code could be replaced by something like this (this would probably be a static method from some util class):</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_14.png"><IMG height="84" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_6.png" width="275" border="0"></A> </P><br />
<P>Which with the Java&#8217;s proposed new method invocation syntax would mean the same thing as:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_16.png"><IMG height="76" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_7.png" width="272" border="0"></A> </P><br />
<P>Neat, huh?&nbsp; With this example, the time() function is used in a manner similar to &#8220;for&#8221;, &#8220;using&#8221;, and other such operations native to the API.&nbsp; This is an instance where using a closure could be used to wrap common functionality around business logic in a more sensible way.&nbsp; Since the time method is a closure, we could also access doSomething() is it was a private method, such as this:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_20.png"><IMG height="75" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_9.png" width="269" border="0"></A> </P><br />
<P>Pretty <A href="http://groovy.codehaus.org/">groovy</A> huh? (pun intended)</P><br />
<P>&nbsp;</P><br />
<H1>From the horse&#8217;s mouth&#8230;</H1><br />
<P><STRONG>*WARNING: If you have a burning lack of curiosity or can&#8217;t fathom looking at code other than code written in your favorite language DO NOT continue reading.&nbsp; Reading LISP code without an open mind can lead to a general sense of disaffection and in more extreme cases unreasonable zealotry for your preferred language.&nbsp; </STRONG></P><br />
<H6></H6><br />
<P>As stated recently I&#8217;ve been digging deeper into LISP lately.&nbsp; In LISP such features are native (and natural) to the language.&nbsp; For some reason I tend to think that closures look for magical (as well as cleaner) in LISP programs.&nbsp; I&#8217;ll give another example of closures, but this time with one of the parent languages to all this closure goodness.</P><br />
<P>So here&#8217;s the scenario&#8230;which, by the way, is an adaptation of the practical exercise in <A href="http://gigamonkeys.com/book/practical-a-simple-database.html">Chapter 3 of Practical Common Lisp</A>.&nbsp; In the example I&#8217;m writing a simple little application to help break down the living things in my yard into a truncated taxonomy.&nbsp; Once finished, I&#8217;ll be able to look up groups of living things by either kingdom or phylum.&nbsp; Alternately, I can look up a living thing by name and see to which kingdom and phylum they belong.&nbsp; Bear in mind I probably would never bother with this in real life&#8230;</P><br />
<H2>Setting things up:</H2><br />
<P>First off, I&#8217;ll create a global symbol for my collection of living things, a function that creates a new living thing, and a function to add a new living thing to my global collection.&nbsp; Now I know that I should be using the CLOS, but I don&#8217;t want to confuse anyone with slots and whatnot.</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_22.png"><IMG height="221" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_10.png" width="623" border="0"></A> </P><br />
<P>That was simple enough.&nbsp; We see that *living-things* is initialized as an empty list (or null set).&nbsp; The function &#8220;make-living-thing&#8221; uses the &#8220;list&#8221; operator to create a special kind of list called a &#8220;property list&#8221;&#8230;think of it as a hashmap.&nbsp; The &#8220;add-living-thing&#8221; function simply pushes whatever is passed to it onto the *living-things* collection (which I&#8217;m using as a stack in this case).</P><br />
<P>Now I&#8217;ll walk around my yard and add the living things that I find&#8230;</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_24.png"><IMG height="225" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_11.png" width="749" border="0"></A> </P><br />
<P>Okay, so I left Bermuda Grass out&#8230;most of the grass in my yard is dead anyway.&nbsp; I can print out the contents of *living-things* and see the raw data:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_26.png"><IMG height="197" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_12.png" width="477" border="0"></A> </P><br />
<P>Now to make things look a little prettier (only a little, mind you), I&#8217;ll add a few functions for displaying the data in a more readable format:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_28.png"><IMG height="257" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_13.png" width="657" border="0"></A> </P><br />
<P>And now I have something like this (output is truncated):</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_30.png"><IMG height="320" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_14.png" width="267" border="0"></A> </P><br />
<H2>And now for something completely different&#8230;</H2><br />
<P>Okay, now we are nearing where closures enter the example.&nbsp; Next I want be able to pull data from *living-things* using a SQL-like syntax.&nbsp; Don&#8217;t ask why, I blame it on too much HQL.&nbsp; </P><br />
<P>Since I have only one entity type, I&#8217;ll just copy the list passed to the from clause and return it (nothing to it&#8230;copy-list came free with Common LISP).&nbsp; The select statement takes a data source (ultimately using the from function) and n comparison predicates.&nbsp; The function &#8220;remove-if-not&#8221; is a Common LISP function that removes items from the list (passed as the second parameter) whenever the predicate evaluates to false/nil (the first parameter).</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_38.png"><IMG height="250" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_18.png" width="836" border="0"></A> </P><br />
<P>If you run the code from the comments you get the following:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_40.png"><IMG height="103" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_19.png" width="533" border="0"></A> </P><br />
<P>Here you see the first use of a lambda expression to make an anonymous function (a function not associated with a symbol).&nbsp; The inner function, getf, is just a getter function that gets the value associated with the symbol :kingdom.&nbsp; The variable x in the getf is the current list item.&nbsp; For instance, the following gets the value associated with :kingdom for the first item in *living-things*:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_42.png"><IMG height="51" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_20.png" width="309" border="0"></A> </P><br />
<P>The equal function returns true (T) if the value for :kingdom at x is equal to &#8216;PLANTAE.&nbsp; That&#8217;s all that there is to the lambda expression&#8230;it simply serves as the comparison predicate for &#8220;remove-if-not&#8221;.&nbsp; There&#8217;s still no closure here&#8230;any symbol could be used instead of :kingdom and the expression would still be valid:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_44.png"><IMG height="60" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_21.png" width="308" border="0"></A> </P><br />
<P>See? return NIL, no problem.&nbsp; </P><br />
<H2>End game&#8230;</H2><br />
<P>Now we&#8217;ll work on the where clause.&nbsp; Passing lambda expressions is kind of ugly, though, so we&#8217;ll want to create an operator that will handle the where clause.&nbsp; Once finished, we should be able to make something like the following call and get all the matching entities back:</P><br />
<P>(select (from *living-things*) (where :kingdom &#8216;ANIMALIA :phylum &#8216;ARTHOPODA))</P><br />
<P>This part gets a little funky because we&#8217;re going to use <A href="http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html">macros</A>.&nbsp; Macros in LISP are similar to macros in C, but pumped up on steroids.&nbsp; Macros in LISP are used for run-time code generation (but much more elegant than IL generation in .Net).&nbsp; I&#8217;ll skip over some of the details on macros but will attempt to get at the spirit of this whole thing:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_48.png"><IMG height="333" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_23.png" width="881" border="0"></A> </P><br />
<P>This part&#8217;s a little hard to follow.&nbsp; We are focusing on the &#8220;where&#8221; macro, but I think we&#8217;ll start with the simpler predicate functions.&nbsp; </P><br />
<P>Birds eye view: First the &#8220;where&#8221; macro utilizes the &#8220;make-comparisons-list&#8221; function to generate a comparison predicate from a set of criteria.&nbsp; The &#8220;make-comparisons-list&#8221; function utilizes &#8220;make-comparison&#8221; for create a part of the overall comparison predicate using a field/value pair (such as :kingdom &#8216;ANIMALIA).</P><br />
<P>The &#8220;make-comparison&#8221; function works just like the lambda function in the example above.&nbsp; First it gets the value associated with the specified symbol (such as :kingdom) and then checks that value against value that was passed as a parameter.&nbsp; Here&#8217;s where we see a closure, where &#8220;living-thing&#8221; appears out of nowhere.&nbsp; First off, the backquote before the list containing &#8220;equal&#8221; is used to evaluate the list as code, the commas latter in the list mark variables.&nbsp; Without the backquote and commas we&#8217;d have an error because &#8220;living-thing&#8221; is not a bound variable (and that&#8217;s bad).&nbsp; This <A href="http://cl-cookbook.sourceforge.net/macros.html#LtohTOCentry-2">backquote facility</A> is very important in that it allows the coder to easily define code that can be evaluated later.&nbsp; So, if you execute &#8220;make-comparison&#8221; you get a piece of the code that the macro will ultimately execute.&nbsp; Again, I&#8217;m sure you noticed that &#8220;living-thing&#8221; isn&#8217;t a bound variable&#8230;yet.&nbsp; We&#8217;ll get back to that.</P><br />
<P>Since we want to support more than one comparison predicate, we&#8217;ve also created the &#8220;make-comparison-list&#8221; function with iterates over a list of fields and values (or properties and their associated values).&nbsp; The &#8220;loop while x collecting y&#8221; construct is an iterator with an accumulator.&nbsp; Basically it is iterating over all the field/value pairs (x), popping the field then the value and passing them to &#8220;make-comparison&#8221;, and finally appending the resulting code (y) to a new list (this is a Common LISP feature).&nbsp; The result is a list of comparison predicate expressions.&nbsp; </P><br />
<P>Here the macro takes everything following the &#8220;where&#8221; operator and constructs the appropriate of comparison predicates.&nbsp; The where function will iterate over the list returned from the &#8220;from&#8221; function and pass each list item to the lambda expression. The variable &#8220;living-thing&#8221; is introduced as a parameter in the lambda expression, which will be bound by the time the code resulting from &#8220;make-comparison&#8221; is evaluated (where the closure is).&nbsp; The &#8220;and&#8221; function is used for the conjunction between all the comparisons resulting from calling &#8220;make-comparisons-list&#8221;.&nbsp; Ideally, I&#8217;d use a more generic name for the bound variable used in &#8220;make-comparison&#8221;, so that I could create predicates for any other property list.</P><br />
<P>To illustrate the code that&#8217;s generated I&#8217;ll make a few calls to the function macroexpand-1 (it&#8217;s kind of like reflecting over the macro):</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_50.png"><IMG height="201" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_24.png" width="579" border="0"></A> </P><br />
<P>So, now you&#8217;ve seen the final lambda expression generated by the macro when using both multiple field/value paris and when using only one.&nbsp; Now we&#8217;ll put together the entire select statement and test it&#8230;I&#8217;ll get all animals from *living-things*.</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_52.png"><IMG height="154" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_25.png" width="549" border="0"></A> </P><br />
<P>&#8230;and now we&#8217;ll select all plants and use the &#8220;friendlier&#8221; display:</P><br />
<P><A href="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_54.png"><IMG height="276" alt="image" src="http://lostechies.com/joshualockwood/files/2011/03SeekingClosures_A7C3/image_thumb_26.png" width="572" border="0"></A> </P><br />
<P>So, as far as using closures, the closure on &#8220;make-comparison&#8221; was handy for supporting the lambda expression in the &#8220;where&#8221; function.&nbsp; I think that LISP is nice to clearly illustrate how closures work.&nbsp; One doesn&#8217;t NEED to use closures&#8230;but at times they are quite useful for making code a bit simpler and easier to read.&nbsp; I hope this post was helpful in elucidating the nature of closures and how they might be used.&nbsp; I also hope it helps show how fresh a 50+ year old language can be.</P><br />
<H1>For more information on closures:</H1><br />
<P><A href="http://csharpindepth.com/Articles/Chapter5/Closures.aspx">This article</A> seemed like a decent illustration of their use in C#.</P><br />
<P>If you can make it through the near 2 hour presentation, <A href="http://video.google.com/videoplay?docid=4051253555018153503">Neal Gafter&#8217;s discussion of Closures in Java</A> about a year and a half ago was an interesting illustration of what they might look like in Java.&nbsp; I also used some of his discussion as an example in this article.&nbsp; (It&#8217;s also fun to watch the original crowd of near 60 people dwindle down to about 10 by the end of the presentation)</P><br />
<P>Then of course there are the scores of books and sites about LISP, Erlang, Haskell, Ruby, JavaScript and other languages that feature closures as a central feature of the language.</P><br />
<P>Happy Coding!</P><br />
<P>Joshua</P>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Learning to Speak with a LISP</title>
		<link>http://lostechies.com/joshualockwood/2008/08/29/learning-to-speak-with-a-lisp/</link>
		<comments>http://lostechies.com/joshualockwood/2008/08/29/learning-to-speak-with-a-lisp/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 20:36:39 +0000</pubDate>
		<dc:creator>Joshua Lockwood</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/08/29/learning-to-speak-with-a-lisp.aspx</guid>
		<description><![CDATA[So it&#8217;s now my second week of playing with LISP and I have to tell you it&#8217;s been a heck of a ride so far.&#160; I&#8217;ve played with LISP in the past, but never with such intensity.&#160; I figured I&#8217;d&#160;&#8230; <a href="http://lostechies.com/joshualockwood/2008/08/29/learning-to-speak-with-a-lisp/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So it&#8217;s now my second week of playing with LISP and I have to tell you it&#8217;s been a heck of a ride so far.&nbsp; I&#8217;ve played with LISP in the past, but never with such intensity.&nbsp; I figured I&#8217;d share some of my experiences as I engage with this language once more.</p>
<p>It&#8217;s hard to convey the value of learning LISP.&nbsp; I&#8217;ve played with Scheme in the past as essentially mental gymnastics&#8230;the LISP family really challenges the way one thinks about programming in general.&nbsp; More recently, the increased popularity of languages such as Ruby has increased interest in functional languages&#8230;many of which trace there pedigree back to LISP (which has been around since the 50s).&nbsp; For you .Net and Java developers out there, the increased importance of functional languages could easily be justified by recent additions to the feature sets of both languages (lambda expressions, closures, anonymous functions&#8230;all LISP).</p>
<p>My first experience with the LISP was in 1998 while taking &#8220;Survey of Programming Languages&#8221;.&nbsp; As part of the class each student had to start off by writing a paper about any programming language that they wished.&nbsp; I though that LISP sounded neat and wrote a paper on Common LISP with a focus on the CLOS.&nbsp; Much to my chagrin, I soon found that our next task was to implement a set of programs in our language of choice.&nbsp; I began to think that maybe the guys who picked languages like Fortran and Pascal weren&#8217;t such idiots after all&#8230;in short I was hating life.</p>
<p>My first major hurtle in learning LISP enough to survive the course &#8211; by survive I mean earn an &#8216;A&#8217; &#8211; was picking an implementation of LISP.&nbsp; I found that there weren&#8217;t a whole lot of options for my Windows 95 box.&nbsp; I ended up settling with Harlequin&#8217;s implementation, but it wasn&#8217;t near as nice as what I&#8217;d used for C++.&nbsp; I delivered my code on time, made the marks I wanted, and then chucked LISP near the dusty bottom of my mind&#8230;along with Pascal and numerous flavors of Basic.</p>
<p>Now 10 years later I&#8217;ve dug out the language am giving it another go.&nbsp; I&#8217;m now aware of quite a few LISP implementation to choose from and picking the right one for me has been a bit of a chore.&nbsp; Dr. Scheme was pretty cool, but I really wanted to learn Common LISP&#8230;so I finally settled with Allegro CL (for the time being at least).&nbsp; The IDE choices are equally disappointing, but there are a few reasonable choices.</p>
<p>I&#8217;m currently using <a href="http://gigamonkeys.com/lispbox/">LispBox</a>, which packages Emacs-Slime-AllegroCL in one nifty little package (Allegro&#8217;s IDE is terrible&#8230;for my uses at least).&nbsp; I must agree that Emacs is probably not for everyone.&nbsp; There are implementations supported by vi as well as a number of commercial products.&nbsp; For Dev Studio guys the IDE options are pretty depressing.&nbsp; There are numerous references to an Eclipse plugin called CUSP that sounds pretty good, but I haven&#8217;t used it myself.&nbsp; As far as Eclipse, I&#8217;m using Ganymede.&nbsp; When I tried to install CUSP in the past I was thwarted by a bad URL for the update site&#8230;I tried an alternate URL that worked, but wouldn&#8217;t run on Ganymede (looks like it was written for Europa).&nbsp; <a href="http://sourceforge.net/projects/dandelion-ecl">Dandelion</a> seems to work okay, I just haven&#8217;t played with it yet (comes with CLISP implementation).</p>
<p>As far as learning the language itself, I&#8217;ve found a couple of sites that did a wonderful job at justifying learning LISP.&nbsp; <a href="http://www.erik-rasmussen.com/blog/2007/07/06/lisp-enlightenment-and-emacs-frustration/">Erik Rasmussen</a> did a great job in explaining both the delight of learning LISP and the horror of picking an IDE.&nbsp; Erik also referenced another <a href="http://www.defmacro.org/ramblings/lisp.html">article</a> that did an amazing job of describing LISP in terms familiar to C++/C#/Java people&#8230;it&#8217;s a little long but well worth the read.&nbsp; My favorite book to date on the subject has been <a href="http://www.gigamonkeys.com/book/">Practical Common Lisp</a> by Peter Seibel.&nbsp; Seibel&#8217;s book is geared toward developers already fluent in another language&#8230;so it doesn&#8217;t beat around the bush too much.&nbsp; </p>
<p>Well, that&#8217;s it for now&#8230;I&#8217;ll share what I learn if I think I can present something of value.</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/joshualockwood/2008/08/29/learning-to-speak-with-a-lisp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
