<?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: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:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Mike G in NYC</title>
	
	<link>http://www.lovemikeg.com/blog</link>
	<description>Mike G's Thoughts on the Web, Code, and Life in The City</description>
	<pubDate>Sat, 17 Oct 2009 06:38:27 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<geo:lat>28.607077</geo:lat><geo:long>-81.30606</geo:long><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/lovemikeg" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>How I Create Secure Passwords</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/FyBXdRCCkoY/</link>
		<comments>http://www.lovemikeg.com/blog/2009/10/16/how-i-create-secure-passwords/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 00:59:12 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=448</guid>
		<description><![CDATA[Recently I was asked about my technique for creating passwords. This made me think and was surprised to realize that as far back as I can recall, I&#8217;ve never had any problem remembering passwords. I&#8217;ve managed to do this by having rigid rules that I always make sure to follow when coming up with passwords:

Every [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was asked about my technique for creating passwords. This made me think and was surprised to realize that as far back as I can recall, I&#8217;ve never had any problem remembering passwords. I&#8217;ve managed to do this by having rigid rules that I always make sure to follow when coming up with passwords:</p>
<ol>
<li>Every account must have a completely unique password. In the event of one of my accounts getting compromised, I want to make sure that the problem is encapsulated to only one account.</li>
<li>Passwords should be hard to memorize by someone other than myself. If a password is revealed in written form, this prevents someone from committing it to memory.</li>
<li>There needs to be a healthy mixture of uppercase, lower case, special characters, and numbers in each password.</li>
<li>Some times, for some ridiculous reason, systems will say you can&#8217;t have special characters in a password. Our password system must account for deviations like this.</li>
<li>Last but not least, generating new passwords should be instantaneous. There should be almost no thought involved.</li>
</ol>
<p>The trick to having each condition satisfied is to have a system. Mine is simple: combine a base &#8220;phrase&#8221; with some dynamic data unique to each account. This means I&#8217;m only required to remember the base phrase. Since every account has a location, identity, and task associated with it; these form the dynamic qualities of the password.</p>
<h3>For example…</h3>
<p>John Doe is married to his lovely wife Jane. He loves her very much and since he&#8217;s a geek, he even involves her into his password scheme, which looks like this: <em>i&lt;3jdVm</em> which if you had to spell it out would be like &#8220;I love Jane Doe VERY much.&#8221;</p>
<p>Cheesy right? That&#8217;s my style. Anyway…</p>
<p>John now takes this scheme and incorporates it into all of his geeky accounts:</p>
<ul>
<li><strong>Twitter:</strong> <em>jdoi&lt;3jdVmtw</em> (assuming that the username is <em>jdoe</em>)</li>
<li><strong>Facebook:</strong> <em>jooi&lt;3jdVmfa</em> (assuming that the username is <em>john.doe@gmail.com</em>)</li>
<li><strong>GMail:</strong> <em>jooi&lt;3jdVmgm</em> (assuming that the username is <em>john.doe@gmail.com</em>)</li>
</ul>
<p>See the pattern? &lt;first two characters of the username&gt; + &lt;some base pass phrase&gt; + &lt;first two characters of the domain name&gt;.</p>
<h3>Unfortunately, this doesn&#8217;t work in all situations.</h3>
<p>Some sites (sadly, like almost all bank sites) <a title="I know, its a damn shame. They deserve a swift kick in the junk. Seriously." href="http://alexduggleby.com/2009/03/13/only-secure-passwords-please-but-no-special-characters-symbols-or-spaces-please/">won&#8217;t allow special characters</a> to be used in a password. Since John uses a non-alphanumeric character, his bank won&#8217;t let him. This is the reason for rule #4.</p>
<p>John decided that in this unfortunate event that he would substitute &#8220;&lt;&#8221; with a &#8220;L&#8221; since it was the closest possible match. Unfortunately, there is no universal solution to this problem. You simply have to have a convention and stick with it. Personally, I see this as an opportunity for greater security: this is yet one more dynamic quality which can be rotated with your password scheme.</p>
<h3>&#8220;Rinse and repeat as necessary&#8221;</h3>
<p>Probably the most important thing to remember out of this whole thing is to change your password often. Think of it as something as important as changing your underwear (or socks if you&#8217;re not into the underwear thing). I like to set a reminder in my calendar to rotate every two months. It also helps to keep a log of all your accounts which need to be updated. If you&#8217;re smart and use <a title="Delicious, IMHO, is the best. Especially after they dropped the dots." href="http://delicious.com/">a social bookmarking service</a>, create a private bundle/set and just run through the list periodically. This process also helps me prune the accounts which I don&#8217;t use anymore, which is another good thing you should be doing.</p>
<p>&#8211;</p>
<p>This is a public service announcement from Mike G. with the intent to make the web a better place. If you liked this post, or even if didn&#8217;t like it, please share your thoughts by leaving a comment below.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=FyBXdRCCkoY:bCTYZwxNjj4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=FyBXdRCCkoY:bCTYZwxNjj4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=FyBXdRCCkoY:bCTYZwxNjj4:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/FyBXdRCCkoY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2009/10/16/how-i-create-secure-passwords/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2009/10/16/how-i-create-secure-passwords/</feedburner:origLink></item>
		<item>
		<title>The Factory Pattern in JavaScript</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/3efOJHNil8Q/</link>
		<comments>http://www.lovemikeg.com/blog/2009/06/26/the-factory-pattern-in-javascript/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 23:08:00 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=424</guid>
		<description><![CDATA[We could also call this article, &#8220;JavaScript Constructors Considered Harmful.&#8221;
I recall reading a post recently which describes factory methods as a best practice. I can&#8217;t tell you how thrilled this made me as I&#8217;ve been advocating this for years, even to the extreme view that the author used as an example: new Form(). 
In my [...]]]></description>
			<content:encoded><![CDATA[<p>We could also call this article, &#8220;JavaScript Constructors Considered Harmful.&#8221;</p>
<p>I recall reading <a href="http://ossigeno.sourceforge.net/blog/content/article/factory-for-everything">a post</a> recently which describes factory methods as a best practice. I can&#8217;t tell you how thrilled this made me as I&#8217;ve been advocating this for years, even to the extreme view that the author used as an example: new Form(). </p>
<p>In <a href="/blog/2009/05/06/upcoming-talk-object-oriented-javascript">my most recent talk at AJAXWorld 2009</a>, I briefly discussed the Factory Pattern as it applies to JavaScript. In my talk, I took a jump away from simple best practices and gave a real-world problem/solution approach to factories in JavaScript. </p>
<p><strong>The problem:</strong> JavaScript will allow you to invoke constructor functions as normal functions.<br />
<strong>The simplest possible solution:</strong> Use a factory method to instantiate everything.</p>
<p>My personal recommendation is to only use constructors internally and to never expose constructors directly.</p>
<h3>What the hell? Why are constructors so bad?</h3>
<p>Constructors in JavaScript are bad because of one thing, and it&#8217;s the same thing that is at the heart of almost all of JavaScript&#8217;s problems: implied global scope. </p>
<p>Consider the following code:</p>
<pre class="prettyprint">
// Define our constructor function
var Person = function (name, location) {
    this.name = name;
    this.location = location;
};

// Create one instance of Person
var mike = new Person('Mike G.', 'NYC');

// Create another instance of Person
var alex = Person('Alex H.', 'NYC');
</pre>
<p>Did you spot my mistake? I omitted the <samp>new</samp> keyword while creating the second <samp>Person</samp> instance. If you run this code in any web browser, you&#8217;ll notice that the browser will redirect you immediately upon running it. </p>
<p>This is a big problem.</p>
<p>When you invoke any function with the <samp>new</samp> keyword, it treats it as a constructor and executes within the context of the newly created instance. When you invoke any function without the <samp>new</samp> keyword, it treats it as a normal function and executes within the context in which the function was defined (typically <samp>window</samp>). </p>
<p>With that knowledge, go back and re-read the code and tell me why the browser redirects now&#8230; </p>
<h3>Factories save the day</h3>
<p>The easiest way to fix this problem is to use a factory. Here&#8217;s my proposed solution:</p>
<pre class="prettyprint">
var Person = function (name, location) {
    return (this === window)
        ? Person.factory(name, location)
        : Person.factory(name, location, this);
};

Person.factory = function (name, location, instance) {
    instance = instance || new Person;
    instance.name = name;
    instance.location = location;

    return instance;
};
</pre>
<p>One of JavaScript&#8217;s brilliant features is that Constructors can have return values. In this example, my constructor is returning the result of the <samp>Person.factory</samp>. It is <samp>Person.factory</samp>&#8217;s job to always return a proper instance and set it up properly. </p>
<p>Now it doesn&#8217;t matter how you invoke this constructor. You can use <samp>new</samp> or you can omit it. This is defensive code and it&#8217;s JavaScript done right. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=3efOJHNil8Q:Lm9Tpn9kFJ4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=3efOJHNil8Q:Lm9Tpn9kFJ4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=3efOJHNil8Q:Lm9Tpn9kFJ4:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/3efOJHNil8Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2009/06/26/the-factory-pattern-in-javascript/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2009/06/26/the-factory-pattern-in-javascript/</feedburner:origLink></item>
		<item>
		<title>Synchronous Execution in JavaScript</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/_TGx7N4ygbw/</link>
		<comments>http://www.lovemikeg.com/blog/2009/05/27/synchronous-execution-in-javascript/#comments</comments>
		<pubDate>Wed, 27 May 2009 08:06:15 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=406</guid>
		<description><![CDATA[Complex front-end web applications generally consist of many components which are initialized and configured at load time. What I&#8217;ve come to find out quite recently is that some browsers simply can&#8217;t handle too many things going on at once (eg: IE6 and lots of DOM operations). 
As a small experiment, I decided to write a [...]]]></description>
			<content:encoded><![CDATA[<p>Complex front-end web applications generally consist of many components which are initialized and configured at load time. What I&#8217;ve come to find out quite recently is that some browsers simply can&#8217;t handle too many things going on at once (eg: IE6 and lots of DOM operations). </p>
<p>As a small experiment, I decided to write a quick system that allows for synchronous execution of functions. In other words, a queue of functions which executes in order and only allows one component to execute at a time. My hopes are that by grouping the initialization routines into segments, the page will become more stable as the effort will be more distributed.</p>
<p>At first the solution sounds simple: just create an array of functions you wish to run, loop over the array and execute each function along the way.</p>
<p>Of course, it just doesn&#8217;t work like that. Function 0 may be complex and take much longer to execute than function 1. In this case, the order of function definition matters very little when compared to the time the function takes to execute.</p>
<p>If you&#8217;re stumped, I&#8217;ve posted <a href="http://code.google.com/p/lovemikeg/source/browse/#svn/synchronous-executor">the solution and a demonstration</a> to the lovemikeg code repository. The breakdown works like this:</p>
<ol>
<li>Like the first proposed solution, an array is used to store functions in the queue.</li>
<li>A next() method is defined which executes the next available function in the queue (if any).</li>
<li>Whenever a function is added to the queue it&#8217;s wrapped in a function which when executed defines another function passed to window.setTimeout. This inner function executes the original function and then immediately calls the next() method</li>
</ol>
<p>It&#8217;s basic I know: There&#8217;s no prioritization&#8230; or scope overriding&#8230; or configurable parameters. This is however, a great example of the power of anonymous functions and closure in JavaScript. I&#8217;m not confident that this will translate over to other languages well, but the pattern certainly will.</p>
<p>Whether this turns out to be a good solution for distributing initialization effort has yet to be determined. As I learn more, I&#8217;ll update this post. </p>
<p><strong>Update May 27, 2009: </strong> Looks like I&#8217;m not the only one thinking about this topic:  <a href="http://cavaliere.org/async">http://cavaliere.org/async</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=_TGx7N4ygbw:mkbZCjgVA_c:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=_TGx7N4ygbw:mkbZCjgVA_c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=_TGx7N4ygbw:mkbZCjgVA_c:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/_TGx7N4ygbw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2009/05/27/synchronous-execution-in-javascript/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2009/05/27/synchronous-execution-in-javascript/</feedburner:origLink></item>
		<item>
		<title>Upcoming Talk: Object Oriented JavaScript</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/2RTlShSM6eM/</link>
		<comments>http://www.lovemikeg.com/blog/2009/05/06/upcoming-talk-object-oriented-javascript/#comments</comments>
		<pubDate>Wed, 06 May 2009 08:28:44 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=401</guid>
		<description><![CDATA[I will be presenting Object Oriented JavaScript at AjaxWorld this year. 
You can find the talk&#8217;s abstract below. I&#8217;m still working on the slides so if there is anything you would like me to touch on, I&#8217;m open to suggestions.
From the Sessions page:
JavaScript has taken a lot of heat over the last few years for [...]]]></description>
			<content:encoded><![CDATA[<p>I will be presenting <em>Object Oriented JavaScript</em> at <a href="http://ajaxworld.com">AjaxWorld</a> this year. </p>
<p>You can find the talk&#8217;s abstract below. I&#8217;m still working on the slides so if there is anything you would like me to touch on, I&#8217;m open to suggestions.</p>
<p>From the <a href="http://ajaxworld.com/event/sessions">Sessions</a> page:</p>
<blockquote><p>JavaScript has taken a lot of heat over the last few years for various reasons, one of which being it&#8217;s lack of proper object orientation. On the contrary, JavaScript is fully object-oriented, supports many types inheritance and also supports member visibility. This talk will explore the JavaScript programming language and will demonstrate several practical design patterns you can use in your JavaScript/Ajax application today.</p></blockquote>
<p>On a somewhat related note, I really need to update my speaking bio and head shots. Any photographers in the audience?</p>
<p>Update: Here are the slides for those who missed out.</p>
<div style="width:425px;text-align:left" id="__ss_1628090"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/mgirouard/object-oriented-javascript-1628090?type=presentation" title="Object Oriented JavaScript">Object Oriented JavaScript</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=objectorientedjavascript-090623151723-phpapp01&#038;stripped_title=object-oriented-javascript-1628090" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=objectorientedjavascript-090623151723-phpapp01&#038;stripped_title=object-oriented-javascript-1628090" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/mgirouard">Michael Girouard</a>.</div>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=2RTlShSM6eM:TZCZdFor7yQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=2RTlShSM6eM:TZCZdFor7yQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=2RTlShSM6eM:TZCZdFor7yQ:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/2RTlShSM6eM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2009/05/06/upcoming-talk-object-oriented-javascript/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2009/05/06/upcoming-talk-object-oriented-javascript/</feedburner:origLink></item>
		<item>
		<title>Review: Learning Dojo by Peter Svensson</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/WLaD9kDZHyI/</link>
		<comments>http://www.lovemikeg.com/blog/2009/02/23/review-learning-dojo-by-peter-svensson/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 02:52:24 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Opinion]]></category>

		<category><![CDATA[Reviews]]></category>

		<category><![CDATA[books]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=346</guid>
		<description><![CDATA[&#8230; or How to Write a Good JavaScript Book
It&#8217;s widely known that the vast majority of JavaScript books that exist are bad. Unfortunately, I have another one to add to the list: Learning Dojo by Peter Svensson.
I fought with myself over whether or not it is a good idea to post this review. I&#8217;m afraid [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; or <em>How to Write a Good JavaScript Book</em></p>
<p>It&#8217;s widely known that the vast majority of JavaScript books that exist are bad. Unfortunately, I have another one to add to the list: Learning Dojo by Peter Svensson.</p>
<p>I fought with myself over whether or not it is a good idea to post this review. I&#8217;m afraid that this review may come across as an attack on the author, the publisher, or the reviewers of the book. Instead of looking at all of the errors in the book one-by-one, I am going to try to write an exhortatory post so I can better communicate what I would expect in any JavaScript book in this class.</p>
<p>To be fair, I don&#8217;t think that the blame for the book&#8217;s poor quality should be entirely on the author. From what I can gather simply from reading it, I would say this book was rushed and not properly reviewed for quality or accuracy. Also, I&#8217;m a purest when it comes to the web; so when I see [what I perceive to be] an outright dismissal of best practices, I start to get a little judgmental. Sorry, I can&#8217;t help it.</p>
<p>So, after over a month, I have finished reading the book cover-to-cover. I&#8217;ll admit that I part of the reason why it took me so long to get through the book was because I  lost interest about halfway through. Chapter 6, Layouts (linked below) is long, tedious and goes against nearly everything I stand for when it comes to building web pages. I simply had to keep putting the book down. Before I get ahead of myself, let me start off start off at the beginning and work our way down.</p>
<h3>Source code should always be carefully formatted</h3>
<p>Whenever someone asks me to critique a web site they have built, one of the first things I do is view the HTML source. If the developer has taken the time to make sure that the code indented properly and consistently spaced, I see that as someone who really cares about the quality of their project. I see it as a sign of a <em>craftsman</em> at work. </p>
<p>In the real world, this is a &#8220;nice to have&#8221; as it doesn&#8217;t really matter much &#8212; just as long as the page functions correctly, I don&#8217;t have much to complain about. In the world of tech books, however, properly formatted source code is a <em>requirement</em>. Remember, people learn from the source. Chances are, people will copy that down character-by-character and think that it&#8217;s the right way to do it.</p>
<p>Listen, JavaScript source code can be complex enough by itself. It&#8217;s an author&#8217;s responsibility to make sure that it&#8217;s as clear as possible so that good habit patterns are established from the jump. In nearly every source code listing in the book, I found something inconsistent, oddly spaced, full of errors, or simply impossible to read. This to me is completely unacceptable and was one of the first things I noticed while reading this book.</p>
<h3>Even JavaScript books should encourage web standards</h3>
<p>Almost every HTML document in the book was invalid. This was mainly due to the fact that Dojo itself encourages the use of custom attributes. Some may argue that there&#8217;s nothing wrong with this practice, especially when making use of a custom DOCTYPE. What&#8217;s worse is that the author made no effort to provide any alternative techniques let alone even discuss the dangers of deliberately writing invalid code. This may have been excusable ten years ago, but not in this day and age.</p>
<p>At the very least, I believe the author should have demonstrated an alternative technique for defining custom attributes &#8212; for example, using a combination of <samp>dojo.addOnLoad</samp> and <samp>setAttribute</samp>, or even better: not use custom attributes at all and use each respective dijit&#8217;s constructor.</p>
<h3><samp>eval</samp> is Evil</h3>
<p>There is only one circumstance where the <samp>eval</samp> function should be used: parsing an Ajax response; and that&#8217;s only allowed after the response has been properly sanitized via a regular expression.</p>
<p>This is a concept which is well known and documented in every programming language with an <samp>eval</samp> function. Nothing further needs to be said about this.</p>
<h3>JavaScript is deep; spend extra time on complex topics</h3>
<p>Because I&#8217;m also working on a post where I explain closures in JavaScript, I was very pleased to see that the author had taken the time out to explain them in this book. Unfortunately, the explanation of closures in Chapter 2 left me more confused than when I had started &#8212; and I&#8217;m quite familiar with the topic. </p>
<p>Admittedly, the problem of JavaScript closures is two-fold: closures are incredibly abstract and secondly, almost nobody knows JavaScript&#8217;s full capabilities as a <a href="http://en.wikipedia.org/wiki/Functional_programming">functional programming language</a>. Source code helps to illuminate the complex topics, but a practical example should be carefully chosen. Two examples are given by the author, however one is broken and the other is completely misleading. This book is better off not even mentioning closures at all.</p>
<p>It also should be mentioned that your explanations should be technically correct. Let me quote the author&#8217;s explanation of how Ajax works:</p>
<blockquote><p>In practices, what happens is that the browser opens a new iframe with zero height and width. Each iframe is capable of loading and posting data independently of each other, and so the accesses of the &#8216;invisible&#8217; iframe will not affect the main page to be reloaded.</p></blockquote>
<p>I&#8217;m not sure if the user was explaining how Dojo does Ajax or if he was trying to simplify the topic into familiar language, but the explanation is just wrong. This makes for a wonderful segue into the next, and equally important topic: proper terminology.</p>
<h3>Never use improper terminology &#8212; ever</h3>
<p>Programming is as much of a science as it is an art form, and as a result any sort of educational material should make use of proper terminology. In areas of introducing new concepts, it&#8217;s quite acceptable to use an analogy or reference another topic in order to build a frame of reference. For example, the author likens JavaScript objects to associative arrays. This is great because the name/value structure of objects in JavaScript are <em>very similar</em> to associative arrays; however, they are not the same thing. All throughout the book, the author uses the term &#8220;associative array&#8221; when he really means &#8220;use an object-literal as an associative array.&#8221;</p>
<p>In other instances, the terms &#8220;parameter&#8221;, &#8220;property&#8221;, and &#8220;attribute&#8221; are used interchangeably when referring to HTML attributes. Switching up vocabulary is just as dangerous as using incorrect terminology. Why? Because it makes you sound like you don&#8217;t know what you&#8217;re talking about. This is really bad when the people you teach start parroting this back. </p>
<h3>Concluding Thoughts</h3>
<p>There you have it, five simple things to keep in mind while reading this book or while attempting to write your own. I&#8217;ll say it again, I don&#8217;t want to attack anyone involved in the publishing of this book. That said, I won&#8217;t apologize for my response. The above mentioned topics are basic and there is simply no excuse for them to have slipped through the cracks.</p>
<p>At the time of this writing, absolutely no <a href="http://www.packtpub.com/support/book/tutorial-for-building-interactive-interfaces-with-dojo">errata</a> has been published for this book. This only adds to the reasons why I simply cannot recommend this book anyone, regardless skill level.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=WLaD9kDZHyI:m__w2j7o-Og:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=WLaD9kDZHyI:m__w2j7o-Og:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=WLaD9kDZHyI:m__w2j7o-Og:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/WLaD9kDZHyI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2009/02/23/review-learning-dojo-by-peter-svensson/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2009/02/23/review-learning-dojo-by-peter-svensson/</feedburner:origLink></item>
		<item>
		<title>Teaser: Learning Dojo by Peter Svensson</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/TdOPXBV9izc/</link>
		<comments>http://www.lovemikeg.com/blog/2009/01/14/teaser-learning-dojo-by-peter-svensson/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 22:02:30 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Opinion]]></category>

		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=318</guid>
		<description><![CDATA[Yesterday I received a review copy of Learning Dojo by Peter Svensson (via Packt Publishing). Over the next week or two, I&#8217;ll be reading it and taking some notes on the book&#8217;s content. When I&#8217;m done, I&#8217;ll follow up with an official book review.
Believe it or not, I&#8217;m actually looking forward to this book as [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I received a review copy of <a href="http://www.packtpub.com/tutorial-for-building-interactive-interfaces-with-dojo/book">Learning Dojo by Peter Svensson</a> (via <a href="http://www.packtpub.com/">Packt Publishing</a>). Over the next week or two, I&#8217;ll be reading it and taking some notes on the book&#8217;s content. When I&#8217;m done, I&#8217;ll follow up with an official book review.</p>
<p>Believe it or not, I&#8217;m actually looking forward to this book as <a href="http://www.dojotoolkit.com/" title="The Dojo JavaScript Toolkit homepage">Dojo</a> is one of the few libraries that I haven&#8217;t spent a great deal of time with. I&#8217;m certainly a fan of component libraries like Dojo, <a href="http://developer.yahoo.com/" title="The Yahoo! User Interface Library home page">YUI</a>, <a href="http://prototypejs.org/" title="The Prototype JavaScript Framework home page">Prototype</a> (YUI being my favorite) so at least the territory is familiar. I do remember there being a few things about the library that were immediate turn-offs to me, but seeing a few best practices mentioned in the book (that&#8217;s the secret to my heart, by the way) and also after the <a href="http://devzone.zend.com/article/3545-Dojo-and-Zend-Framework-Partnership-Announcement">Dojo + Zend partnership announcement</a> of last year, I think giving the library a second try is in order.</p>
<h3>Chapter Summary</h3>
<ol>
<li>Introduction to Dojo</li>
<li>Useful JavaScript and Dojo Tricks</li>
<li>Basic Dijit Knowledge</li>
<li>Ajax Communication</li>
<li>Forms</li>
<li>Layout (<a href="http://www.packtpub.com/files/learning-dojo-sample-chapter-6-layout.pdf">PDF</a>)</li>
<li>Data, Trees, and Grids</li>
<li>Real-World Dojo</li>
</ol>
<p>The book itself seems to offer a pretty good introduction to the library (and JavaScript too). Check out the <a href="http://www.packtpub.com/article/tutorial-for-building-interactive-interfaces-with-dojo-table-of-contents">table of contents</a> and see for yourself.</p>
<div class="update">
<p>Update: You can check out <a href="http://www.packtpub.com/files/learning-dojo-sample-chapter-6-layout.pdf">Chapter 6: Layout</a> for free on the PacktPub website.</p>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=TdOPXBV9izc:nigB_MTH51k:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=TdOPXBV9izc:nigB_MTH51k:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=TdOPXBV9izc:nigB_MTH51k:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/TdOPXBV9izc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2009/01/14/teaser-learning-dojo-by-peter-svensson/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2009/01/14/teaser-learning-dojo-by-peter-svensson/</feedburner:origLink></item>
		<item>
		<title>2009</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/3PtaBKi1VzY/</link>
		<comments>http://www.lovemikeg.com/blog/2009/01/01/2009/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 21:20:16 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Personal Life]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=291</guid>
		<description><![CDATA[Happy New Year everyone. Welcome to 2009. It seems to be the trend these days to be blogging about the past year &#8212; I think that is a healthy activity, and I would love to do the same here but to be quite honest, the entire past year seems like a complete blur. Everything simply [...]]]></description>
			<content:encoded><![CDATA[<p>Happy New Year everyone. Welcome to 2009. It seems to be the trend these days to be blogging about the past year &#8212; I think that is a healthy activity, and I would love to do the same here but to be quite honest, the entire past year seems like a complete blur. Everything simply happened too fast. </p>
<p>I will say this though: 2008 was an incredible year. Here are some quick notes to myself that I intend to keep in mind for this new year (listed in order of importance):</p>
<ol>
<li><strong>I worked entirely too much.</strong> Life is too short to spend all my time working for someone else&#8217;s profit. I need to have more Mike G. Time.</li>
<li><strong>I hate front-end.</strong> It&#8217;s true. I admit it. Front end web development sucks and I think that it always will. I need to move on.</li>
<li><strong>I miss PHP dearly.</strong> I spent way too much time focusing on JavaScript.</li>
<li><strong>I don&#8217;t write enough.</strong> In 2007 I published 49 posts. In 2008 I published only 15 (see note 1 for an explanation why).</li>
<li><strong>Longboarding is therapy.</strong> There is something incredible about catching a natural rhythm of carving back and forth along a nice smooth path.</li>
<li><strong>JavaScript is <a href="http://www.slideshare.net/mgirouard/the-beauty-of-java-script-presentation">beautiful</a> but I need to give it a rest.</strong> In 2007 I <a href="/blog/2007/09/22/barcamp-orlando-slides/">fell in love</a> with it. In 2008 it turned into an obsession.</li>
</ol>
<p>With all this in mind, I am confident that 2009 will be an even greater year than 2008. The goals that I&#8217;ve set for this year are quite ambitious, but that&#8217;s just my nature. I have no doubt that I will be able to accomplish most, if not all long before the end of the year.</p>
<h3>Health</h3>
<p>I really plumped up at the end of 2007 and I continued to swell until around October of 2008 (that&#8217;s when I got my gym membership). It&#8217;s incredible how easy it is to let yourself go and not pay any attention to the food you ingest or the amount of exercise you get (or don&#8217;t get, in my situation). I&#8217;m happy to say that I am already much more aware of my health and will continue to improve as long as I am able. </p>
<p>This year I will: </p>
<ul>
<li>Improve my diet by learning to cook at home more and eat out less.</li>
<li>Get to bed early so I can wake up early and go to the gym <em>before work</em>.</li>
<li>Become more agile and increase my endurance by adding cardio to my workout.</li>
<li>Become more flexible by stretching before, during, and after my workouts.</li>
</ul>
<h3>Finances</h3>
<p>I have always been terrible at managing money. If I see something I want, I buy it&#8230; even if I know it&#8217;s on an impulse. I firmly believe that making a lot of money entitles one self to enjoy their hard-earned money, but balance and moderation are always the best choice.</p>
<p>This year I will: </p>
<ul>
<li>Invest heavily and diversify my portfolio by adding more non-tech securities.</li>
<li>Start planning for retirement by contributing more aggressively to my 401K.</li>
<li>Learn to save my money by analyzing spending patterns and eliminating frivolous, wasteful spending.</li>
</ul>
<h3>Work</h3>
<p>I take my work very seriously, almost to a fault (see point 1 again in my 2008 notes). This year I will enable myself to work less by focusing a lot of effort in optimizing my team&#8217;s workflow. Of course this will not just help me, but will also help anyone else who puts the effort forth to achieve these goals.</p>
<p>This year my team and I will: </p>
<ul>
<li>Eliminate thrashing by raising overall awareness levels (IE: killing autopilot).</li>
<li>Introduce architecture by treating all projects (big and small) like actual software development.</li>
</ul>
<h3>Personal</h3>
<p>This past year I felt like I hadn&#8217;t really accomplished anything. I didn&#8217;t launch any new sites or announce any new projects in my list. Starting this year I won&#8217;t let that happen again.</p>
<p>This year I will: </p>
<ul>
<li>Improve my writing by blogging once per week.</li>
<li>Begin organizing regular Refresh NYC meetings (Note: this has already begun so stay tuned for details).</li>
<li>Attend more conferences as a speaker by actually submitting proposals to CFP&#8217;s (instead of waiting for opportunities to find me).</li>
</ul>
<p>So there you have it. Like I said, I don&#8217;t have any problem saying that I can accomplish all of these. I hope that everyone else out there has done themselves a favor by conducting a personal retrospective like this. With that knowledge you can really see areas of your life which need improving. Setting goals (even ambitious ones) also really help motivate people to improve themselves and their quality of life. </p>
<p>Happy 2009 everyone.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=3PtaBKi1VzY:yjtIQODnuos:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=3PtaBKi1VzY:yjtIQODnuos:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=3PtaBKi1VzY:yjtIQODnuos:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/3PtaBKi1VzY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2009/01/01/2009/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2009/01/01/2009/</feedburner:origLink></item>
		<item>
		<title>Thoughts on Professional Entrance Exams</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/Kpt4yqiraiw/</link>
		<comments>http://www.lovemikeg.com/blog/2008/10/27/thoughts-on-professional-entrance-exams/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 05:54:19 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=266</guid>
		<description><![CDATA[In a recent surge to bring new freelancers (and full-timers) in to work with us, we began to make candidates take an entrance exam. I debated with myself over this for quite some time because I wasn&#8217;t really sure if it was entirely necessary. When you think about it, why wouldn&#8217;t a good old-fashioned phone [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent surge to bring new freelancers (and full-timers) in to work with <a href="http://www.mcdpartners.com/">us</a>, we began to make candidates take an entrance exam. I debated with myself over this for quite some time because I wasn&#8217;t really sure if it was entirely necessary. When you think about it, why wouldn&#8217;t a good old-fashioned phone interview/in-person interview work? Well, as we have come to find out, it doesn&#8217;t. I am still amazed at the staggering number of low-quality candidates that have been responding to our job postings, most of which come from professional staffing agencies.</p>
<p>Some people would be completely satisfied hiring the first buzzword-emitting person who makes a good cultural fit. I however, don&#8217;t share the same sentiments. I like to make sure that the people who I work with, and share code with, are going to do a good job. I will be the first to admit that there is a great deal of inherited technical debt that I&#8217;m trying to work through (as is the case with most people in my position), and I am certainly not trying to create any more. By creating an entrance exam, companies like the one I work for can, at the very least, insure that the people that they hire are able to perform the tasks in which they were tested. </p>
<h3>The Format</h3>
<p>The first time I ever experienced an entrance exam was at Yahoo! when I was shooting for a Front-end Engineer position back in 2006. This began by a series of Engineers calling me up and asking me technical questions to get a feel for how much I actually know. After a few days of this, I was flown out to Sunnyvale, CA where I continued my interviews in person. I met with several different teams of people, each of which asked me questions testing my knowledge in XHTML, CSS, JavaScript, PHP, standards, semantics, accessibility, and so on.</p>
<p>My company&#8217;s core competencies don&#8217;t match that of Yahoo&#8217;s, so I can&#8217;t quite implement the same tests; I can, however, implement a format similar to theirs. At MCD, candidates are given a 15 to 20 minute phone interview to find out whether or not they can keep a conversation going about the web. I also ask them questions pertinent to the level of developer they are applying for (Developer, Sr. Developer, etc.). Generally questions cover XHTML, CSS, and JavaScript at the minimum, but I always taylor the conversation since obviously no two candidates are the same.</p>
<p>After the phone interview, if the candidate proved him or herself, I arrange for them to come in for an in-person interview. During this interview, we of course go through the normal motions of a traditional interview, but we also administer a practical exam. I won&#8217;t disclose the details of the exam, but I will say that they are required to demonstrate their skills at solving common XHTML, CSS, and JavaScript problems.</p>
<h3>Feedback&#8230; Please.</h3>
<p>I&#8217;m curious if anyone has created a professional entrance exam for their company, or maybe even been on the receiving end. We are in the process of refining the tests to better hone in on the tasks that each developer level is expected to perform.</p>
<p>What are your thoughts? Is this a good format? What would you do if you were tasked with something similar?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=Kpt4yqiraiw:Ic89z5jfm9g:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=Kpt4yqiraiw:Ic89z5jfm9g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=Kpt4yqiraiw:Ic89z5jfm9g:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/Kpt4yqiraiw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/10/27/thoughts-on-professional-entrance-exams/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2008/10/27/thoughts-on-professional-entrance-exams/</feedburner:origLink></item>
		<item>
		<title>AjaxWorld 2008 Wrap-up</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/gdow7uWjggM/</link>
		<comments>http://www.lovemikeg.com/blog/2008/10/23/ajaxworld-2008-wrap-up/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 04:19:56 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=276</guid>
		<description><![CDATA[So I&#8217;ve gone dark for a while, I know. You don&#8217;t need to remind me. Truth be told, I put almost every ounce of spare time into perfecting my talk that I just presented this week at AjaxWorld West 2008. From the feedback I gathered, it went over pretty well.
For those of you who missed [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve gone dark for a while, I know. You don&#8217;t need to remind me. Truth be told, I put almost every ounce of spare time into perfecting my talk that I just presented this week at <a href="http://ajaxworld.com/event/session/63">AjaxWorld West 2008</a>. From the feedback I gathered, it went over pretty well.</p>
<p>For those of you who missed it, you can <a href="http://www.slideshare.net/mgirouard/the-beauty-of-java-script-presentation">view it on SlideShare</a> or <a href="/downloads/talks/the-beauty-of-javascript/ajaxworld2008.pdf">download the PDF</a>. Since the majority of the slides are code, you would probably be better off just downloading the <a href="/downloads/talks/the-beauty-of-javascript/ajaxworld2008-notes.pdf">PDF with my presenter notes</a>. </p>
<p>Overall, the conference went really well. Since I had never been to a Sys-Con event before, I didn&#8217;t know quite what to expect. If I had to compare it with previous conferences I&#8217;ve attended, I would say that this was definitely one of the better ones; they really know how to put on a good show. There were lots of really smart geeks, lots interesting talks and yes even a fair share of interesting product demos. Normally, I&#8217;m not one to pay attention to vendors taking up valuable podium time, but I&#8217;ll admit that there were some really awesome products that I saw first-hand.</p>
<p>I do have one regret though: not attending <a href="http://ajaxsecuritybootcamp.sys-con.com/">Billy Hoffman&#8217;s Ajax Security Bootcamp</a> sooner. I walked in about half-way through and only caught the tail-end of it. Billy was youthful, energetic and too smart for his own good (maybe that&#8217;s why he&#8217;s so into security). If you ask me, his workshop was the best out of them all.</p>
<p>I also got to see Douglas Crockford speak live for the first time. That was pretty amazing too. Granted, it was a talk I had already seen before (and I also read the book too), but it&#8217;s a completely different experience hearing and seeing it right before you.</p>
<p>I&#8217;m not sure when or where AjaxWorld will appear next, but I&#8217;m hoping it will be in NYC like it was earlier this year. There is a SOAWorld that I&#8217;ll be submitting my long-awaited <em>Consuming Web Services in JavaScript</em> talk to. </p>
<p>We shall see.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=gdow7uWjggM:R0B4X1Q_F_o:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=gdow7uWjggM:R0B4X1Q_F_o:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=gdow7uWjggM:R0B4X1Q_F_o:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/gdow7uWjggM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/10/23/ajaxworld-2008-wrap-up/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2008/10/23/ajaxworld-2008-wrap-up/</feedburner:origLink></item>
		<item>
		<title>A Week in JavaScript Patterns: Lazy Function Definition</title>
		<link>http://feedproxy.google.com/~r/lovemikeg/~3/QNOWojkBrak/</link>
		<comments>http://www.lovemikeg.com/blog/2008/08/21/a-week-in-javascript-patterns-lazy-function-definition/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 11:53:06 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=205</guid>
		<description><![CDATA[Lazy Function Definition is a pattern of functional JavaScript programming, similar to Load Time Configuration. The key difference is that the final function value isn&#8217;t configured at load time, but rather upon the first invocation of the function.
The Lazy Function Definition pattern was discovered and named by Peter Michaux.
Motivation
Generally there are two main reasons for [...]]]></description>
			<content:encoded><![CDATA[<p>Lazy Function Definition is a pattern of functional JavaScript programming, similar to <a href="/blog/2008/08/18/a-week-in-javascript-patterns-load-time-configuration/">Load Time Configuration</a>. The key difference is that the final function value isn&#8217;t configured at load time, but rather upon the first invocation of the function.</p>
<p>The Lazy Function Definition pattern was discovered and named by <a href="http://peter.michaux.ca/article/3556">Peter Michaux</a>.</p>
<h3>Motivation</h3>
<p>Generally there are two main reasons for wanting to defer defining functions until a later time (although with any pattern, many other applications exist):</p>
<ol>
<li>Resources required for a function to be fully defined are not available until the page fully loads or until a user-driven event (for example, determining page scroll).</li>
<li>The resources created by defining the function are particularly taxing and may not even be needed (for example <a href="http://mattsnider.com/javascript/xbrowser-event-handling/">attaching event handlers</a>).</li>
</ol>
<h3>Implementation</h3>
<p>The Lazy Function Definition solves these problems by defining resources upon the first invocation of the function and then redefining itself so that they are not recreated during subsequent calls. All resources are stored via closure so they remain available to the inner function (which becomes the new definition for the outer function).</p>
<pre class="prettyprint">
var getResource = function () {
    var resource, counter;

    resource = 'foo';
    counter = 0;

    getResource = function () {
        return resource + ' has been accessed ' + (++counter) + ' times';
    };

    return getResource();
};
</pre>
<p>In the code above, a <samp>getResource</samp> function is defined. When the function is called the first time, <samp>resource</samp> and <samp>counter</samp> are created to store important information which is needed in future calls to <samp>getResource</samp>. </p>
<p>The function which immediately follows <em>redefines</em> the original <samp>getResource</samp> function, but because resource <samp>resource</samp> and <samp>counter</samp> are defined in the same scope as the inner function, they remain available.</p>
<p>Finally, the new <samp>getResource</samp> is executed and it&#8217;s value is returned. Now any future calls to <samp>getResource</samp> will use the inner function. </p>
<h3>Conclusion</h3>
<p>The Lazy Function Definition pattern allows for deferred function definition as well as insuring that resources that only need to be created once, are created once.</p>
<ul>
<li><strong>Sunday:</strong> <a href="/blog/2008/08/17/a-week-in-javascript-patterns-self-invocation/">Self-invocation</a></li>
<li><strong>Monday:</strong> <a href="/blog/2008/08/18/a-week-in-javascript-patterns-load-time-configuration/">Load Time Configuration</a></li>
<li><strong>Tuesday:</strong> <a href="/blog/2008/08/19/a-week-in-javascript-patterns-the-module/">The Module</a></li>
<li><strong>Wednesday:</strong> Lazy Function Definition</li>
</ul>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/lovemikeg?a=QNOWojkBrak:cCP60Ym1oI8:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=QNOWojkBrak:cCP60Ym1oI8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/lovemikeg?a=QNOWojkBrak:cCP60Ym1oI8:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/lovemikeg?d=dnMXMwOfBR0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/lovemikeg/~4/QNOWojkBrak" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/08/21/a-week-in-javascript-patterns-lazy-function-definition/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.lovemikeg.com/blog/2008/08/21/a-week-in-javascript-patterns-lazy-function-definition/</feedburner:origLink></item>
	</channel>
</rss>
