<?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:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>James Padolsey</title>
	
	<link>http://james.padolsey.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 06 May 2012 17:31:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JamesPadolsey" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="jamespadolsey" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">JamesPadolsey</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FJamesPadolsey" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FJamesPadolsey" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FJamesPadolsey" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://feeds.feedburner.com/JamesPadolsey" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FJamesPadolsey" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FJamesPadolsey" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FJamesPadolsey" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
		<title>Move that parenthesis!</title>
		<link>http://james.padolsey.com/javascript/move-that-parenthesis/</link>
		<comments>http://james.padolsey.com/javascript/move-that-parenthesis/#comments</comments>
		<pubDate>Sun, 06 May 2012 17:31:52 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2084</guid>
		<description><![CDATA[JavaScript style guides seem to be all the rage recently. The thing is, I&#8217;ve never really agreed fully with any existing style guide.

It would seem to be in the spirit of the community to just fork one and make changes, but I won&#8217;t. The&#8230;]]></description>
			<content:encoded><![CDATA[<p>JavaScript style guides seem to be all the rage recently. The thing is, I&#8217;ve never really agreed fully with any existing style guide.</p>

<p>It would seem to be in the spirit of the community to just fork one and make changes, but I won&#8217;t. The conclusion I&#8217;ve come to is that there is no one perfect style guide and the existing ones don&#8217;t seem to address the things that really make code hard to understand.</p>

<p>The idea is that adopting a single coding style will ease the development in a large team. Each team member will supposedly find it easier to maintain other team members&#8217; code because they use the same &#8220;style&#8221; of coding. What does &#8220;style&#8221; even mean though?</p>

<blockquote><p><em>an elegant, fashionable, or luxurious mode of living: to live in style.</em></p></blockquote>

<p>That doesn&#8217;t sound right. Maybe it&#8217;s this one:</p>

<blockquote><p><em>a particular kind, sort, or type, as with reference to form, appearance, or character: the baroque style; The style of the house was too austere for their liking. [<a href="http://dictionary.reference.com/browse/style">src</a>]</em></p></blockquote>

<p>So, it seems to be concerned with the appearance, the visual form, the aesthetic etc.</p>

<p>Like everyone, I have my preferences when it comes to variable declarations and whitespace between operators but I will readily admit that what makes code easier to read for me might do the very opposite for someone else.</p>

<p>And I could get ridiculously pernickety about it too:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw1">for</span> <span class="br0">&#40;</span> <span class="sy0">;</span> i <span class="sy0">&lt;</span> l<span class="sy0">;</span> i<span class="sy0">++</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span>  ...</pre></div></div>




<p>You see the first semi-colon? Well, it doesn&#8217;t agree with me, aesthetically. I don&#8217;t like it. It&#8217;s given too much weight, nestled between so much whitespace. I think I&#8217;d prefer it to immediately follow the opening parenthesis. But, No! I cannot, for it doesn&#8217;t comply with the style guide! This isn&#8217;t the <a href="http://james.padolsey.com/javascript/ordering-variable-declarations/">first time a style guide has bitten me</a>.</p>

<p>That was petty, I know. Musing over an operator like an eccentric art critic would. I shouldn&#8217;t take these guides so seriously perhaps. After all, Style guides are &#8220;guides&#8221; only. They&#8217;re not commandments. But that&#8217;s just it! They&#8217;re not, and so why do we impress them upon our peers so religiously?</p>

<p>Just to repeat something: <em>what makes code easier to read for me might do the very opposite for someone else</em>!</p>

<p>Addy Osmani recently posted a very good <a href="http://addyosmani.com/blog/javascript-style-guides-and-beautifiers/">overview of JavaScript style guides</a>. To demonstrate one of the styles he took a piece of code and transformed it to comply with the guide. I found the resulting code to be harder to read than the former. This is just me, of course, but surely I can&#8217;t be the only one? In fact, the sheer amount of different style guides proves that I&#8217;m not the only one.</p>

<p>What style guides do a good job at is promoting conformance to <em>something</em>. It doesn&#8217;t matter what. At the end of the day what they aim for is <strong>consistency</strong>.</p>

<p>But, surely, code can still be <em>consistently awful</em> and difficult to understand. No style guide can help me understand how you think &#8212; how your mind forms algorithms &#8212; how you go about solving a problem using the path of least resistance. Reading other peoples&#8217; code is eased only slightly by their conformance to a style guide. Only slightly&#8230;</p>

<p>A style guide will merrily slap your hand when you misplace a comma or semi-colon, but nothing will slap you when you form an incoherent API, or don&#8217;t put enough thought into your module&#8217;s design, or when you use DOM nodes to store program state. No. Nothing will stop you in these cases.</p>

<p>I know this isn&#8217;t a strong argument against style guides. And that&#8217;s fine. I don&#8217;t want to rid the world of them. I just want to say that they do not uniformly solve all problems and may sometimes make it harder to understand code.</p>

<p>In my opinion a style guide should be more liberal and steer clear of the realm of subjectivity. It should ensure an overall consistency and that&#8217;s all. Don&#8217;t tell me where to place something so tiny as a piece of punctuation, unless it has actual ramifications (like with the semi-colon debate). I will place the parenthesis as my mind instructs me &#8212; as my best judgement deems most understandable to the reader of my code. Otherwise I&#8217;m just a code monkey punching away as per instructed by sub-section 4.3 of that &#8220;style guide&#8221; you&#8217;re waving around.</p>
]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/move-that-parenthesis/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Zerg rush in JavaScript</title>
		<link>http://james.padolsey.com/javascript/zerg-rush-in-javascript/</link>
		<comments>http://james.padolsey.com/javascript/zerg-rush-in-javascript/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 19:53:14 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2077</guid>
		<description><![CDATA[
  You may have recently seen Google&#8217;s &#8220;<a href="https://www.google.com/search?aq=f&#038;sourceid=chrome&#038;ie=UTF-8&#038;q=zerg+rush">Zerg Rush</a>&#8221; Easter Egg.
  I thought it&#8217;d be fun to try doing something like this myself. <a href="/demo/ZergRush/demo.html">See my
  demo</a> before you read on. As you can see it&#8217;s not as polished as the
  Google version but the basic behaviour is&#8230;]]></description>
			<content:encoded><![CDATA[<p>
  You may have recently seen Google&#8217;s &#8220;<a href="https://www.google.com/search?aq=f&#038;sourceid=chrome&#038;ie=UTF-8&#038;q=zerg+rush">Zerg Rush</a>&#8221; Easter Egg.
  I thought it&#8217;d be fun to try doing something like this myself. <a href="/demo/ZergRush/demo.html">See my
  demo</a> before you read on. As you can see it&#8217;s not as polished as the
  Google version but the basic behaviour is the same.
</p>

<p>
  I haven&#8217;t looked at Google&#8217;s source so I&#8217;m not sure how they chose to do it,
  but for me there was no other route more obvious than <a href="https://developer.mozilla.org/en/DOM/document.elementFromPoint"><code>elementFromPoint</code></a>,
  a DOM method that returns the element at any defined coordinate within the 
  current viewport.
</p>

<p>
  So, I create a bunch of little Zergling instances. Each Zerling searches for &#8220;targets&#8221;,
  i.e. any DOM element nearby. A Zergling instance will begin by looking in its close
  proximity, calling <code>elementFromPoint</code> at eighth-degree turns around a
  steadily increasing radius:
</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="co1">// (Zergling.prototype.findTarget)</span>
&nbsp;
<span class="kw1">for</span> <span class="br0">&#40;</span>radius <span class="sy0">=</span> <span class="nu0">10</span><span class="sy0">;</span> radius <span class="sy0">&lt;</span> Zergling.<span class="me1">VISION</span><span class="sy0">;</span> radius <span class="sy0">+=</span> <span class="nu0">50</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="kw1">for</span> <span class="br0">&#40;</span>degree <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> degree <span class="sy0">&lt;</span> <span class="nu0">360</span><span class="sy0">;</span> degree <span class="sy0">+=</span> <span class="nu0">45</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
    x <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">x</span> <span class="sy0">+</span> halfWidth <span class="sy0">+</span> radius <span class="sy0">*</span> cos<span class="br0">&#40;</span>PI<span class="sy0">/</span><span class="nu0">180</span> <span class="sy0">*</span> degree<span class="br0">&#41;</span> <span class="sy0">-</span> scrollLeft<span class="sy0">;</span>
    y <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">y</span> <span class="sy0">+</span> halfHeight <span class="sy0">+</span> radius <span class="sy0">*</span> sin<span class="br0">&#40;</span>PI<span class="sy0">/</span><span class="nu0">180</span> <span class="sy0">*</span> degree<span class="br0">&#41;</span> <span class="sy0">-</span> scrollTop<span class="sy0">;</span>
&nbsp;
    <span class="kw1">if</span> <span class="br0">&#40;</span>Zergling.<span class="me1">isSuitableTarget</span><span class="br0">&#40;</span>el <span class="sy0">=</span> doc.<span class="me1">elementFromPoint</span><span class="br0">&#40;</span>x<span class="sy0">,</span> y<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="co1">// We have a viable target</span>
      <span class="co1">// ...</span>
      <span class="kw1">break</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>




<p>
  Any random element might not be a suitable target though. For example, we want to avoid
  other Zergling instances on the page. We also want to avoid anything too big, like
  the <code>BODY</code> element. I also added in an <code>antiZerg</code> feature so
  elements on the page can protect themselves from the zergs:
</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Zergling.<span class="me1">isSuitableTarget</span> <span class="sy0">=</span> <span class="kw2">function</span> isSuitableTarget<span class="br0">&#40;</span>candidate<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
  <span class="kw2">var</span> targetData<span class="sy0">;</span>
&nbsp;
  <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>candidate<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">return</span> <span class="kw2">false</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
&nbsp;
  <span class="co1">// Make sure none of its ancestors are currently targets:</span>
  <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> parent <span class="sy0">=</span> candidate<span class="sy0">;</span> parent <span class="sy0">=</span> parent.<span class="me1">parentNode</span><span class="sy0">;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span>$.<span class="me1">data</span><span class="br0">&#40;</span>parent<span class="sy0">,</span> Zergling.<span class="me1">DATA_KEY</span><span class="br0">&#41;</span> <span class="sy0">||</span> <span class="co2">/antiZerg/i</span>.<span class="me1">test</span><span class="br0">&#40;</span>parent.<span class="me1">className</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="kw1">return</span> <span class="kw2">false</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
  <span class="br0">&#125;</span>
&nbsp;
  targetData <span class="sy0">=</span> $.<span class="me1">data</span><span class="br0">&#40;</span>candidate<span class="sy0">,</span> Zergling.<span class="me1">DATA_KEY</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
  candidate <span class="sy0">=</span> $<span class="br0">&#40;</span>candidate<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
  <span class="kw1">return</span> <span class="sy0">!/</span>zergling<span class="sy0">/</span>i.<span class="me1">test</span><span class="br0">&#40;</span>candidate<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">nodeName</span><span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span>
    <span class="sy0">!/</span>antiZerg<span class="sy0">/</span>i.<span class="me1">test</span><span class="br0">&#40;</span>candidate<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">className</span><span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> 
    <span class="co1">// Make sure it's either yet-to-be-a-target or still alive:</span>
    <span class="br0">&#40;</span><span class="sy0">!</span>targetData <span class="sy0">||</span> targetData.<span class="me1">life</span> <span class="sy0">&gt;</span> <span class="nu0">0</span><span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span>
    <span class="co1">// Make sure it's not too big</span>
    candidate.<span class="me1">width</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">*</span> candidate.<span class="me1">height</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&lt;</span> Zergling.<span class="me1">MAX_TARGET_AREA</span><span class="sy0">;</span>
&nbsp;
<span class="br0">&#125;</span><span class="sy0">;</span></pre></div></div>




<p>
  Once we have a viable target we begin moving towards it.
</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">calcMovement<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
  <span class="kw2">var</span> target <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">target</span><span class="sy0">,</span>
      <span class="co1">// Move towards random position within the target element:</span>
      xDiff <span class="sy0">=</span> <span class="br0">&#40;</span>target.<span class="me1">position</span>.<span class="me1">left</span> <span class="sy0">+</span> random<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">*</span> target.<span class="me1">width</span><span class="br0">&#41;</span> <span class="sy0">-</span> <span class="kw1">this</span>.<span class="me1">x</span><span class="sy0">,</span>
      yDiff <span class="sy0">=</span> <span class="br0">&#40;</span>target.<span class="me1">position</span>.<span class="me1">top</span> <span class="sy0">+</span> random<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">*</span> target.<span class="me1">height</span><span class="br0">&#41;</span> <span class="sy0">-</span> <span class="kw1">this</span>.<span class="me1">y</span><span class="sy0">,</span>
      angle <span class="sy0">=</span> atan2<span class="br0">&#40;</span>yDiff<span class="sy0">,</span> xDiff<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
  <span class="co1">// Assign deltaX/Y (i.e. how much we move {x,y} on each step)</span>
  <span class="kw1">this</span>.<span class="me1">dx</span> <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">speed</span> <span class="sy0">*</span> cos<span class="br0">&#40;</span>angle<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw1">this</span>.<span class="me1">dy</span> <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">speed</span> <span class="sy0">*</span> sin<span class="br0">&#40;</span>angle<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="br0">&#125;</span><span class="sy0">,</span> <span class="co1">//...</span></pre></div></div>




<p>
  On every step the Zergling needs to check whether it&#8217;s reached the target yet:
</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">hasReachedTarget<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
  <span class="kw2">var</span> target <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">target</span><span class="sy0">,</span>
      pos <span class="sy0">=</span> target.<span class="me1">position</span><span class="sy0">;</span>
&nbsp;
  <span class="kw1">return</span>  <span class="kw1">this</span>.<span class="me1">x</span> <span class="sy0">&gt;=</span> pos.<span class="me1">left</span> <span class="sy0">&amp;&amp;</span>
          <span class="kw1">this</span>.<span class="me1">y</span> <span class="sy0">&gt;=</span> pos.<span class="me1">top</span> <span class="sy0">&amp;&amp;</span>
          <span class="kw1">this</span>.<span class="me1">x</span> <span class="sy0">&lt;=</span> pos.<span class="me1">left</span> <span class="sy0">+</span> target.<span class="me1">width</span> <span class="sy0">&amp;&amp;</span>
          <span class="kw1">this</span>.<span class="me1">y</span> <span class="sy0">&lt;=</span> pos.<span class="me1">top</span> <span class="sy0">+</span> target.<span class="me1">height</span>
<span class="br0">&#125;</span><span class="sy0">,</span> <span class="co1">//...</span></pre></div></div>




<p>
  When a Zergling reaches its target it begins killing it:
</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hasReachedTarget</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="kw1">this</span>.<span class="me1">isKilling</span> <span class="sy0">=</span> <span class="kw2">true</span><span class="sy0">;</span>
  <span class="kw1">return</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>




<p>
  And the actual killing:
</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">isKilling</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="kw1">if</span> <span class="br0">&#40;</span>target.<span class="me1">life</span> <span class="sy0">&gt;</span> <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="co1">// It's still alive! Pulsate and continue to kill:</span>
    target.<span class="me1">life</span><span class="sy0">--;</span>
    <span class="kw1">this</span>.<span class="me1">pulsate</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    target.<span class="me1">dom</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="st0">'opacity'</span><span class="sy0">,</span> target.<span class="me1">life</span> <span class="sy0">/</span> Zergling.<span class="me1">LIFE</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
    <span class="co1">// It's DEAD! </span>
    target.<span class="me1">dom</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="st0">'visibility'</span><span class="sy0">,</span> <span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">this</span>.<span class="me1">pulsate</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">this</span>.<span class="me1">isKilling</span> <span class="sy0">=</span> <span class="kw2">false</span><span class="sy0">;</span>
    <span class="kw1">this</span>.<span class="me1">target</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
  <span class="kw1">return</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>




<p>Setting <code>this.target</code> to <code>null</code> means that the Zergling
  will begin searching for a new target on its next step.
</p>

<p>
  To manage all the Zerglings I put together a <code>ZergRush</code> class:
</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">function</span> ZergRush<span class="br0">&#40;</span>nZerglings<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
  <span class="kw2">var</span> me <span class="sy0">=</span> <span class="kw1">this</span><span class="sy0">,</span>
      zerglings <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">zerglings</span> <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">,</span>
      targets <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">targets</span> <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">;</span>
&nbsp;
  <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> nZerglings<span class="sy0">;</span> <span class="sy0">++</span>i<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    zerglings.<span class="me1">push</span><span class="br0">&#40;</span>
      <span class="kw2">new</span> Zergling<span class="br0">&#40;</span>
        Math.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">100</span><span class="sy0">,</span>
        Math.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">100</span><span class="sy0">,</span>
        <span class="kw1">this</span>
      <span class="br0">&#41;</span>
    <span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
&nbsp;
  <span class="kw1">this</span>.<span class="me1">intervalID</span> <span class="sy0">=</span> setInterval<span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    me.<span class="me1">step</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
  <span class="br0">&#125;</span><span class="sy0">,</span> <span class="nu0">30</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="br0">&#125;</span></pre></div></div>





<p>
  All Zerglings start at random positions in the top-left of the page
  (anywhere from <code>{0,0}</code> to <code>{100,100}</code>).
</p>

<p>
  As I said, it&#8217;s not very polished. The Zerglings are currently just little
  red dots, made like so:
</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="co1">// (in Zergling constructor):</span>
&nbsp;
<span class="co1">// &lt;zergling&gt; element used to avoid CSS conflicts and because its cool..</span>
<span class="kw1">this</span>.<span class="me1">dom</span> <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="st0">'&lt;zergling&gt;'</span><span class="br0">&#41;</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
  width<span class="sy0">:</span> <span class="kw1">this</span>.<span class="me1">width</span><span class="sy0">,</span>
  height<span class="sy0">:</span> <span class="kw1">this</span>.<span class="me1">height</span><span class="sy0">,</span>
  position<span class="sy0">:</span> <span class="st0">'absolute'</span><span class="sy0">,</span>
  display<span class="sy0">:</span> <span class="st0">'block'</span><span class="sy0">,</span>
  background<span class="sy0">:</span> <span class="st0">'red'</span><span class="sy0">,</span>
  left<span class="sy0">:</span> x<span class="sy0">,</span>
  top<span class="sy0">:</span> y<span class="sy0">,</span>
  borderRadius<span class="sy0">:</span> <span class="st0">'5px'</span><span class="sy0">,</span>
  zIndex<span class="sy0">:</span> <span class="nu0">9999</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">appendTo</span><span class="br0">&#40;</span>body<span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>




<p>Please visit <a href="/demo/ZergRush/demo.html">the demo</a>, <a href="https://github.com/padolsey/ZergRush/blob/master/ZergRush.js">see the source</a> on Github, or save <a href="javascript:void function(){function j(){function c(a,b,c){this.rush=c;this.speed=3;this.x=a;this.y=b;this.height=this.width=10;this.isFinished=this.isKilling=!1;this.dPulsate=0;this.dom=e(&quot;&lt;zergling&gt;&quot;).css({width:this.width,height:this.height,position:&quot;absolute&quot;,display:&quot;block&quot;,background:&quot;red&quot;,left:a,top:b,borderRadius:&quot;5px&quot;,zIndex:9999}).appendTo(k)}function f(a){var b=this,d=this.zerglings=[];this.targets=[];for(var e=0;e&lt;a;++e)d.push(new c(100*Math.random(),100*Math.random(),this));this.intervalID=setInterval(function(){b.step()},
30)}window.Zergling=c;window.ZergRush=f;var h=document,k=h.body,g=Math.atan2,m=Math.cos,n=Math.sin,o=Math.PI,i=Math.random,p=Math.max;c.DATA_KEY=&quot;zergTargetData&quot;;c.MIN_TARGET_AREA=5E4;c.VISION=1E3;c.LIFE=50;c.isSuitableTarget=function(a){var b;if(!a)return!1;for(b=a;b=b.parentNode;)if(e.data(b,c.DATA_KEY)||/antiZerg/i.test(b.className))return!1;b=e.data(a,c.DATA_KEY);a=e(a);return!/zergling/i.test(a[0].nodeName)&amp;&amp;!/antiZerg/i.test(a[0].className)&amp;&amp;(!b||0&lt;b.life)&amp;&amp;a.width()*a.height()&lt;c.MIN_TARGET_AREA};
c.prototype={calcMovement:function(){var a=this.target,b=a.position.left+i()*a.width-this.x,a=a.position.top+i()*a.height-this.y,b=g(a,b);this.dx=this.speed*m(b);this.dy=this.speed*n(b)},draw:function(){if(!this.isFinished){var a=this.target;if(this.isKilling)0&lt;a.life?(a.life--,this.pulsate(),a.dom.css(&quot;opacity&quot;,a.life/c.LIFE)):(a.dom.css(&quot;visibility&quot;,&quot;hidden&quot;),this.pulsate(0),this.isKilling=!1,this.target=null);else{if(!this.target||0&gt;=this.target.life)if(this.findTarget())a=this.target,this.calcMovement();
else{this.isFinished=!0;this.dom.fadeOut(100,function(){e(this).remove()});return}this.hasReachedTarget()?this.isKilling=!0:(this.x+=this.dx,this.y+=this.dy,this.dom.css({left:this.x,top:this.y}))}}},hasReachedTarget:function(){var a=this.target,b=a.position;return this.x&gt;=b.left&amp;&amp;this.y&gt;=b.top&amp;&amp;this.x&lt;=b.left+a.width&amp;&amp;this.y&lt;=b.top+a.height},findTarget:function(){var a,b,d,f,g=this.width/2,i=this.height/2,j=p(k.scrollTop,h.documentElement.scrollTop),l=p(k.scrollLeft,h.documentElement.scrollLeft);
for(a=10;a&lt;c.VISION;a+=50)for(b=0;360&gt;b;b+=45)if(d=this.x+g+a*m(o/180*b)-l,f=this.y+i+a*n(o/180*b)-j,c.isSuitableTarget(d=h.elementFromPoint(d,f)))return d=e(d),a=this.target=d.data(c.DATA_KEY),a||(d.data(c.DATA_KEY,this.target={dom:d,position:d.offset(),width:d.width(),height:d.height(),life:c.LIFE,initialCSS:{visibility:&quot;&quot;,opacity:d.css(&quot;opacity&quot;)||&quot;&quot;}}),this.rush.registerTarget(this.target)),!0},pulsate:function(){(this.dPulsate=!this.dPulsate)?this.dom.css({left:this.x-2,top:this.y-2,width:14,
height:14}):this.dom.css({left:this.x,top:this.y,width:10,height:10})}};f.prototype={step:function(){for(var a=!0,b=0;b&lt;this.zerglings.length;++b)this.zerglings[b].draw(),a=a&amp;&amp;this.zerglings[b].isFinished;a&amp;&amp;clearInterval(this.intervalID)},destroy:function(){clearInterval(this.intervalID);for(var a=0;a&lt;this.zerglings.length;++a)this.zerglings[a].dom.remove();for(a=0;a&lt;this.targets.length;++a)this.targets[a].dom.css(this.targets[a].initialCSS),this.targets[a].dom.removeData(c.DATA_KEY)},registerTarget:function(a){this.targets.push(a)}}}
var e,f=window.jQuery,g=document.createElement(&quot;script&quot;);g.src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js&quot;;document.body.appendChild(g);var l=setInterval(function(){if(f?window.jQuery!==f:window.jQuery)clearInterval(l),e=window.jQuery.noConflict(!0),j(),new ZergRush(20)},200)}();">this bookmarklet</a> for the future.</p>

<p>If I&#8217;m honest, I prefer long strategy but once in a while rushing is fun!</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/zerg-rush-in-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The insecurity of being wrong</title>
		<link>http://james.padolsey.com/general/the-insecurity-of-being-wrong/</link>
		<comments>http://james.padolsey.com/general/the-insecurity-of-being-wrong/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 17:07:45 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2068</guid>
		<description><![CDATA[I cannot blame a child for harbouring beliefs I see as damaging so why is it acceptable to blame an adult for the same thing? The only thing that&#8217;s changed is <em>time</em>. Time on the planet that we presume to have been spent by having&#8230;]]></description>
			<content:encoded><![CDATA[<p>I cannot blame a child for harbouring beliefs I see as damaging so why is it acceptable to blame an adult for the same thing? The only thing that&#8217;s changed is <em>time</em>. Time on the planet that we presume to have been spent by having their foolish beliefs knocked out of them by social pressure and established norms.</p>

<p>So, when one encounters an exception &#8212; someone that, for whatever reason, didn&#8217;t have X and Y knocked out of them, it comes as a shock and offence. Did nobody teach that guy not to pee while on public transport? Did they not tell you it&#8217;s wrong to make decisions based on race?</p>

<p>I think to myself: What&#8217;s abhorrent to me? What offends me deeply? Is it war, incest, racism, bigotry, apathy, rape? I know I&#8217;m right about my position on these things. I know it. My heart of hearts tells me it&#8217;s so. So I am right.</p>

<p>And if I&#8217;m wrong: will I let myself believe it?</p>
 
<p>We each believe we have a monopoly on the truth. We&#8217;re never willingly wrong. But what if you <em>are</em> wrong?
An excellent quote from Kathryn Schulz&#8217;s TED talk &#8220;<a href="http://www.ted.com/talks/kathryn_schulz_on_being_wrong.html">on being wrong</a>&#8220;:</p>

<blockquote><p>
This is a catastrophe. This attachment to our own rightness keeps us from preventing mistakes when we absolutely need to, and causes us to treat each other terribly.
<br/>What&#8217;s most baffling and most tragic about this is that it misses the whole point of being <em>human</em>.
<br/>It&#8217;s like we want to imagine that our minds are these perfectly translucent windows and we just gaze out of them and describe the world as it unfolds&#8230; and we want everyone else to gaze out of the same window and see the exact same thing.
</p></blockquote>

<p>We hear opinions that we believe to be wrong; they may even offend us deeply. We can accept this though &#8212; we shrug it off as an opinion. &#8220;<em>It&#8217;s just someone&#8217;s opinion. It&#8217;s fine. People can believe what they want.</em>&#8220;</p>

<p>But when someone <em>does</em> something we see as terrible &#8212; when they enact the feelings and desires in their heads, <em>this</em> is when we get mad! &#8220;<em>How dare he</em>!&#8221;</p>

<p>What did he do wrong though? Was it the opinion, the feeling, the desire that was wrong, or was it simply acting on it that made it a sin?</p>

<p>This relativism and doubtfulness is unnerving.</p>

<p>Maybe that&#8217;s why it&#8217;s so soothing to work with absolutes: like the obvious truth that you should use semi-colons and stop relying on ASI&#8230; <em>kidding</em>! You see, even here, in our cushy little world there are still offensive beliefs.</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/general/the-insecurity-of-being-wrong/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery EventEmitter</title>
		<link>http://james.padolsey.com/javascript/jquery-eventemitter/</link>
		<comments>http://james.padolsey.com/javascript/jquery-eventemitter/#comments</comments>
		<pubDate>Sat, 07 Apr 2012 09:01:04 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2063</guid>
		<description><![CDATA[If you&#8217;re already using jQuery and you need an EventEmitter you may as well use jQuery&#8217;s event system instead of building your own. Here&#8217;s something I used in a recent project:

<strong>EDIT: made it simpler. (Now mixin: <code>jQuery.eventEmitter</code> instead of <code>jQuery.EventEmitter.prototype</code>.)</strong>


<pre class="javascript" style="font-family:monospace;"><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>jQuery<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&#160;
  jQuery.<span class="me1">eventEmitter</span> <span class="sy0">=</span> <span class="br0">&#123;</span>
    _JQInit<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="kw1">this</span>._JQ <span class="sy0">=</span> jQuery<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
    emit<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> data<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="sy0">!</span><span class="kw1">this</span>._JQ <span class="sy0">&#38;&#38;</span> <span class="kw1">this</span>._JQInit<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw1">this</span>._JQ.<span class="me1">trigger</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> data<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
    once<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="sy0">!</span><span class="kw1">this</span>._JQ <span class="sy0">&#38;&#38;</span> <span class="kw1">this</span>._JQInit<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw1">this</span>._JQ.<span class="me1">one</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
    on<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="sy0">!</span><span class="kw1">this</span>._JQ <span class="sy0">&#38;&#38;</span> <span class="kw1">this</span>._JQInit<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw1">this</span>._JQ.<span class="me1">bind</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
    off<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="sy0">!</span><span class="kw1">this</span>._JQ&#8230;</pre>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re already using jQuery and you need an EventEmitter you may as well use jQuery&#8217;s event system instead of building your own. Here&#8217;s something I used in a recent project:</p>

<p><strong>EDIT: made it simpler. (Now mixin: <code>jQuery.eventEmitter</code> instead of <code>jQuery.EventEmitter.prototype</code>.)</strong></p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>jQuery<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
  jQuery.<span class="me1">eventEmitter</span> <span class="sy0">=</span> <span class="br0">&#123;</span>
    _JQInit<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="kw1">this</span>._JQ <span class="sy0">=</span> jQuery<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
    emit<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> data<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="sy0">!</span><span class="kw1">this</span>._JQ <span class="sy0">&amp;&amp;</span> <span class="kw1">this</span>._JQInit<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw1">this</span>._JQ.<span class="me1">trigger</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> data<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
    once<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="sy0">!</span><span class="kw1">this</span>._JQ <span class="sy0">&amp;&amp;</span> <span class="kw1">this</span>._JQInit<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw1">this</span>._JQ.<span class="me1">one</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
    on<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="sy0">!</span><span class="kw1">this</span>._JQ <span class="sy0">&amp;&amp;</span> <span class="kw1">this</span>._JQInit<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw1">this</span>._JQ.<span class="me1">bind</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
    off<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="sy0">!</span><span class="kw1">this</span>._JQ <span class="sy0">&amp;&amp;</span> <span class="kw1">this</span>._JQInit<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw1">this</span>._JQ.<span class="me1">unbind</span><span class="br0">&#40;</span>evt<span class="sy0">,</span> handler<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
  <span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="br0">&#125;</span><span class="br0">&#40;</span>jQuery<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>




<p>It&#8217;s a mixin, and you can use it like so:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">function</span> App<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="co1">// do stuff</span>
<span class="br0">&#125;</span>
&nbsp;
jQuery.<span class="me1">extend</span><span class="br0">&#40;</span>App.<span class="me1">prototype</span><span class="sy0">,</span> jQuery.<span class="me1">eventEmitter</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="kw2">var</span> myApp <span class="sy0">=</span> <span class="kw2">new</span> App<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// myApp supports events!</span>
&nbsp;
myApp.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'someEvent'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">'someEvent!'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
myApp.<span class="me1">emit</span><span class="br0">&#40;</span><span class="st0">'someEvent'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// 'someEvent' alerted</span></pre></div></div>




<p>Feel free to change the property/method names. The stuff prefixed with <code>_JQ</code> should not be accessed publicly and should avoid conflicts with your objects. I guess you could use jQuery&#8217;s expando to hide them better. Or, alternatively, if performance is less of a concern, you can re-construct the jQuery object on each method-call instead of saving it.</p>

<p>When destroying your object be sure to call <code>jQuery.removeData(myObj)</code> too.</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/jquery-eventemitter/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Mozilla CTO on political dialogue</title>
		<link>http://james.padolsey.com/general/mozilla-cto-on-political-dialogue/</link>
		<comments>http://james.padolsey.com/general/mozilla-cto-on-political-dialogue/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 13:42:47 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2057</guid>
		<description><![CDATA[I&#8217;ll keep this short. I don&#8217;t care for the silencers who would see this topic dead and buried. Dialogue,
  in all areas, breeds a higher understanding. It is of the upmost importance to maintain
  an atmosphere of critique and reflection. If you don&#8217;t agree with&#8230;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll keep this short. I don&#8217;t care for the silencers who would see this topic dead and buried. Dialogue,
  in all areas, breeds a higher understanding. It is of the upmost importance to maintain
  an atmosphere of critique and reflection. If you don&#8217;t agree with this then many of the following
  points might anger you.
</p>

<p>A <a href="http://brendaneich.com/2012/04/community-and-diversity/">response</a> from the Mozilla CTO, who recently underwent criticism for his support of <a href="http://en.wikipedia.org/wiki/California_Proposition_8">Proposition 8</a>, concludes with the following:</p>

<blockquote><p>
So I do not insist that anyone agree with me on a great many things,
including political issues, and I refrain from putting my personal
beliefs in others’ way in all matters Mozilla, JS, and Web.
I hope for the same in return.
</p></blockquote>

<p>This seems like an agreeable statement but the matter at hand is crucial here.
Regardless of the specific reasons Brendan had for supporting Proposition 8,
the fact is, nonetheless, that he did.</p>

<p>And this particular constitutional amendment would come to define marriage as
only between a man and a woman. This is seen as freedom-inhibiting and discrimanotory
by many opponents.</p>

<p>So, it is but with a touch of irony that Brendan&#8217;s closing remark comes across.
He states that he doesn&#8217;t want his &#8220;personal beliefs in others&#8217; way&#8221;. Granted, he
is referring to Mozilla, JS and Web, but the irony still reeks.</p>

<p>It seems like a lot of logical footwork for Brendan to maintain this ideology with
web-related topics, but an entirely different ideology with issues of equaity and
politics.</p>

<p>I find it funny how it&#8217;s now politically correct to entirely avoid politics
in almost all matters. A person would be labelled as immature, perhaps, if they
were to let their political beliefs get in the way of other more &#8220;productive&#8221; things.</p>

<p>It is a huge double standard to silence political dialogue with
one hand yet sing the praises of an open, free, and just web with the other. And this is what Brendan seems to be doing.</p>

<p>Yes, fine. You can have your opinions. You can have your community where peoples&#8217; opinions do
not get in the way. But you can&#8217;t proclaim this principle and at the same time seek
refuge behind it for previous actions that are entirely incompatible with this
very principle.</p>

<p>It is logically inconsistent. That is all I wish to point out.</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/general/mozilla-cto-on-political-dialogue/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>The pursuit of free knowledge</title>
		<link>http://james.padolsey.com/general/the-pursuit-of-free-knowledge/</link>
		<comments>http://james.padolsey.com/general/the-pursuit-of-free-knowledge/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 23:59:55 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2046</guid>
		<description><![CDATA[Why are we still writing books for profit?

<a href="http://en.wikipedia.org/wiki/Robert_K._Merton">Robert Merton</a>, a well-known sociologist, established a set of norms that characterised the scientific community. One of these norms was communalism &#8212; communal ownership and willing sacrifice of intellectual property for the betterment of the field and&#8230;]]></description>
			<content:encoded><![CDATA[<p>Why are we still writing books for profit?</p>

<p><a href="http://en.wikipedia.org/wiki/Robert_K._Merton">Robert Merton</a>, a well-known sociologist, established a set of norms that characterised the scientific community. One of these norms was communalism &#8212; communal ownership and willing sacrifice of intellectual property for the betterment of the field and humanity.</p>

<p>This is a good principle to follow. It furthers humanity&#8217;s progress via a method of sharing based on equal say and equal access. It is, at the very least, a respectable and ethically sound principle to aim for.</p>

<p>The open source movement follows this very principle. We, in the web development community, are not strangers to the strengths of open source.</p>

<p>The programming book publication machine, another thing well accepted and prevalent in this community, runs in opposition to the tenets of open source that we should be striving for. Why do we allow this?</p>

<p>In an ideal world &#8212; and there is no good argument for heading in any other direction than ideal &#8212; knowledge should not have a single barrier to access, including money. Why should we be so accepting of passively discriminating against those without the means to know what we know?</p>

<p>Yes, we live in a world of dollars and euros, but has that stopped the open source movement from gaining popularity and wide acceptance? No. And since when was it acceptable to forgo progress for the sake of an unfair and unequal status quo?</p>

<p>We should continue, in the same fashion as we have with <a href="http://en.wikipedia.org/wiki/FOSS">FOSS</a>, by making the idea of paid-for knowledge abhorrant. The best place to start is in what we do day-to-day.</p>

<p>There are always excuses and some of them are reasonable. There are people who make a living selling knowledge. For such people it would be a fight between principle and survival/comfort. We know which one wins. For many of us though we have the luxury of abiding by the principle in the vast majority of what we do.</p>

<p>We should continue to pursue free and equal access to all knowledge.</p>

<p>So, before you write your next book and put it behind a pay-wall, consider the principles you wish to live by.</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/general/the-pursuit-of-free-knowledge/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Programming exchange feedback</title>
		<link>http://james.padolsey.com/general/programming-exchange-feedback/</link>
		<comments>http://james.padolsey.com/general/programming-exchange-feedback/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 23:53:09 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2037</guid>
		<description><![CDATA[A few days ago I posted a <a href="https://docs.google.com/spreadsheet/viewform?formkey=dEMyUDdYRzlaSHVtTjFrNTlJNmwzZHc6MQ#gid=0">survey to gauge interest in a programming-language exchange platform/community</a>. It&#8217;s received some interest, perhaps not as much as I would of thought, but I&#8217;m still glad for the responses received. We have a relatively <em>okay</em> representation of a slightly&#8230;]]></description>
			<content:encoded><![CDATA[<p>A few days ago I posted a <a href="https://docs.google.com/spreadsheet/viewform?formkey=dEMyUDdYRzlaSHVtTjFrNTlJNmwzZHc6MQ#gid=0">survey to gauge interest in a programming-language exchange platform/community</a>. It&#8217;s received some interest, perhaps not as much as I would of thought, but I&#8217;m still glad for the responses received. We have a relatively <em>okay</em> representation of a slightly biased-towards-JavaScript sect within the larger programming community.</p>

<p>It was not a shock to discover that most people that received word of the survey and took it are knowledgeable in JavaScript. In fact, 81% of people that answered the survey know JavaScript to a high level.</p>

<p>Here&#8217;s the rundown of the first question, &#8220;What languages do you know to a high level?&#8221;:</p>

<p><img src="https://chart.googleapis.com/chart?cht=bhs&#038;chs=345x420&#038;chbh=24%2C6&#038;chco=2626e5%7C8080f0%7C4d4de9%7C3333e6%7C6666ec%7C0000e0%7C0d0de2%7C5959eb%7C7373ee%7C4040e8%7C8c8cf1%7C1a1ae3%7C9999f3&#038;chxt=x%2Cy&#038;chxl=0%3A%7C0%7C12%7C24%7C36%7C48%7C60%7C72%7C1%3A%7COther%7CDelphi%7CLua%7CSmalltalk%7CRuby%7CPerl%7CPython%7CJavaScript%7CJava%7CPHP%7CC%23%7CC%2B%2B%7CC&#038;chxs=0%2C000000%2C12%2C0%2Clt%7C1%2C000000%2C12%2C1%2Clt&#038;chds=0%2C72&#038;chd=t%3A10%2C2%2C12%2C40%2C14%2C62%2C8%2C3%2C8%2C0%2C1%2C1%2C12" /></p>

<p>And here&#8217;s the second, &#8220;What languages do you want to learn?&#8221;:</p>

<p><img src="https://chart.googleapis.com/chart?cht=bhs&#038;chs=345x420&#038;chbh=24%2C6&#038;chco=ffa826%7Cffa31a%7Cffad33%7Cffd699%7Cffc773%7Cffc266%7Cff9900%7Cff9e0d%7Cffbd59%7Cffb340%7Cffcc80%7Cffd18c%7Cffb84d&#038;chxt=x%2Cy&#038;chxl=0%3A%7C0%7C8%7C16%7C24%7C32%7C40%7C1%3A%7COther%7CDelphi%7CLua%7CSmalltalk%7CRuby%7CPerl%7CPython%7CJavaScript%7CJava%7CPHP%7CC%23%7CC%2B%2B%7CC&#038;chxs=0%2C000000%2C12%2C0%2Clt%7C1%2C000000%2C12%2C1%2Clt&#038;chds=0%2C40&#038;chd=t%3A15%2C12%2C7%2C5%2C8%2C13%2C38%2C2%2C36%2C7%2C12%2C0%2C16" /></p>

<p><em>People could select more than one checkbox, e.g. Bobby wants to learn C++ and Ruby&#8230;</em></p>

<p>Also, &#8220;high level&#8221; is ill-defined, so is liable to subjective modesty and vanity alike.</p>

<p>Overall there were 77 people that took the survey, and from the survey results plus various other comments it seems that there is interest for <em>*something*</em> to help us pick up alien programming languages/platforms, but we&#8217;re just not sure what.</p>

<p>If you&#8217;re interested in further pursuing this speck of an idea, please feel free to go ahead. Right now I&#8217;m limited on time. I would be very interested in a platform enabling such an exchange. I am sure that it would garner some interest within the community too. I can&#8217;t promise anything though.</p>

<p>I am personally looking for someone with an immense knowledge of Perl to tutor me via Skype. But this person should also be yearning to learn JavaScript to a high level. If such a person exists, please contact me.</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/general/programming-exchange-feedback/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Programming skill exchange (survey)</title>
		<link>http://james.padolsey.com/general/programming-skill-exchange-survey/</link>
		<comments>http://james.padolsey.com/general/programming-skill-exchange-survey/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 12:50:22 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2034</guid>
		<description><![CDATA[I don&#8217;t know if something like this exists yet. If you know of something similar please let me know in the comments.

The idea: You know language <em>X</em> and you want to know language <em>Y</em>. So, this platform/community enables you to &#8220;pair up&#8221; with someone that&#8230;]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know if something like this exists yet. If you know of something similar please let me know in the comments.</p>

<p>The idea: You know language <em>X</em> and you want to know language <em>Y</em>. So, this platform/community enables you to &#8220;pair up&#8221; with someone that knows language <em>Y</em> and wants to know language <em>X</em>. I&#8217;m surprised nothing like this exists yet. If you&#8217;d be interested please fill out <strong><a href="https://docs.google.com/spreadsheet/viewform?formkey=dEMyUDdYRzlaSHVtTjFrNTlJNmwzZHc6MQ">this form</a></strong>.</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/general/programming-skill-exchange-survey/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Ordering variable declarations</title>
		<link>http://james.padolsey.com/javascript/ordering-variable-declarations/</link>
		<comments>http://james.padolsey.com/javascript/ordering-variable-declarations/#comments</comments>
		<pubDate>Thu, 01 Mar 2012 19:38:46 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[conventions]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2020</guid>
		<description><![CDATA[I was recently exposed to a coding convention which requires you to order variable declarations in alphabetical order. Crockford mentions this in <a href="http://javascript.crockford.com/code.html">Code conventions for JavaScript</a>. An oversight of Crockford&#8217;s, perhaps, is that he doesn&#8217;t explain <em>why</em> we should do these things.

So the convention requires&#8230;]]></description>
			<content:encoded><![CDATA[<p>I was recently exposed to a coding convention which requires you to order variable declarations in alphabetical order. Crockford mentions this in <a href="http://javascript.crockford.com/code.html">Code conventions for JavaScript</a>. An oversight of Crockford&#8217;s, perhaps, is that he doesn&#8217;t explain <em>why</em> we should do these things.</p>

<p>So the convention requires that instead of this:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> ccc<span class="sy0">;</span>
<span class="kw2">var</span> aaa<span class="sy0">;</span>
<span class="kw2">var</span> bbb<span class="sy0">;</span></pre></div></div>




<p>&#8230; you do this:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> aaa<span class="sy0">;</span>
<span class="kw2">var</span> bbb<span class="sy0">;</span>
<span class="kw2">var</span> ccc<span class="sy0">;</span></pre></div></div>




<p>By ordering the variables alphabetically we have supposedly made it easier to find variable names.</p>

<p>I should probably use a real world example to demonstrate its true benefit, so here&#8217;s a chunk of variables from jQuery:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> rformElems <span class="sy0">=</span> <span class="co2">/^(?:textarea|input|select)$/i</span><span class="sy0">,</span>
    rtypenamespace <span class="sy0">=</span> <span class="co2">/^([^\.]*)?(?:\.(.+))?$/</span><span class="sy0">,</span>
    rhoverHack <span class="sy0">=</span> <span class="co2">/(?:^|\s)hover(\.\S+)?\b/</span><span class="sy0">,</span>
    rkeyEvent <span class="sy0">=</span> <span class="co2">/^key/</span><span class="sy0">,</span>
    rmouseEvent <span class="sy0">=</span> <span class="co2">/^(?:mouse|contextmenu)|click/</span><span class="sy0">,</span>
    rfocusMorph <span class="sy0">=</span> <span class="co2">/^(?:focusinfocus|focusoutblur)$/</span><span class="sy0">,</span>
    rquickIs <span class="sy0">=</span> <span class="co2">/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/</span><span class="sy0">;</span></pre></div></div>




<p>They&#8217;re using some quasi-hungarian notation which, it could be argued, negates the benefits of alphabetical ordering, so let&#8217;s remove all of the <code>r</code> prefixxes so that we&#8217;ve got a good example to work with:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> formElems <span class="sy0">=</span> <span class="co2">/^(?:textarea|input|select)$/i</span><span class="sy0">,</span>
    typenamespace <span class="sy0">=</span> <span class="co2">/^([^\.]*)?(?:\.(.+))?$/</span><span class="sy0">,</span>
    hoverHack <span class="sy0">=</span> <span class="co2">/(?:^|\s)hover(\.\S+)?\b/</span><span class="sy0">,</span>
    keyEvent <span class="sy0">=</span> <span class="co2">/^key/</span><span class="sy0">,</span>
    mouseEvent <span class="sy0">=</span> <span class="co2">/^(?:mouse|contextmenu)|click/</span><span class="sy0">,</span>
    focusMorph <span class="sy0">=</span> <span class="co2">/^(?:focusinfocus|focusoutblur)$/</span><span class="sy0">,</span>
    quickIs <span class="sy0">=</span> <span class="co2">/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/</span><span class="sy0">;</span></pre></div></div>




<p>Okay, now let&#8217;s re-order according to the convention:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> focusMorph <span class="sy0">=</span> <span class="co2">/^(?:focusinfocus|focusoutblur)$/</span><span class="sy0">,</span>
    formElems <span class="sy0">=</span> <span class="co2">/^(?:textarea|input|select)$/i</span><span class="sy0">,</span>
    hoverHack <span class="sy0">=</span> <span class="co2">/(?:^|\s)hover(\.\S+)?\b/</span><span class="sy0">,</span>
    keyEvent <span class="sy0">=</span> <span class="co2">/^key/</span><span class="sy0">,</span>
    mouseEvent <span class="sy0">=</span> <span class="co2">/^(?:mouse|contextmenu)|click/</span><span class="sy0">,</span>
    quickIs <span class="sy0">=</span> <span class="co2">/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/</span><span class="sy0">,</span>
    typenamespace <span class="sy0">=</span> <span class="co2">/^([^\.]*)?(?:\.(.+))?$/</span><span class="sy0">;</span></pre></div></div>




<p>Did you notice the difference? The convention suggests that it is now easier for programmers to come along and find the variable <code>focusMorph</code> because it is within an alphabetically sorted list. I have doubts about this though.</p>

<p>For me, this variable list is no easier to navigate than before. I&#8217;m probably below average in &#8220;alphabet skill&#8221; though. Sometimes I find myself reading out the alphabet internally so I can try to remember if K really does come before M. It&#8217;s sad but true.</p>

<p>It could very well be that this is just one of those things that only affects me. And that&#8217;s fine. I still would like to continue with my exploration of this convention though.</p>

<p>This convention can become a problem when, for example, one variable depends on a previous variable&#8217;s assignment. For example:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> radians <span class="sy0">=</span> foo.<span class="me1">getRadians</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span>
    angle <span class="sy0">=</span> radians <span class="sy0">/</span> Math.<span class="me1">PI</span> <span class="sy0">*</span> <span class="nu0">180</span><span class="sy0">,</span> <span class="co1">// we need radians to be defined</span>
    ...<span class="sy0">;</span></pre></div></div>




<p>With the convention applied:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> angle <span class="sy0">=</span> radians <span class="sy0">/</span> Math.<span class="me1">PI</span> <span class="sy0">*</span> <span class="nu0">180</span><span class="sy0">,</span>
    radians <span class="sy0">=</span> foo.<span class="me1">getRadians</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span>
    ...<span class="sy0">;</span></pre></div></div>




<p>But that doesn&#8217;t work anymore. When the first line runs, <code>radians</code> is undefined. Of course, in this example, I could just get rid of the <code>radians</code> variable and use <code>foo.getRadians()</code> straight off. Yes, I could do that. But this is just an example, and I have battled with this quandary many times without such simple solutions.</p>

<p>So, strictly, how does one solve this, supposing it was a trickier case? Actually, wait &#8212; let&#8217;s explore why we&#8217;re solving this. Is this a programming problem? Nope, this is an issue born from tireless compliance to standards and conventions.</p>

<p>Is it worth fixing? Shall I? &#8211;</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> angle<span class="sy0">,</span>
    radians <span class="sy0">=</span> foo.<span class="me1">getRadians</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span>
    ...<span class="sy0">;</span>
&nbsp;
angle <span class="sy0">=</span> radians <span class="sy0">/</span> Math.<span class="me1">PI</span> <span class="sy0">*</span> <span class="nu0">180</span><span class="sy0">;</span></pre></div></div>




<p>I fixed it! The variable declarations are in order. But at what cost? I&#8217;ve moved down the actual assignment of <code>angle</code> to after the declarations.</p>

<p>But doing this would not serve the convention&#8217;s purpose because we haven&#8217;t made it easier to find <code>angle = ...</code>.</p>

<p>Okay, so I guess the correct thing to do would be to rename one of the variables so that they&#8217;re ordered correctly. Now, I&#8217;m sitting here thinking of what I should name a variable. I&#8217;m looking for a word that means the same as <code>angle</code> but starts with a letter beyond <code>r</code>. This is starting to feel less like programming and more like a game.</p>

<p>Let&#8217;s be honest though. Nobody is going to have trouble finding either of these variables. There are only two. And I would argue that the jQuery variable block is also easily navigable.</p>

<p>As programmers, surely it is our responsibility to ensure that our code is well abstracted and that we separate our concerns. If we do this effectively we should rarely end up with lists of more than five variables in each function/method, give or take a few.</p>

<p>If you have a list of variables that is difficult to navigate then you&#8217;re problem isn&#8217;t going to be fixed by applying a convention &#8212; it&#8217;s going to be fixed by abstracting code and separating concerns.</p>

<p>Also, more often than not, the way in which I order variables is governed by the way in which they relate to each-other, semantically, and the functional story that is told through their assignments, e.g.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> data <span class="sy0">=</span> getData<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw2">var</span> id <span class="sy0">=</span> data.<span class="me1">id</span><span class="sy0">;</span>
<span class="kw2">var</span> base <span class="sy0">=</span> getBaseById<span class="br0">&#40;</span>id<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// [rest of the function]</span>
<span class="co1">// usage of `data`, `id` and `base` etc.</span></pre></div></div>




<p>A story is told through variable assignment, just like it is through flow control.</p>

<p>At least in my personal code I make it a policy to not let conventions have undue authority. I don&#8217;t code for conventions. I didn&#8217;t make this website so that it would pass HTML validation. I don&#8217;t worry about JSLint. I don&#8217;t lie awake at night wondering where I&#8217;ll find that lost semi-colon!</p>

<p>What I do worry about is creating functional and readable code. Sometimes it&#8217;s difficult and I end up with a mess. But that mess isn&#8217;t going to be fixed by stringent coding standards &#8212; it&#8217;s going to be fixed by repeated application of my programming abilities to abstract and separate.</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/ordering-variable-declarations/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>The London Commute</title>
		<link>http://james.padolsey.com/general/london-commute/</link>
		<comments>http://james.padolsey.com/general/london-commute/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 23:30:11 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[My Life]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=2010</guid>
		<description><![CDATA[In September of last year I set about looking for a contracting role in London. They&#8217;re seemingly abundant and well paid, especially if you&#8217;re young and degree-less. I held my breath and accepted a two-month contract at a small &#8220;digital&#8221; agency near Regents Park. An&#8230;]]></description>
			<content:encoded><![CDATA[<p>In September of last year I set about looking for a contracting role in London. They&#8217;re seemingly abundant and well paid, especially if you&#8217;re young and degree-less. I held my breath and accepted a two-month contract at a small &#8220;digital&#8221; agency near Regents Park. An optimistic commute from where I lived was around 100 minutes. I knew that it would be a difficult undertaking having already been riding the commuting bandwagon for three months prior.</p>

<p>Perfecting my route only took a week of practice and within no time I had it down to a ninety-minute sprint, but bad days could lengthen it to a full two hours. A potential four-hour commute each day is huge, especially if the destination is neither friendly nor enjoyable. Of course, I shouldn&#8217;t complain. At any time I had the luxury of leaving with little or no repercussions. A minimal-commitment contract is a great thing when you&#8217;re working in a thankless technical role in an office not made for comfort, but for new-age openness. At any time you can see and hear twenty-odd people tapping away, sipping at their vices, and mindlessly badgering on about something that has nothing to do with anyone else in the room. I craved an office of my own so badly.</p>

<p>Everything about the layout of the office, the facilities, the chairs, the decor, the agency culture&#8230; all of it screamed a wretched ignorance of ideal working conditions. It&#8217;s painfully wonderful to watch as my very own passion for something as seemingly dull as JS is sucked dry by idiotic requests, mundane tasks and a socially hostile working environment. It&#8217;s invisible most of the time, but the really tiny things make a difference. I am almost entirely sure that I wouldn&#8217;t have lasted the full two months if not for having a desk (or rather, a contemporary-styled bar and bar-stool setup) next to a window.</p>

<p>You see, the window is what reminded me, every few minutes, that this thing I&#8217;m tapping away on isn&#8217;t the world, and neither are the people around me. A frequent dose of perspective enabled me to keep my sanity. The window overlooked a hostel so I could distract myself by peering at the comings and goings of guests, each from different cultures, walks-of-life, and each leading lives, at those moments, far more interesting than the one I was silently avoiding as it sat baring bugs and browser inconsistencies before me.</p>

<p>I can only introspect or guess at what other people tell me. I, for one, find that my motivation fluctuates. It doesn&#8217;t sit still for eight hours as I&#8217;m required to. Most days commuting home were spent wondering why on earth we still make things so unbelievably difficult for ourselves. Actually, it&#8217;s no wonder at all. It&#8217;s not us. It&#8217;s them. The ones who decide that you should have to come in and work at the desk, live at the desk, eat at the desk, be the desk. You may as well be, because to &#8220;them&#8221;, in traditional (but still widely pervasive) business-management models, you are just an occupier of a desk and a fixer of bugs.</p>

<p>I said no to what seemed like a collective silent social contract which required everyone to eat at their desks while continuing work or forgo lunch and opt instead for the seventh red bull. It felt liberating just to leave for lunch everyday. This feeling never faded over time. I loved the first breath of fresh air at lunch and when leaving to go home in the evening. Freedom!</p>

<p>So, the two months did eventually finish and I felt giddy from the relief. I knew that this wasn&#8217;t normal. It shouldn&#8217;t be such a struggle, I thought, surely! This commute, this work, everything was dry and spent in my mind. I didn&#8217;t want any of it.</p>

<p>With time I realised that the mental grief of the daily haul to work could be eradicated by working at home. This had an unbelievably huge array of added benefits. The big struggle would be finding a job that would allow me to work at home while pursuing the passions that, thankfully, I still held.</p>

<p>After some time I got that very job I was looking for. Uxebu, an entirely-JavaScript company, based in Munich, employed me. I&#8217;m able to work completely at home. The benefits of working from home included:</p>

<ul>
  <li>I gained X hours every day from not having to commute!</li>
  <li>I can stand up and stretch at any time without creating a spectacle</li>
  <li>I can change my working environment whenever I please. I can sit on the chair, lie on the floor, go outside (a laptop does help with this).</li>
  <li>I can wear what I want.</li>
  <li>I can model my entire environment to suit me. The music, the light, the decor, everything.</li>
  <li>I can crawl out of bed on a bad morning and still not be late for work.</li>
  <li>I can take a long cycle through London parks, tasting fresh air, instead of spending hours in the stuffy London underground.</li>
  <li>I can spend more time with my family while <em>not</em> commuting.</li>
  <li>The list goes on&#8230;</li>
</ul>

<p>The benefits so vastly outweigh the cons that I am in no doubt that as long as I do this for a living I will favour this setup. Not everyone is like me though. For some, the office environment suits. For me, though, working from home seems to suit.</p>

<p>The key thing about the list above is that every one of those items enables me to be a better worker, a happier person, a healthier person and a more passionate person because there are less things sucking my motivations dry.</p>

<p>A giddy and hopefully long-lasting farewell to the London commute!</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/general/london-commute/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.968 seconds --><!-- Cached page generated by WP-Super-Cache on 2012-05-10 16:08:45 -->

