<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:posterous="http://posterous.com/help/rss/1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
  <channel>
    <title>rhyolight.blog</title>
    <link>http://rhyolight.posterous.com</link>
    <description>where i ramble about code and other stuff</description>
    <generator>posterous.com</generator>
    <link xmlns="http://www.w3.org/2005/Atom" href="http://posterous.com/api/sup_update#2103c4d69" type="application/json" rel="http://api.friendfeed.com/2008/03#sup" />
    
    
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/rhyolight-posterous" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="rhyolight-posterous" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://posterous.superfeedr.com/" /><item>
      <pubDate>Wed, 04 Jan 2012 19:57:00 -0800</pubDate>
      <title>Numenta</title>
      <link>http://rhyolight.posterous.com/numenta</link>
      <guid>http://rhyolight.posterous.com/numenta</guid>
      <description>
        <![CDATA[<p>
	<p>It was probably four years ago that I picked up the books&nbsp;<a href="http://onintelligence.com/">On Intelligence</a>&nbsp;(Jeff Hawkins) and&nbsp;<a href="http://www.singularity.com/aboutthebook.html">The Singularity is Near</a>&nbsp;(Ray Kurzweil). Reading those two books was eye-opening. I'd never thought about the present time and its place in humanity's evolution towards the future. Although I've always been a science fiction fan, I'd never actually&nbsp;<em>dreamt</em>&nbsp;about our possible futures -- about the problems we'll face as a species over the next 50, 100, 1000 years. It had never occurred to me that over the past 100 years, humanity has been changing more between <em>generations</em> than it has historically over <em>millennium</em>.</p>
<p>Technology has increased our population to over 7 billion people, and as we begin to run out of the fossil fuels that has enabled that population explosion, we'll have to rely on technology to help us mitigate the effects of our own decline. The same technologies that have allowed us to create our dilemma provide the only tools we have to correct that situation.</p>
<p>Technological evolution is a natural extension of biological evolution. (I've given a&nbsp;<a href="http://weblog.dangertree.net/2009/12/04/video-and-slides-for-humanity-20/">presentation</a>&nbsp;supporting this idea.) Therefore I have few reservations about allowing technology to evolve in most areas. Especially genetics, nanotechnology, and artificial intelligence.</p>
<p>I've always been interested in AI, but I missed my opportunity to become a computer scientist and study the appropriate subjects that lay the groundwork for progress in this field. I have, however, followed the progress of one company that has been doing groundbreaking research within this field:&nbsp;<a href="http://en.wikipedia.org/wiki/Numenta">Numenta</a>.</p>
<p><div class='p_embed p_image_embed'>
<a href="http://getfile2.posterous.com/getfile/files.posterous.com/temp-2012-01-01/DmgwBlpdavHCxbCftkmpwbjFawtFcItyuEFJHopmrAwxrsxojhaHnkvcheGl/3854684694_599f24f683_o.png.scaled1000.png"><img alt="3854684694_599f24f683_o" height="500" src="http://getfile5.posterous.com/getfile/files.posterous.com/temp-2012-01-01/DmgwBlpdavHCxbCftkmpwbjFawtFcItyuEFJHopmrAwxrsxojhaHnkvcheGl/3854684694_599f24f683_o.png.scaled500.png" width="500" /></a>
<img alt="746466_300" height="300" src="http://getfile3.posterous.com/getfile/files.posterous.com/temp-2012-01-01/eIcgDFfyyEeslbBJiDuJBHfAAnlmnCzltqxBuaEzdrAnrtDJsgtzGEpxlEws/746466_300.jpg.scaled500.jpg" width="300" />
<a href="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2012-01-01/wHDEwJFogjmorzEHtConmuyJbGiwBEddBdpvHJlyHtGxbJqqojgAHctkdfbo/On_Intelligence.jpg.scaled1000.jpg"><img alt="On_intelligence" height="765" src="http://getfile4.posterous.com/getfile/files.posterous.com/temp-2012-01-01/wHDEwJFogjmorzEHtConmuyJbGiwBEddBdpvHJlyHtGxbJqqojgAHctkdfbo/On_Intelligence.jpg.scaled500.jpg" width="500" /></a>
<div class='p_see_full_gallery'><a href="http://rhyolight.posterous.com/numenta">See the full gallery on Posterous</a></div>
</div>
</p>
<p>Since reading&nbsp;<span style="text-decoration: underline;">On Intelligence</span>, I have been signed up to receive Numenta's newsletter explaining their progress on "Hierarchical Temporal Memory" (HTM). Numenta is Jeff Hawkins' company established to take the ideas he defined in On Intelligence and turn them into a software product.&nbsp;This project is essentially a reverse engineering of how the neocortex of the human brain works.</p>
<p>The stuff that Numenta is working on is extremely cool.&nbsp;Bill Atkinson, one of the software engineers who designed the original user interface for the Mac computer, said, <a href="http://money.cnn.com/magazines/business2/business2_archive/2007/02/01/8398989/index.htm">"What Numenta is doing is more fundamentally important to society than the personal computer and the rise of the Internet."</a> Even recently, I've noticed some <a href="http://stackoverflow.com/questions/432922/significant-new-inventions-in-computing-since-1980#answer-433012">big names</a> mentioning Numenta.</p>
<p>Needless to say, I'm happy to become a part of the Numenta team, and I'm more excited than ever about what I'll be working on.</p>
<p>Here's to changing the world.</p>
	
</p>

<p><a href="http://rhyolight.posterous.com/numenta">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/numenta#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="678" width="678" url="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2012-01-01/DmgwBlpdavHCxbCftkmpwbjFawtFcItyuEFJHopmrAwxrsxojhaHnkvcheGl/3854684694_599f24f683_o.png">
        <media:thumbnail height="500" width="500" url="http://getfile5.posterous.com/getfile/files.posterous.com/temp-2012-01-01/DmgwBlpdavHCxbCftkmpwbjFawtFcItyuEFJHopmrAwxrsxojhaHnkvcheGl/3854684694_599f24f683_o.png.scaled500.png" />
      </media:content>
      <media:content type="image/jpeg" height="300" width="300" url="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2012-01-01/eIcgDFfyyEeslbBJiDuJBHfAAnlmnCzltqxBuaEzdrAnrtDJsgtzGEpxlEws/746466_300.jpg">
        <media:thumbnail height="300" width="300" url="http://getfile3.posterous.com/getfile/files.posterous.com/temp-2012-01-01/eIcgDFfyyEeslbBJiDuJBHfAAnlmnCzltqxBuaEzdrAnrtDJsgtzGEpxlEws/746466_300.jpg.scaled500.jpg" />
      </media:content>
      <media:content type="image/jpeg" height="917" width="599" url="http://getfile3.posterous.com/getfile/files.posterous.com/temp-2012-01-01/wHDEwJFogjmorzEHtConmuyJbGiwBEddBdpvHJlyHtGxbJqqojgAHctkdfbo/On_Intelligence.jpg">
        <media:thumbnail height="765" width="500" url="http://getfile4.posterous.com/getfile/files.posterous.com/temp-2012-01-01/wHDEwJFogjmorzEHtConmuyJbGiwBEddBdpvHJlyHtGxbJqqojgAHctkdfbo/On_Intelligence.jpg.scaled500.jpg" />
      </media:content>
    </item>
    <item>
      <pubDate>Sun, 02 Oct 2011 21:38:00 -0700</pubDate>
      <title>Node.js is Not Cancer</title>
      <link>http://rhyolight.posterous.com/nodejs-is-not-cancer</link>
      <guid>http://rhyolight.posterous.com/nodejs-is-not-cancer</guid>
      <description>
        <![CDATA[<p>
	<p>Yesterday, Ted Dziuba wrote an <a href="http://teddziuba.com/2011/10/node-js-is-cancer.html" title="Node.js is Cancer">acidic post</a> about NodeJS, and there was much tweeting afterwards. <a href="https://twitter.com/#!/rhyolight/status/120585150319955968" title="My tweet about Dziuba's blog">I was a part of the tweeting</a>, and I acknowledged that he has some points.</p>
<p>I am not a fan of the way Ted structured his critique. Calling Ryan Dahl (creator of NodeJS) a <strong><a href="https://twitter.com/#!/dozba/status/120166266962051072" title="Tweet where Ted calls Ryan Dahl a pansy">pansy</a></strong> was not only rude, but incorrect. I don't know Ryan myself, but <strong><em>he is doing something very interesting</em></strong>, and I'm sure he's had to fight a lot of battles to get where he's at.</p>
<p>And seriously, how many of us software engineers are actually <em>doing something</em> truly interesting?</p>
<p>Ted did have some valid points, especially about the event-loop synchronicity model. I think there is a bit of false advertising involved, not necessarily from Joyent and Ryan Dahl, but from the NodeJS community that has sprung up around it. <strong>If you have requirements for sufficiently parallel code execution, your code readability, maintainability, and clarity will suffer -- no matter what model you use for parallelism.</strong></p>
<p>The typical&nbsp;<span style="font-family: arial, sans-serif;">NodeJS</span>&nbsp;asynchronous callback approach is simple and beautiful in the easiest cases, but it gets nasty when your system gets more complicated. The problems <a href="http://rhyolight.posterous.com/nodejs-framework-rule-1-assume-it-blocks" title="NodeJS Framework Rule #1: Assume it Blocks">I've needed to solve</a> to build a framework in&nbsp;<span style="font-family: arial, sans-serif;">NodeJS</span>&nbsp;have not been architecturally simpler to solve than problems in other environments.</p>
<p><strong><em>There is no silver bullet.</em></strong></p>
<p><span style="font-family: arial, sans-serif;">NodeJS</span><span>&nbsp;can be deceptively simple. You can find yourself dealing with the unanticipated consequences of blocking code you didn't write rather easily if you are dealing with other people's code. You can also find yourself deeply nested within closure executions because everything <strong>has</strong> to be non-blocking, and sometimes it is hard to anticipate what might block and what won't, so you wrap everything in asynch callbacks. It is easy to write spaghetti code.</span></p>
<p>Programmers should <a href="https://twitter.com/#!/olympum/status/120595045861687296" title="Bruno's tweet about CPU blocking">never do CPU-blocking operations on a web server</a>, but outside a NodeJS server, the consequences of blocking are smaller. On any other web server (without the event loop idea), code that blocks will slow down the thread it is running within as well as draining CPU resources from other processes running in other threads. But in NodeJS, blocking code is more dangerous because it can halt the processing of all other requests on the server. This consequence can come from any application code running within the server, and from my standpoint as a framework engineer, it is particularly dangerous because frameworks deal with application code programmed by others. I can't make assumptions about the quality of the application code.</p>
<p><span>I like JavaScript, and I like&nbsp;</span><span style="font-family: arial, sans-serif;">NodeJS</span><span>, but not for the event loop model. I like it because JavaScript is flexible and functional, and now I can use the same language for my applications for the server and client. I think this is the big win for SSJS. I can write web components that run on the server as well as the client.&nbsp;</span></p>
<p><span>Saying NodeJS is cancer is purely trolling.&nbsp;</span>NodeJS is brand-spanking-new. It's still 0.X.X. The community is vibrant, but still feeling out the problem space.&nbsp;NodeJS bucks the system. It introduces new ideas. It sparks the imagination. It stretches the limits of current technologies. All good things. I commend Ryan Dahl for his work on such an obviously successful project.</p>
<p><span>In the end,&nbsp;</span><span style="font-family: arial, sans-serif;">NodeJS</span><span>&nbsp;is an interesting way to solve a problem. The wonderful thing is that we have so many choices as software engineers about how we can solve our problems.</span></p>
	
</p>

<p><a href="http://rhyolight.posterous.com/nodejs-is-not-cancer">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/nodejs-is-not-cancer#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Sun, 02 Oct 2011 13:05:00 -0700</pubDate>
      <title>NodeJS Framework Rule #1: Assume it Blocks</title>
      <link>http://rhyolight.posterous.com/nodejs-framework-rule-1-assume-it-blocks</link>
      <guid>http://rhyolight.posterous.com/nodejs-framework-rule-1-assume-it-blocks</guid>
      <description>
        <![CDATA[<p>
	<p>I am currently involved in building an <a href="http://www.slideshare.net/rhyolight/mojito-sl-2011" title="Mojito Slide Deck at Strange Loop 2011">all-JavaScript web application framework</a> for <strong>Yahoo!</strong> It runs on top of <a href="http://www.yuiblog.com/blog/2010/09/29/video-glass-node/" title="YUI Theater &mdash; Dav Glass: &ldquo;Using Node.js and YUI 3&Prime;">YUI3 &amp; NodeJS</a> on the server side, and the same core code also runs on the client. This "core" part of the framework absolutely cannot block the event loop under any circumstances (one of the core rules of NodeJS). This requirement is because of the server-side environment that NodeJS presents, one in which any on HTTP request handler can slow the execution of any other request simply by performing any blocking operation. A blocking operation can be an IO call to the file system, a web service, or even just a CPU-intensive task.</p>
<p><div class='p_embed p_image_embed'>
<img alt="Do-not-block" height="264" src="http://posterous.com/getfile/files.posterous.com/temp-2011-10-02/IbrHxzhboEzrirvBBainnEueFrrDeGDJbqaIHwAzIDpsxnGokxcnGatFlsCh/do-not-block.gif.scaled500.gif" width="200" />
</div>
Because we are building a <em>framework</em>, we need to be able to mix in user-created extensions in several places. Even without these extensions, a framework is a place for other programmers' code to execute, so the framework must constantly pass the execution flow to application code and recieve control back again at some point. With the NodeJS <strong>NOTHING MUST EVER BLOCK</strong> rule, this gets really tricky because every time we pass control to application code, we must always assume it will block the event loop.</p>
<p>This is nice for the end user writing the application code because they can always assume their code is running asychronously already. It is a lot more work of the framework, however. There are very clean places the framework can call application code asynchrously, but there are also some very niche situations where it is not evident that application code is even being executed, and the framework engineers have to know these places well.</p>
<p>It has become a general rule for me to <strong>always assume application code blocks</strong>, and draw very large red boxes around this code as we pass it around within the framework itself. We have to ensure we always treat it consistently asynchronously no matter where it ends up executing.</p>
	
</p>

<p><a href="http://rhyolight.posterous.com/nodejs-framework-rule-1-assume-it-blocks">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/nodejs-framework-rule-1-assume-it-blocks#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
      <media:content type="image/gif" height="264" width="200" url="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2011-10-02/IbrHxzhboEzrirvBBainnEueFrrDeGDJbqaIHwAzIDpsxnGokxcnGatFlsCh/do-not-block.gif">
        <media:thumbnail height="264" width="200" url="http://getfile5.posterous.com/getfile/files.posterous.com/temp-2011-10-02/IbrHxzhboEzrirvBBainnEueFrrDeGDJbqaIHwAzIDpsxnGokxcnGatFlsCh/do-not-block.gif.scaled500.gif" />
      </media:content>
    </item>
    <item>
      <pubDate>Sun, 24 Oct 2010 20:57:46 -0700</pubDate>
      <title>Browser Extension Idea: Query for Rendered UI State</title>
      <link>http://rhyolight.posterous.com/browser-extension-idea-query-for-rendered-ui</link>
      <guid>http://rhyolight.posterous.com/browser-extension-idea-query-for-rendered-ui</guid>
      <description>
        <![CDATA[<p>
	I want a browser plugin that allows me to query the state of the rendered page through a JavaScript API. This would allow me to write tests for things like SVG and Canvas to verify some aspects of the visual information presented to users. <p /><div>The problem is, I have no idea what I&#39;m talking about.</div><p /><div>I don&#39;t know browsers well enough to understand what information I would be able to get about the rendered layout. I assume that because one of the browser&#39;s jobs is to translate markup, styling, etc into a pixels on the screen, there should be a way to query the browser for the state of a pixel on the page.</div> <p /><div>var pix = document.getPixel(100,100);</div><div>if (pix.getHexColor() === &#39;0000FF&#39;) {</div><div>    console.log(&#39;pixel at 100x100 is red&#39;);</div><div>}</div><p /><div>Given this simple ability, the API could be easily broadened for further functionality.</div> <p /><div>var pixRow = document.getPixels([100,100], [100,200]);</div><p /><div>This should give me an array of 100 pixel objects corresponding to a vertical bar starting at 100,100 and going down.</div> <p /><div>var pixBox = document.getPixels([100,100], [200,200]);</div><p /><div>This should give me an array of 100 arrays of pixel objects corresponding to a 100x100 box with its top left edge at 100,100.</div> <p /><div>But once again, my problem is that I really don&#39;t know what I&#39;m talking about. Is one pixel in fact one color? Or does it contain more information than that? Would anyone else find this type of thing useful? Or does something else provide this type of functionality?</div>
	
</p>

<p><a href="http://rhyolight.posterous.com/browser-extension-idea-query-for-rendered-ui">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/browser-extension-idea-query-for-rendered-ui#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Tue, 19 Oct 2010 11:58:00 -0700</pubDate>
      <title>YUI3 &amp; NodeJS for JavaScript View Rendering on Client or Server</title>
      <link>http://rhyolight.posterous.com/yui3-nodejs-for-javascript-view-rendering-on</link>
      <guid>http://rhyolight.posterous.com/yui3-nodejs-for-javascript-view-rendering-on</guid>
      <description>
        <![CDATA[<p>
	<p>It was hard to come up with a title for my <a href="http://yuiconf2010.eventbrite.com/" title="YUIConf registration">YUIConf</a> talk this year, but there it is. It looks better laid out in a slide:</p>
<p><div class='p_embed p_image_embed'>
<a href="http://posterous.com/getfile/files.posterous.com/temp-2010-10-19/zbaIBelvCnjqsgIBdtfBDnrEBInffxphBmtdsHzhormgjzBcCxjdykvrspdH/YUIConf_2010.001.png.scaled1000.png"><img alt="Yuiconf_2010" height="375" src="http://posterous.com/getfile/files.posterous.com/temp-2010-10-19/zbaIBelvCnjqsgIBdtfBDnrEBInffxphBmtdsHzhormgjzBcCxjdykvrspdH/YUIConf_2010.001.png.scaled500.png" width="500" /></a>
</div>
</p>
<p>The premise of this idea is to enable data to be translated into HTML either on the browser or the server. The only way to do this on the browser is with JavaScript, so we must have JavaScript on the server as well. Good thing we have <strong>NodeJS</strong>. Most web application frameworks have some type of templating engine that accepts two things: (1) data, (2) template, and returns HTML to be assembled into an HTTPResponse.</p>
<p>But, the richer the client gets, the more it only wants data -- not markup -- from the server. It is fairly common for an XHR response handler to expect straight JSON data and update the DOM itself, effectively taking the place of the templating engine that might do the <em>same thing</em> with the <em>same data</em> on the server.</p>
<p>This <strong>contradicts DRY</strong> because there is most likely server-side logic to munge that same data through a templating engine to produce HTML <em>as well as</em> the JavaScript function that updates the DOM with the same JSON data.</p>
<p>But what if we could take the browser-side JavaScript function that handles the XHR response data and run it on the server? With the <a href="http://github.com/davglass/nodejs-yui3" title="Dav Glass's NodeJS YUI3 module">nodejs-yui3</a> module, we can!</p>
<p>This presentation will specifically define our use case, then walk through an entirely open-source implementation of this idea using <a href="http://developer.yahoo.com/yui/3/" title="YUI3">YUI3</a>, <a href="http://nodejs.org/" title="NodeJS">NodeJS</a>, and a <a href="http://grails.org" title="Grails">Grails</a> web server (for page assembly and dispatch).</p>
<p>I hope to see you there!</p>
<p><em><strong>UPDATE:</strong> I've posted the <a href="http://github.com/rhyolight/YUI-Conf-NodeJS-YUI3-Rendering-Example" title="YUI3 &amp; NodeJS JS View Rendering Code Demo">code demo source</a>, which is still a work-in-progress (but it does all seem to work right now).</em></p>
	
</p>

<p><a href="http://rhyolight.posterous.com/yui3-nodejs-for-javascript-view-rendering-on">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/yui3-nodejs-for-javascript-view-rendering-on#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="768" width="1024" url="http://getfile8.posterous.com/getfile/files.posterous.com/temp-2010-10-19/zbaIBelvCnjqsgIBdtfBDnrEBInffxphBmtdsHzhormgjzBcCxjdykvrspdH/YUIConf_2010.001.png">
        <media:thumbnail height="375" width="500" url="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2010-10-19/zbaIBelvCnjqsgIBdtfBDnrEBInffxphBmtdsHzhormgjzBcCxjdykvrspdH/YUIConf_2010.001.png.scaled500.png" />
      </media:content>
    </item>
    <item>
      <pubDate>Sun, 10 Oct 2010 19:49:55 -0700</pubDate>
      <title>Why I Code</title>
      <link>http://rhyolight.posterous.com/why-i-code</link>
      <guid>http://rhyolight.posterous.com/why-i-code</guid>
      <description>
        <![CDATA[<p>
	<p>When I was a teenager, I wanted very badly to be an independent comic book publisher. I daydreamed about it while I mowed lawns to earn extra money, and I was addicted to indie comics like <a href="http://en.wikipedia.org/wiki/Poison_Elves" title="Poison Elves Wikipedia">Poison Elves</a> and <a href="http://en.wikipedia.org/wiki/Cerebus" title="Cerebus on Wikipedia">Cerebus</a>. I drew things like <a href="http://storage.dangertree.net/oldCrap/Spacegod2%20Index/fs6.html" title="The Adventures of Flip Spaceboy">this</a> comedy sci-fi comic, and even interviewed with the Chicago Art Institute. I knew it was going to be extremely hard to be successful in a field like this, as many indie comics publishers<a href="http://www.amazon.com/Cerebus-Guide-Self-Publishing-Dave/dp/B000O16CF2" title="Cerebus Guide to Self Publishing"> will tell you</a> if you happen to ask them.</p>
<p>My mother, who was much smarter than I though she was at the time, convinced me to direct my talents in other areas as well (especially ones that had decent earning potential). So eventually I abandoned the dream and replaced it with a series of misguided educational, familial, and career&nbsp;maneuvers&nbsp;that landed me enlisted in the military and sitting in front of a computer for most of my workday. This led into my career as a software engineer.</p>
<p>How I got from <em>soldier to JavaScript geek</em> at Yahoo! is not interesting. <strong>Why I Code</strong> is interesting, and I would like to talk about that. At first, I dabbled like a frightened monkey pushing unknown buttons in a lab cage, wondering what combinations divvy out the best digital treats. Soon, I could see the full potential of this <strong>amazing</strong> career field, and I wanted nothing more than to <em>dive into it, head-first, without reservation</em>.</p>
<p>But <strong>why?</strong> Why is this <em>coding </em>thing so awesome? Why are so many of us <em>so <strong>passionate</strong></em> about what we do with our little languages that compile down into cryptic bytecode? I know<strong> Why <em>I</em> Code</strong>. There are two reasons.</p>
<p><span style="font-size: large;"><strong>Code is Art</strong></span></p>
<p>There are programmers and then there are <strong><em>programmers</em></strong>. You and I are <em><strong>programmers</strong></em>, and we can have conversations about the artistic quality of <a href="http://oreilly.com/catalog/9780596510046" title="Beautiful Code Book Site">beautiful code</a>. We all know bad code because there is an abundance of it out in the world. Just stroll around github for a few hours and you'll find kilobytes of the stuff. But you and I... we know when we see really good code. I gives us a little tingle, doesn't it? You take a look at that recursive function one more time and realize why it makes absolute logical sense for it to be calling itself at that instance, and you know that's good code. It is like really seeing a painting for the first time, or listening to <a href="http://www.youtube.com/watch?v=xU23LqQ6LY4" title="Music for 18 Musicians on Youtube Live">Music for 18 Musicians</a>.</p>
<p>It breathes. You connect to it in more than just a logical way. It touches you and you can learn from it. When we write code, we express ourselves and our ideas as if the editor were our canvas and the keyboard were our palette.</p>
<p><span style="font-size: large;"><strong>Code Transcends Context</strong></span></p>
<p>Once you grok the code, you can drive your codewagon in any direction you'd like. Our toolboxes are full of utilities with unlimited potential to launch rockets to Mars, cure cancer, map the human genome, or just map your own neighborhood. With all the power that programming gives us, we superhumans of technology can apply our skills to any field we wish.</p>
<p><strong>They all <em>need</em> our code.</strong> They yearn for us to come and help them solve their graphing problems, their social media problems, their structural engineering problems. <em>We need not pigeonhole ourselves into one field of work.</em> Our power as programmers is <strong>unlimited</strong> in its application to any real world context.</p>
<p>We programmers have the world at our fingertips. That is <strong>Why I Code</strong>.</p>
<p>&nbsp;</p>
	
</p>

<p><a href="http://rhyolight.posterous.com/why-i-code">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/why-i-code#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Sun, 10 Oct 2010 13:34:51 -0700</pubDate>
      <title>We Were All So Alone Once</title>
      <link>http://rhyolight.posterous.com/we-were-all-so-alone-once</link>
      <guid>http://rhyolight.posterous.com/we-were-all-so-alone-once</guid>
      <description>
        <![CDATA[<p>
	<p>We are so fucking connected today. When was the last time you found yourself completely and utterly alone? No option to talk to anyone, call anyone, text anyone? No Twitter, Facebook, Google? Alone, with no one around, completely surrounded by nature, not other humans?</p>
<p>I spent lots of time during my youth like this, and I enjoyed it quite a bit. Now, this seems to be my nightmare. I may be lying in my bed, my computer and phone in other rooms of the house, and my brain starts pinging for connectivity. I feel like I need to at least have my phone in my hand, or on the bedstand by me. Just in case someone emails or comments on my Facebook status, or retweets something of mine. Just so I can have that instant gratification of social acceptance that drives so many of my daily actions today.</p>
<p>The world has change quickly and drastically, and each of us have been changed by it.&nbsp;</p>
<p>&nbsp;</p>
	
</p>

<p><a href="http://rhyolight.posterous.com/we-were-all-so-alone-once">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/we-were-all-so-alone-once#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Tue, 27 Jul 2010 10:31:00 -0700</pubDate>
      <title>GrailsUI is Now an Unsupported Plugin</title>
      <link>http://rhyolight.posterous.com/grailsui-is-now-an-unsupported-plugin</link>
      <guid>http://rhyolight.posterous.com/grailsui-is-now-an-unsupported-plugin</guid>
      <description>
        <![CDATA[<p>
	<h3>Why?</h3>
<p>I'm the only active developer, and I'm totally lame.</p>
<h3>But What About My Current Grails App?</h3>
<p>First of all, <em>I will still monitor the Grails user mailing list for questions about GrailsUI</em> and reply as I have time to help out.</p>
<p>Also, there may be some <a href="http://grails.org/plugin/grails-ui" title="GrailsUI Plugin page">GrailsUI</a> users out there thinking they made the wrong decision about which RIA plugin to install, but read below before you get upset with yourself (or me). The bottom line is this: <em>If you are making a considerably complex RIA application using JavaScript, you will be better off hand-coding it with JavaScript than using a plugin as an RIA platform.</em></p>
<p><span style="font-size: 15px; font-weight: bold;">My Thoughts About GrailsUI</span></p>
<p>Initial roles of GrailsUI:</p>
<ol>
<li>Simple AJAX widget provider</li>
<li>Platform for RIA frontend</li>
</ol>
<p>GrailsUI does #1 pretty well, in that it abstracts the complexity of creating AJAX widgets away from the Grails developer. You don't have to write any JavaScript to get a basic widget working, but if necessary you can write some JavaScript to interact with the widget on the page, thus adding functionality.</p>
<p>Although it seems like GrailsUI does #2 well as well, this becomes <strong>largely unmaintainable as the codebase increases</strong>, and <strong>especially as the importance of performance increases</strong>.</p>
<p>It turns out that <em>GrailsUI is a horrible thing to build an entire RIA codebase on</em>. In fact, if the design goals of a RIA front-end are extensive, I believe the code should be written <strong>entirely by hand</strong>.</p>
<p>It is just like putting down the WYSIWYG editor and hand-coding your UI. GrailsUI might provide a great way to layout some basic AJAX stuff, but as soon as you get into any non-trivial JavaScript work, it breaks down in an unmaintainable heap.</p>
<p>I do not think the concept of an RIA platform plugin for Grails is a bad idea, however. I just think that I lacked the wisdom and foresight to create that platform with GrailsUI.</p>
<p>There are several maintainability issues within the JavaScript and markup that GrailsUI creates, namely:</p>
<ul>
<li> <span style="color: #ff0000;"><strong>Global JavaScript variables</strong></span>. They are all over the place. I would not be surprised if a lot of the GrailsUI bugs are because of this.</li>
<li>JavaScript liberally sprinkled throughout the markup, and generated in a very dynamic way. This really complicates things.</li>
<li>Scripts all load at the top of the page.</li>
<li>Core GrailsUI JS lib augments native JavaScript object (String)</li>
<li>JSON responses are manually eval()'ed instead of going through a proper JSON parser</li>
<li>There are 0 JavaScript tests, and minimal Groovy tests</li>
</ul>
<p>It is entirely possible to address each of these issues in a rewrite of GrailsUI, and in fact I was planning on doing this with GrailsUI 2.0. But this is a major task.</p>
<p>All that being said, there are a lot of GrailsUI users, and many of them have thanked me for this plugin, saying it has made their lives easier. Like I said, I think a plugin like this has a place in the Grails ecosystem, but I think it's primary role should be that of a shortcut to AJAX widget goodness, no so much shortcut to an AJAX platform. It can also be useful as a stop-gap measure to get a UI in place before major front-end resources are brought in to cleanup and re-implement.</p>
<p><span style="font-size: 15px; font-weight: bold;">Thank you</span></p>
<h3 style="font-size: 1.17em;"><span style="font-weight: normal; font-size: 13px;">Thanks to all of you who use GrailsUI, for making it one of the <a href="http://grails.org/plugin/category/popular" title="Grails Most Popular Plugins">most popular</a> Grails plugins. Especially thank all of you who <a href="http://jira.codehaus.org/browse/GRAILSPLUGINS/component/13467" title="GrailsUI JIRA page">submitted bugs and attached patches</a>, and especially <strong>Daniel Honig</strong>, who was instrumental in getting the first version of GrailsUI off the ground.</span></h3>
<h3 style="font-size: 1.17em;">Would You Like to Take the Torch?</h3>
<p>Awesome. I've already established a <a href="http://groups.google.com/group/grailsui-dev" title="GrailsUI Dev Group">group</a> for it with a <a href="http://groups.google.com/group/grailsui-dev/web/grailsui-2-0-planning-page" title="GrailsUI 2.0 Planning">planning page for GrailsUI 2.0</a>, and there are actually members. This message is getting posted there as well. What the GrailsUI project really needs is a leader with a good amount of JavaScript and Grails experience -- and the motivation and time to dedicate to an open source project.</p>
<h3 style="font-size: 1.17em;">In Summary</h3>
<p>This is one of those <strong>"if I knew then what I know now"</strong> situations. When I started GrailsUI, I had very little experience with JavaScript, so I did a lot things wrong. Now that I know JavaScript really well, I cringe when I look over the GrailsUI codebase. I would love to take six months and completely re-write GrailsUI, and if anyone is willing to pay me to do so, I would be happy to. But now that I'm working at Yahoo!, my plate is full of JavaScript work already, and I am choosing to use my spare time for other endeavers. </p>
<p>If you would like to contribute, please contact me or join the dev group.</p>
<p><sub>Also, <a href="http://grails.1312388.n4.nabble.com/GrailsUI-is-Now-an-Unsupported-Plugin-td2303936.html#a2303936" title="grails user mailing list">here is the Grails user mailing list discussion on this topic</a>.</sub></p>
	
</p>

<p><a href="http://rhyolight.posterous.com/grailsui-is-now-an-unsupported-plugin">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/grailsui-is-now-an-unsupported-plugin#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Thu, 08 Apr 2010 09:38:00 -0700</pubDate>
      <title>JavaScript Constructor Performance</title>
      <link>http://rhyolight.posterous.com/javascript-constructor-performance</link>
      <guid>http://rhyolight.posterous.com/javascript-constructor-performance</guid>
      <description>
        <![CDATA[<p>
	<p>I assumed there might be some differences in performance between the <a href="http://rhyolight.posterous.com/javascript-constructors-for-dummies" title="Classic inheritance">classic prototypal inheritance object construction</a> and the <a href="http://rhyolight.posterous.com/extending-explicit-object-constructors" title="Extending Explicit Object Constructors">explicit object construction models</a>, so I wrote some code that tested it using the models below:</p>
<h4>Classic</h4>
<p><a href="http://gist.github.com/360282.js?file=gistfile1">http://gist.github.com/360282.js?file=gistfile1</a></p>
<h4>Object</h4>
<p><a href="http://gist.github.com/360283.js?file=gistfile1">http://gist.github.com/360283.js?file=gistfile1</a></p>
<p>I ran each constructor function 1,000,000 times in Chrome and tallied up the resulting times it took for each construction, with some interesting results:</p>
<table>

<tr>
<th>Time(ms) for 1M constructions</th> <th>Type of constructor</th>
</tr>


<tr>
<td>3</td>
<td>new Rectangle(2,3)</td>
</tr>
<tr>
<td>8.2</td>
<td>new PositionedRectangle(2,3,0,0)</td>
</tr>
<tr>
<td>26.5</td>
<td>new ColoredPositionedRectangle(2,3,0,0)</td>
</tr>
<tr>
<td>24.8</td>
<td>new ORectangle(2,3)</td>
</tr>
<tr>
<td>298.3</td>
<td>new PositionedORectangle(2,3,0,0)</td>
</tr>
<tr>
<td>1221.5</td>
<td>new ColoredPositionedORectangle(2,3,0,0)</td>
</tr>

</table>
<p><div class='p_embed p_image_embed'>
<a href="http://posterous.com/getfile/files.posterous.com/rhyolight/fIHedlAcEFdEpeveBqBIgsvqckqglrirmoHtiDEjabhpbtJrgHrzmqDcBfhe/media_httpsdangertree_FEmff.png.scaled1000.png"><img alt="Media_httpsdangertree_femff" height="387" src="http://posterous.com/getfile/files.posterous.com/rhyolight/fIHedlAcEFdEpeveBqBIgsvqckqglrirmoHtiDEjabhpbtJrgHrzmqDcBfhe/media_httpsdangertree_FEmff.png.scaled500.png" width="500" /></a>
</div>
</p>
<p>With no inheritance at all, <em>classic object construction is over 8 times faster</em> than the explicit object construction method. On constructing an object with one superclass, <em>classic construction is over 36 times faster</em>. And on constructing an object with two superclasses, <em>over 46 times faster</em>. These are pretty telling results, but you must keep in mind that I've created one million objects in each case. </p>
<p>These results are from Chrome, but I also ran them through Firefox. The results gave the the same conclusions, but object construction in Firefox is roughly 10 times slower than Chrome across the board. The remaining examples are all from Chrome, just because it was so much faster to test.</p>
<p>These results have me an idea to test a deeper inheritance structure, so I put together some code (not shown here, but contact me if you are interested) that created an inheritance hierarchy that was 10 levels deep. The first case was just an empty model with no attributes, but a toString method that was overridden in each subclass to return a different string. In the second case, I added only one attribute to the topmost superclass. For this case, in the object-construction model, I also added the typical getter and setter methods to the topmost class as well. Here are the results of creating 1,000,000 objects of each level of inheritance with both the classic and object-explicit construction models.</p>
<p><div class='p_embed p_image_embed'>
<img alt="" src="http://s.dangertree.net/p/constr_perf2.png" />
</div>
</p>
<p>The flat lines on the bottom are representing the classic model, one without any attributes, the other with one attribute. As you can see, there is a linear growth in construction time through all the models, but the slope of the explicit object construction model is much higher, especially when there is an attribute involved even at the topmost inheritance level.</p>
<p>I didn't take the inheritance heirarchy past 10 generations, but if you look at the data another way, you can see that the discrepancy in construction time starts to level off at around 50 times faster at 10 generations.</p>
<p><div class='p_embed p_image_embed'>
<a href="http://posterous.com/getfile/files.posterous.com/rhyolight/BgwupcinjEhDzjqJqhmniGuhwIlounjDnymzhCqvieuFlEsaJgmynrCamyft/media_httpsdangertree_atdkv.png.scaled1000.png"><img alt="Media_httpsdangertree_atdkv" height="396" src="http://posterous.com/getfile/files.posterous.com/rhyolight/BgwupcinjEhDzjqJqhmniGuhwIlounjDnymzhCqvieuFlEsaJgmynrCamyft/media_httpsdangertree_atdkv.png.scaled500.png" width="500" /></a>
</div>
</p>
<p>Here are some conclusions I got from running these tests:</p>
<ul>
<li>Chrome is over 10X faster than Firefox at JavaScript object construction.</li>
<li>If you forget the 'new' keyword using the class construction model, you are screwed. You must use 'new', and there is no error thrown if you forget about it. The function just executes without the extra "construction" features.</li>
<li>If you forget the 'new' keyword using the explicit object construction model, you actually get a small (negligible) performance boost.</li>
<li>Large inheritance hierarchies should be avoided no matter with method you use.      
<ul>
<li>In both cases because it is just friggin' confusing</li>
<li>In the explicit object model because it can get really slow</li>
</ul>
</li>
<li>If you must have a non-trivial inheritance hierarchy, you need to know approximately how it will be used. If there will be many instances created of the model, maybe the classic inheritance scheme is preferred for performance reasons.</li>
</ul>
	
</p>

<p><a href="http://rhyolight.posterous.com/javascript-constructor-performance">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/javascript-constructor-performance#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="426" width="551" url="http://getfile9.posterous.com/getfile/files.posterous.com/rhyolight/fIHedlAcEFdEpeveBqBIgsvqckqglrirmoHtiDEjabhpbtJrgHrzmqDcBfhe/media_httpsdangertree_FEmff.png">
        <media:thumbnail height="387" width="500" url="http://getfile0.posterous.com/getfile/files.posterous.com/rhyolight/fIHedlAcEFdEpeveBqBIgsvqckqglrirmoHtiDEjabhpbtJrgHrzmqDcBfhe/media_httpsdangertree_FEmff.png.scaled500.png" />
      </media:content>
      <media:content type="image/png" height="517" width="652" url="http://getfile3.posterous.com/getfile/files.posterous.com/rhyolight/BgwupcinjEhDzjqJqhmniGuhwIlounjDnymzhCqvieuFlEsaJgmynrCamyft/media_httpsdangertree_atdkv.png">
        <media:thumbnail height="396" width="500" url="http://getfile4.posterous.com/getfile/files.posterous.com/rhyolight/BgwupcinjEhDzjqJqhmniGuhwIlounjDnymzhCqvieuFlEsaJgmynrCamyft/media_httpsdangertree_atdkv.png.scaled500.png" />
      </media:content>
    </item>
    <item>
      <pubDate>Thu, 25 Mar 2010 08:03:00 -0700</pubDate>
      <title>Extending Explicit Object Constructors</title>
      <link>http://rhyolight.posterous.com/extending-explicit-object-constructors</link>
      <guid>http://rhyolight.posterous.com/extending-explicit-object-constructors</guid>
      <description>
        <![CDATA[<p>
	<p>Lately, I talked about <a href="http://rhyolight.posterous.com/javascript-inheritance-part-2-the-explicit-ob" title="JavaScript Inheritance Part 2: The Explicit Object Construction Model">creating classes of objects in JavaScript by having the constructor function explicitly return an object literal</a>. Using this method, the resulting object has no prototype, and the constructor does not need to be executed using the 'new' keyword (although it is a good idea to use the 'new' keyword in order to explicitly specify object creation to other programmers).  Now, we're going to talk about creating a local extension of this "class" of objects. We ended up with this constructor function:</p>
<p><a href="http://gist.github.com/337776.js?file=blog_good2">http://gist.github.com/337776.js?file=blog_good2</a></p>
<p>And now we want to create a local extension to this called PositionedRectangle, which adds location data and a new method to calculate a distance between itself and another PositionedRectangle.  With the first <a href="http://rhyolight.posterous.com/javascript-constructors-for-dummies" title="JavaScript Inheritance Part 1: The Classic Model">class example of prototypal inheritance</a>, we created a new constructor function that called the "superclass" constructor, then did much mucking about with the prototypes of the two constructor functions in order to hook them together into an inheritance model.  While we still have some mucking about to do in the form of encapsulation, but we can accomplish this without too much trouble. This inheritance model will create a new object of the type of the superclass, then use it to create a new object that contains its properties in addition to the properties the subclass defines. It looks like this:</p>
<p><a href="http://gist.github.com/343634.js?file=gistfile1">http://gist.github.com/343634.js?file=gistfile1</a></p>
<p>This constructor function is a local extension of the Rectangle constructor above. It accepts parameters representing width, height, x position, and y position. It also creates a new object using the Rectangle constructor, which we use later. The last thing it does is create a new object literal that contains all the properties we want to be available in PositionedRectangle objects in addition to those that come along with the Rectangle constructor function. There is a 'mixin' method that somehow magically puts the instance of Rectangle and the definition of our PositionedRectangle together, and that is what is returned. The input values are assigned to local function-scope variables that can be accessed by the methods declared within the 'me' object literal that is used in the mixin function.</p>
<p>Essentially, we create two objects using the input parameters to the constructor, then we mix the two objects together to create something new, and that is our result.  The first object is an encapsulated instance of Rectangle, which we'll use for the mixin and possibly local overriddings of methods (we'll do that in a minute). The second object contains a collection of properties that belong to a PositionedRectangle instance, including accessor methods and also a distanceFrom method that accepts another PositionedRectangle and calculates the distance from it.  Time to take a look at the magical 'mixin' function:</p>
<p><a href="http://gist.github.com/343636.js?file=gistfile1">http://gist.github.com/343636.js?file=gistfile1</a></p>
<p>In our case, the 'mixin' function is looping through all the properties of the Rectangle instance we created and putting them directly into the new PositionedRectangle instance we are creating. The only condition is that the property cannot already exist in the PositionedRectangle instance. This is just <em>one</em> way of going about it, but I like it because it allows me to override methods of the Rectangle, as I'm doing below:</p>
<p><a href="http://gist.github.com/343637.js?file=gistfile1">http://gist.github.com/343637.js?file=gistfile1</a></p>
<p>Notice the 'toString' method attached to the object under construction above. In order to take advantage of the toString method within Rectangle, it uses the reference it has to the encapsulated Rectangle object that was created for the mixin process, then adds the x/y location to the string. So now:</p>
<p><a href="http://gist.github.com/343638.js?file=gistfile1">http://gist.github.com/343638.js?file=gistfile1</a></p>
<p>Produces this:</p>
<blockquote class="posterous_short_quote">
<p>(2X3)</p>
<p>6</p>
<p>(6X3) at 0,0</p>
<p>18</p>
<p>141.4213562373095</p>
</blockquote>
<p>Our new instance of PositionedRectangle still has reference to all the Rectangle methods, and its own methods. And it overrides a Rectangle method while still able to call the super class method from within.  I'll try to make another blog post about the performance implications of each of these inheritance methods soon.</p>
	
</p>

<p><a href="http://rhyolight.posterous.com/extending-explicit-object-constructors">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/extending-explicit-object-constructors#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Sat, 20 Mar 2010 21:12:00 -0700</pubDate>
      <title>New brushes for Harmony canvas app</title>
      <link>http://rhyolight.posterous.com/new-brushes-for-harmony-canvas-app</link>
      <guid>http://rhyolight.posterous.com/new-brushes-for-harmony-canvas-app</guid>
      <description>
        <![CDATA[<p>
	<div>If you haven't seen the <a href="http://mrdoob.com/projects/harmony/" title="Harmony">harmony project</a> on the HTML5 <a href="https://developer.mozilla.org/en/HTML/Canvas" title="Mozilla docs on canvas tag">canvas</a>, you are missing out. This is a very cool drawing canvas with really interesting brushes. I was reading <a href="http://mrdoob.com/blog/post/689" title="MrDoob's blog post about harmony">MrDoob's blog</a> about his project and he mentioned how his code was modular, so new brush strokes could be added easily. So I thought I would give it a <a href="http://storage.dangertree.net/harmonyStrokes/harmony.html#curvy" title="My Curvy brush">try</a> <a href="http://storage.dangertree.net/harmonyStrokes/harmony.html#stringy" title="My stringy brush">myself</a>. The source is on <a href="http://github.com/rhyolight/Harmony-Brushes" title="My source for my brushes on github">github</a>.</div>
<p />
<div>I pulled the javascript from his page and it only took a few minutes to figure it out. It turns out it was really simple to create a new brush type and add it into the whole program. The only code you really need to write is code that draws a line from the last point to the current point. There is a function called 'stroke' that accepts a coordinate for the current point to be drawn. A fun tactic is not only to store the previous coordinate, but an array of all points that have been drawn in the line so there can be interactions between the current point and any previous points.</div>
<p />
<div>Here is the code for my first brush: stringy:</div>
<p><a href="http://gist.github.com/339068.js?file=stringy">http://gist.github.com/339068.js?file=stringy</a></p>
<p />
<div>In the stroke function, the line isn't actually drawn to the point where the mouse points, but to a random point nearby. Then lines with smaller weights are drawn backward from that point to 10 points in the array of points behind it. This creates a "string art" effect.</div>
<p />
<div>The next brush is called 'curvy' for obvious reasons:</div>
<p><a href="http://gist.github.com/339070.js?file=curvy">http://gist.github.com/339070.js?file=curvy</a></p>
<p />
<div>This one draws a line to the current point where the mouse is, then it draws a bezier curve backward to a point 30 points away along the line, using two other points along the curve as control points. It makes for an interesting curvy effect that looks cool when you make lots of random turns.</div>
<p><div class='p_embed p_image_embed'>
<a href="http://posterous.com/getfile/files.posterous.com/rhyolight/rMGMsQ7rfEVm4tS5wMqN1UxiIsOucMc3ZHFThMWxrjkXy5EiWCgvcH0pP1zS/Screen_shot_2010-03-20_at_8.58.png"><img alt="Screen_shot_2010-03-20_at_8" height="350" src="http://posterous.com/getfile/files.posterous.com/rhyolight/CPZpu9XHFf69zgikuxpYmENcm3I1r59DaqzQjM3hf0d4SvF62IgilMOLuvW0/Screen_shot_2010-03-20_at_8.58.png.scaled.500.jpg" width="500" /></a>
<a href="http://posterous.com/getfile/files.posterous.com/rhyolight/SaIT5kxfiv3yeQEZ3AJ5xaXEYkiCKLpjksqFISnVdMeGv7Ev5BmKELTOEIx2/Screen_shot_2010-03-20_at_8.59.png"><img alt="Screen_shot_2010-03-20_at_8" height="372" src="http://posterous.com/getfile/files.posterous.com/rhyolight/eTWE9iTDAOQizu2gbzZNzVg14Qy35nqICa5YltIVMHmVzcOpy0cRU1U4Uz78/Screen_shot_2010-03-20_at_8.59.png.scaled.500.jpg" width="500" /></a>
<div class='p_see_full_gallery'><a href="http://rhyolight.posterous.com/new-brushes-for-harmony-canvas-app">See the full gallery on Posterous</a></div>
</div>
</p>
	
</p>

<p><a href="http://rhyolight.posterous.com/new-brushes-for-harmony-canvas-app">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/new-brushes-for-harmony-canvas-app#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="672" width="960" url="http://getfile8.posterous.com/getfile/files.posterous.com/rhyolight/rMGMsQ7rfEVm4tS5wMqN1UxiIsOucMc3ZHFThMWxrjkXy5EiWCgvcH0pP1zS/Screen_shot_2010-03-20_at_8.58.png">
        <media:thumbnail height="350" width="500" url="http://getfile9.posterous.com/getfile/files.posterous.com/rhyolight/CPZpu9XHFf69zgikuxpYmENcm3I1r59DaqzQjM3hf0d4SvF62IgilMOLuvW0/Screen_shot_2010-03-20_at_8.58.png.scaled.500.jpg" />
      </media:content>
      <media:content type="image/png" height="589" width="792" url="http://getfile2.posterous.com/getfile/files.posterous.com/rhyolight/SaIT5kxfiv3yeQEZ3AJ5xaXEYkiCKLpjksqFISnVdMeGv7Ev5BmKELTOEIx2/Screen_shot_2010-03-20_at_8.59.png">
        <media:thumbnail height="372" width="500" url="http://getfile3.posterous.com/getfile/files.posterous.com/rhyolight/eTWE9iTDAOQizu2gbzZNzVg14Qy35nqICa5YltIVMHmVzcOpy0cRU1U4Uz78/Screen_shot_2010-03-20_at_8.59.png.scaled.500.jpg" />
      </media:content>
    </item>
    <item>
      <pubDate>Fri, 19 Mar 2010 09:36:00 -0700</pubDate>
      <title>JavaScript Inheritance Part 2: The Explicit Object Construction Model</title>
      <link>http://rhyolight.posterous.com/javascript-inheritance-part-2-the-explicit-ob</link>
      <guid>http://rhyolight.posterous.com/javascript-inheritance-part-2-the-explicit-ob</guid>
      <description>
        <![CDATA[<p>
	<p>Let's walk through the construction of the Rectangle class from the <a href="http://rhyolight.posterous.com/javascript-constructors-for-dummies" title="JavaScript Inheritance Part 1: The Classic Model">previous blog post</a> in a completely different way.  Remember from the previous blog post:</p>
<blockquote class="posterous_medium_quote">If the constructor function returns anything <em>explicitly</em>, <strong>the object under construction is completely discarded</strong>, and the constructor will return what you told it to return. Whatever you told it to return will <strong>NOT</strong> have a prototype property.</blockquote>
<p>In this method of construction, we're going to explicitly create an object literal and return it from the constructor function. This example will start small and build into a working solution.   First thing's first, we'll simply return an object from the constructor function that contains the things each instance should have</p>
<p><a href="http://gist.github.com/337760.js?file=blog_bad_example">http://gist.github.com/337760.js?file=blog_bad_example</a></p>
<p>This isn't quite right, but I want to show why it doesn't work before we make the changes necessary for it to work properly. In this snippet, we are putting the input w &amp; h parameters directly into an object literal as properties for width and height. We also have an area method that simply multiplies the input parameters together to calculate area. Let's identify the first problem with our class by creating a new object and trying to call the area method on it.</p>
<p><a href="http://gist.github.com/337762.js?file=blog_out_1">http://gist.github.com/337762.js?file=blog_out_1</a></p>
<p>outputs:</p>
<div class="output">area: 6</div>
<p>Hey, it works great, right? Well yes, until you attempt to assign a new value to width or height. Try this:</p>
<p><a href="http://gist.github.com/337766.js?file=blog_out_2">http://gist.github.com/337766.js?file=blog_out_2</a></p>
<p>outputs:</p>
<div class="output">area: 6<br /> area: 6</div>
<p>Doesn't work so well anymore, but we can fix this easily. This makes sense because we are reassigning the rectangle instance property 'width' to a new value, but the area function isn't using it to do its calculation:</p>
<p><a href="http://gist.github.com/337768.js?file=blog_snip1">http://gist.github.com/337768.js?file=blog_snip1</a></p>
<p>The area method is using the w &amp; h input parameters to the constructor function, and those never change, even if 'width' and 'height' are reassigned! You might think that those input parameters are completely discarded when the constructor has finished executing, but because of closure scope the area function has reference to the parameters values for its entire lifespan.  We don't want to compute the area based only on the unchanging input parameters to the constructor or else changes to each instance object will never be reflected in our calculation. But it turns out it is simple to update the area method to refer to the value of the current instance where the method is being called from.</p>
<p><a href="http://gist.github.com/337771.js?file=blog_snip2">http://gist.github.com/337771.js?file=blog_snip2</a></p>
<p>In our case above, 'this' inside the area method refers to the object on which the method is being called, which is almost always the object literal that is being created in the Rectangle constructor (for a wealth of information on what 'this' means in different contexts, Lucas Smith has an excellent article <a href="http://lucassmith.name/pub/this.html" title="Lucas Smith's article on this in JavaScript">here</a>). So our constructor now looks like this:</p>
<p><a href="http://gist.github.com/337772.js?file=blog_good1">http://gist.github.com/337772.js?file=blog_good1</a></p>
<p>I've also added a toString method that will help us print information about this object later on (sound familiar, Java folks?). So now we can test it out again:</p>
<p><a href="http://gist.github.com/337774.js?file=blog_out_3">http://gist.github.com/337774.js?file=blog_out_3</a></p>
<p>outputs:</p>
<div class="output">area of (2X3): 6<br /> area of (5X3): 15</div>
<p>Awesome. Now let's talk about...</p>
<h4>Encapsulation</h4>
<p>Essentially, everything we shove inside the object the constructor is returning will be public. Anything we do outside of that object is private. This is a powerful concept that most Java programmers are very familiar with. The convention in the Java world is to make everything private and only open up things that need to be accessed through accessor methods. Well, we can do the same thing with JavaScript. Check this out.</p>
<p><a href="http://gist.github.com/337776.js?file=blog_good2">http://gist.github.com/337776.js?file=blog_good2</a></p>
<p>First, I've declared variables inside the constructor function called 'width' and 'height' and assigned the corresponding input parameters to them. That's all I'm doing with the input parameters to the Rectangle constructor -- just assigning them to some internal variables. From here on out I'll use my references to these only.  I have getters and setters for 'width' and 'height' as well, and these are <em>public</em> because they are members of the object literal that is being created and returned by the constructor. The 'width' and 'height' values themselves are entirely <em>private</em>, but the accessor methods will always have reference to them because of closure scope. Notice particularly that none of the references to 'width' or 'height' within the instance methods reference them through the 'this' keyword. That is because there are no longer width and height properties on the object being constructed! They are private now, so we cannot reference them. The functions can, however, directly reference the private 'width' and 'height' variables because of closure scope.  So now we use our Rectangle like this:</p>
<p><a href="http://gist.github.com/337779.js?file=blog_out_4">http://gist.github.com/337779.js?file=blog_out_4</a></p>
<p>which outputs:</p>
<div class="output">area of (2X3): 6<br /> area of (5X3): 15</div>
<h4>A word about prototypes</h4>
<p>Objects created using the Explict Object Construction Model as shown above <strong><em>have no prototype</em></strong>. So if you think you can do something like this:</p>
<p><a href="http://gist.github.com/337781.js?file=blog_proto1">http://gist.github.com/337781.js?file=blog_proto1</a></p>
<p>... and then all instances of Rectangle will have a perimeter() function, you are wrong! The prototype object does <strong>not</strong> come into play using this method. It is entirely ignored. In fact, do you remember from the previous blog post about how using the 'new' keyword invokes a function as a constructor, and special things happen? Well when using this method, that makes no difference what-so-ever. You don't even have to use the 'new' keyword when you create a new instance. We could just as easily do this:</p>
<p><a href="http://gist.github.com/337783.js?file=blog_no_new">http://gist.github.com/337783.js?file=blog_no_new</a></p>
<p>... with exactly the same result.</p>
<p>Stay tuned for my next post, which will go over extending this explicit object&nbsp;construction&nbsp;model.</p>
	
</p>

<p><a href="http://rhyolight.posterous.com/javascript-inheritance-part-2-the-explicit-ob">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/javascript-inheritance-part-2-the-explicit-ob#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Fri, 12 Mar 2010 12:00:00 -0800</pubDate>
      <title>JavaScript Inheritance Part 1: The Classic Model</title>
      <link>http://rhyolight.posterous.com/javascript-constructors-for-dummies</link>
      <guid>http://rhyolight.posterous.com/javascript-constructors-for-dummies</guid>
      <description>
        <![CDATA[<p>
	<p>This has confused me since I started working in JavaScript. One of the most powerful things about the language also makes it very confusing at times, and that is its extreme versatility. I'm going to show you the classic way to create constructors that create objects. These constructors are sometimes loosely called "classes" in some JavaScript texts, but I don't like calling them that because it confuses Java programmers (read: me). The constructor is really just a <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function" title="JavaScript Function docs">Function</a>. When invoked with the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/new_Operator" title="new operator docs">new</a> operator ("new FineYoungCannibal()" for example) the function acts as a constructor, and the returning value is will be the new "<em>instance</em>" of the "<em>class</em>". <em>I am using these terms very loosely!</em> These are not <em>classes</em> and <em>instances</em> in a Java sense of the term. They are constructor functions that define the shape of objects they will create in the future.</p>
<p><a href="http://gist.github.com/330515.js?file=classic_constructor">http://gist.github.com/330515.js?file=classic_constructor</a></p>
<p>Rectangle is a Function object. When a function is executed normally -- without the 'new' operator in front of it -- the logic within the function is executed without ceremony. If the function returns a value explicitly, that value is returned. Otherwise, the return value is 'undefined'.</p>
<p>But when the function is invoked as a constructor, the way the function executes changes a lot.  When a Function is executed as a constructor (with the 'new' operator):</p>
<ol>
<li>Inside the function, 'this' refers to an object that is being created, not the function invoker.</li>
<li>The constructor will implicitly return the object under construction, which is made for you magically by JavaScript.</li>
<li>A property called 'prototype' is attached to the constructor function. This prototype is like an object literal, and it comes along with one property called 'constructor', which points back to the constructor Function (yes, recursively!). <strong>Objects inherit properties from the prototype object of their constructor.</strong> This prototype object will be accessible to every object the constructor function creates implicitly. So the constructor of any instance object can be referred to as instance.prototype.constructor. In the case above, an object created by the Rectangle constructor will have .prototype.constructor that points back to the Rectangle function.</li>
<li>If the constructor function returns anything <em>explicitly</em>, <strong>the object under construction is completely discarded</strong>, and the constructor will return what you told it to return. Whatever you told it to return will <strong>NOT</strong> have a prototype property.</li>
</ol>
<h4>What is a prototype?</h4>
<p>Every Function has a prototype, and they come into play when the function is used as a constructor. The prototype is an object that is used as a blueprint for each object the constructor function creates. If the prototype of the constructor function contains an property called 'cobwebs', then every object created by that constructor will also have the same property. In our case above, we've placed a method called 'area' into the Rectangle prototype, ensuring that every instance that comes out of that constructor function will also have reference to this exact logic.</p>
<p><a href="http://gist.github.com/330515.js?file=classic_constructor">http://gist.github.com/330515.js?file=classic_constructor</a></p>
<p>Now we are only up to <strong>line 5</strong> of the snippet above! After the constructor function has been declared, there is a Rectangle Function object, and it has a prototype property that is like an object literal that contains a reference to the constructor itself. Now we can add stuff into the prototype that we want all objects this constructor creates to have! And that is exactly what is happening on lines 5-7 above. An area function is attached to the prototype, and when it is executed on any object the constructor creates, 'this' evaluates to the object invoking the function, which is of course the instance.  Now, if you want to extend a Rectangle "class" with another "class" that adds more state and behavior to Rectangle, you need to set up a little bit of plumbing before doing so.</p>
<p><a href="http://gist.github.com/330488.js?file=heir">http://gist.github.com/330488.js?file=heir</a></p>
<p>This function comes right out of the <a href="http://www.amazon.com/JavaScript-Definitive-Guide-David-Flanagan/dp/0596101996/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1268424431&amp;sr=8-1" title="link to the Definitive Guide to JavaScript on Amazon.com">Definitive Guide to JavaScript, 5th Ed.</a> by <a href="http://www.davidflanagan.com/" title="link to David Flanagan's blog">David Flanagan</a>. It is a very complete text, and I highly recommend it. Before explaining what this function does, I'll show you how it is used to extend a constructor function:</p>
<p><a href="http://gist.github.com/330487.js?file=classic_inheritance">http://gist.github.com/330487.js?file=classic_inheritance</a></p>
<p>Here, we have the same Rectangle constructor and prototype manipulation as before, and there is also another constructor for a PositionedRectangle. The first thing that happens in this new constructor is a <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/call" title="Function.call docs">call</a> to the "superclass" constuctor. The 'call' method's first argument is always what it will use for 'this' internally. So the Rectangle constructor is being executed here using the PositionedRectangle as the invocation scope (or context). In this way, 'w', and 'h' are passed into the Rectangle constructor and subsequently attached to the object under construction by the PostionedRectangle constructor. The rest of the "subclass" constructor is just attaching more parameters passed into itself onto the object under construction.</p>
<p>It's all very simple, right? Hardly. Now here comes the complicated part. :/</p>
<p>Up to this point, after the PositionedRectangle function has been created, it has a prototype object attached to it just like the Rectangle function, right? But in order for PositionedRectangle to be a "subclass" of Rectangle, we need its prototype to have all the properties of the Rectangle's prototype! How else will we be able to calculate the area of the PositionedRectangle? This is where it gets tricky. Let's focus directly on the code we need to understand:</p>
<p><a href="http://gist.github.com/330820.js?file=heir_focus">http://gist.github.com/330820.js?file=heir_focus</a></p>
<p>The purpose of the 'heir' function is to accept a prototype and create an object that inherits from that prototype. So if we sent the Rectangle prototype into the 'heir' function, we will surely get back an object that we can call area() on. Why? Because Rectangle.prototype has an 'area' property, and prototype properties are always accessible from instances of that prototype.</p>
<p>But in the code above, it looks like heir(Rectangle.prototype) should return just an object with the same prototype as Rectangle, but we are using this value as the prototype for our PostionalRectangle. At first glance, this doesn't make much sense, but you have to realize that the object returned from heir is perfectly acceptable to be used as a prototype because it contains all the methods and properties of the Rectangle prototype. But it doesn't have a meaningful constructor! The constructor that actually created the object coming from heir is 'f() {}', and that means nothing to us. So the last step in completing this convoluted inheritance scheme is to replace the new prototype object's constructor with the Rectangle function.</p>
<h4>In Summary</h4>
<p><a href="http://gist.github.com/330515.js?file=classic_constructor">http://gist.github.com/330515.js?file=classic_constructor</a></p>
<p>Wow, that was not simple, was it? That is a <em>lot</em> of explanation for only 7 lines of code! Luckily, this is one of the most core concepts of JavaScript to understand in able to really use it to its fullest potential. It is also one of the hardest concepts to learn and explain to others, especially if they are used to classical inheritance structures like C++ or Java.</p>
<p>And just to make things more confusing, my <a href="http://rhyolight.posterous.com/javascript-inheritance-part-2-the-explicit-ob" title="Explicit Object Inheritance Model">next blog post</a> will over over an entirely different method of creating constructors and inheritance using explicitly returned object literals without prototypes at all!</p>
	
</p>

<p><a href="http://rhyolight.posterous.com/javascript-constructors-for-dummies">Permalink</a> 

	| <a href="http://rhyolight.posterous.com/javascript-constructors-for-dummies#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1742503/rhyolight_200.jpg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5ebEOOaK2rrr</posterous:profileUrl>
        <posterous:firstName>Matthew</posterous:firstName>
        <posterous:lastName>Taylor</posterous:lastName>
        <posterous:nickName>rhyolight</posterous:nickName>
        <posterous:displayName>Matthew Taylor</posterous:displayName>
      </posterous:author>
    </item>
  </channel>
</rss>

