<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Garrett Bluma &#187; Javascript</title>
	<atom:link href="http://garrettbluma.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://garrettbluma.com</link>
	<description>Web Developer</description>
	<lastBuildDate>Mon, 21 May 2012 00:00:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Coffeescript Contracts</title>
		<link>http://garrettbluma.com/2011/09/07/coffeescript-contracts/</link>
		<comments>http://garrettbluma.com/2011/09/07/coffeescript-contracts/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 17:46:10 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Microblog]]></category>

		<guid isPermaLink="false">http://garrettbluma.com/?p=865</guid>
		<description><![CDATA[<a href="http://disnetdev.com/contracts.coffee/">contracts.coffee @ GitHub</a>.

Mozilla Research:
<blockquote>Contracts.coffee is a dialect of CoffeeScript with built-in support for contracts. It is inspired by the contract system found in Racket.


Contracts let you clearly—even beautifully—express how your code behaves, and free you from writing tons of boilerplate, defensive code.</blockquote>
Personally, I think that this <em>update</em> to coffeescript is actually more significant that coffeescript itself. The ability to define invariants (static constraints on data) is something badly needed for new projects.

The likeness to Coffeescript contracts and Haskell types is significant and likely to draw a lot of comparison. Haskell folks might argue that it's still not static typed -- and they'd be right -- but I think they would be missing the bigger picture that <em>this is a huge leap forward for usage of invariants </em> in a (somewhat) common language.]]></description>
			<content:encoded><![CDATA[<p>See: <a href="http://disnetdev.com/contracts.coffee/">contracts.coffee @ GitHub</a>.</p>
<p>Mozilla Research:</p>
<blockquote><p>Contracts.coffee is a dialect of CoffeeScript with built-in support for contracts. It is inspired by the contract system found in Racket.</p>
<p>Contracts let you clearly—even beautifully—express how your code behaves, and free you from writing tons of boilerplate, defensive code.</p></blockquote>
<p>Personally, I think that this <em>update</em> to coffeescript is actually more significant that coffeescript itself. The ability to define invariants (static constraints on data) is something badly needed for new projects.</p>
<p>The likeness to Coffeescript contracts and Haskell types is significant and likely to draw a lot of comparison. Haskell folks might argue that it's still not static typed -- and they'd be right -- but I think they would be missing the bigger picture that <em>this is a huge leap forward for usage of invariants </em> in a (somewhat) common language.</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2011/09/07/coffeescript-contracts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firmin, a JavaScript animation library using CSS transforms and transitions</title>
		<link>http://garrettbluma.com/2011/07/13/firmin-a-javascript-animation-library-using-css-transforms-and-transitions/</link>
		<comments>http://garrettbluma.com/2011/07/13/firmin-a-javascript-animation-library-using-css-transforms-and-transitions/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 20:26:38 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Microblog]]></category>

		<guid isPermaLink="false">http://garrettbluma.com/?p=780</guid>
		<description><![CDATA[<a href="http://extralogical.net/projects/firmin/">Firmin, a JavaScript animation library using CSS transforms and transitions</a>.

With all the benefits that CSS transforms and animations can offer -- namely better performance &#38; lower power consuption -- it would make sense to wrap it in an API similar to what we've seen with other javascript APIs.
<blockquote><span class="Apple-style-span" style="color: #1a1a1a; font-family: Georgia, 'Times New Roman', Times, sans-serif; font-size: 14px; line-height: 21px;">The animation of transform properties can be hardware accelerated because modifying them doesn’t force a <span style="color: #1e4f69;"><span class="Apple-style-span" style="border-bottom-width: 1px; border-style: initial; border-color: initial; outline-style: initial; outline-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-bottom-style: solid; border-bottom-color: #a3becc;">reflow</span></span> of the page; </span>

-- <a href="http://extralogical.net/articles/firmin-javascript-animation.html">Extralogical.net</a></blockquote>]]></description>
			<content:encoded><![CDATA[<p><a href="http://extralogical.net/projects/firmin/">Firmin, a JavaScript animation library using CSS transforms and transitions</a>.</p>
<p>With all the benefits that CSS transforms and animations can offer -- namely better performance &amp; lower power consuption -- it would make sense to wrap it in an API similar to what we've seen with other javascript APIs.</p>
<blockquote><p><span class="Apple-style-span" style="color: #1a1a1a; font-family: Georgia, 'Times New Roman', Times, sans-serif; font-size: 14px; line-height: 21px;">The animation of transform properties can be hardware accelerated because modifying them doesn’t force a <span style="color: #1e4f69;"><span class="Apple-style-span" style="border-bottom-width: 1px; border-style: initial; border-color: initial; outline-style: initial; outline-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-bottom-style: solid; border-bottom-color: #a3becc;">reflow</span></span> of the page; </span></p>
<p>-- <a href="http://extralogical.net/articles/firmin-javascript-animation.html">Extralogical.net</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2011/07/13/firmin-a-javascript-animation-library-using-css-transforms-and-transitions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Server-side Javascript &amp; DOM (i.e. GWT Without the Java)</title>
		<link>http://garrettbluma.com/2010/10/20/server-side-javascript-dom-i-e-gwt-without-the-java/</link>
		<comments>http://garrettbluma.com/2010/10/20/server-side-javascript-dom-i-e-gwt-without-the-java/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 03:16:39 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://garrettbluma.com/?p=369</guid>
		<description><![CDATA[GWT is a great technology. It was hailed as full-stack one-language SDK with a lot of promise. However, be that as it may, I still can't use it. Coming from the perspective of a web developer and having to give up access to HTML, Javascript, DOM, and CSS is difficult. I spent the time to learn how Javascript works and the intricacies of CSS. And even supposing there is a benefit to GWT's compiled Javascript, I would need to learn a ton to make use of it. (I'll bypass the fact that a developer can't be ignorant of what's happening [...]]]></description>
			<content:encoded><![CDATA[<p>GWT is a great technology. It was hailed as full-stack one-language SDK with a lot of promise. However, be that as it may, I still can't use it.</p>
<p>Coming from the perspective of a web developer and having to give up access to HTML, Javascript, DOM, and CSS is difficult. I spent the time to learn how Javascript works and the intricacies of CSS. And even supposing there is a benefit to GWT's compiled Javascript, I would need to learn a ton to make use of it. (I'll bypass the fact that a developer can't be ignorant of what's happening behind the scenes)</p>
<p>But now, <strong>what if we flipped the idea on it's head</strong> and offered a full web application stack, built from the ground up on javascript? Both the client and server sides share the same code-base, Javascript interpreter and DOM; and can (conceivably) render portions of  a web app on either side. Consider it, because it's <em>almost</em> here.</p>
<div class="dropshadow" style="height: 300px"><img style="height:100%" class="aligncenter size-full wp-image-372" title="Dav Glass Presenting YUI Server Side" src="http://garrettbluma.com/wp-content/uploads/2010/10/LittleSnapper.png" alt="Dav Glass Presenting YUI Server Side" /></div>
<p><a href="http://blog.davglass.com/">Dav Glass</a> presenting on YUI used sever-side on NodeJS (link: <a href="http://bit.ly/aq3L87">quicktime movie</a> - 36 minutes )</p>
<p>Dav Glass presents a compelling argument for a server-side DOM. I <strong>really</strong> suggest you check it out if you have the time.</p>
<p>By having a DOM on the server-side, you can use the same Javascript code to manipulate elements and update the DOM with new information. You can create the html for a tabview on the server and then attach events on the client-end for interactive use... or just leave it server-only and let progressive fallback provide links to the alternate states of the tabs. Only one set of code is needed for both types of operation.</p>
<p>We can see the gains to be made from this kind of technology, but certainly it can't be for everybody. The web projects that, even now, work best with a clear separation of roles (i.e. PHP always equals server-side code, JS always equals client-side code). People get a nice sense of safety out of believing that one type of code should remain separate from another. <strong>And this is not for those people.</strong></p>
<p>In fact, what we might see is less of a clear separation of domains and more of a spectrum of domains. Conceivably we could even have a slider that would adjust between being all static and all dynamic (supposing, of course, that we could tie those values to different functionality being turned on and of.)</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2010/10/20/server-side-javascript-dom-i-e-gwt-without-the-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NodeJS is (almost) gonna kill PHP</title>
		<link>http://garrettbluma.com/2010/10/14/nodejs-is-almost-gonna-kill-php/</link>
		<comments>http://garrettbluma.com/2010/10/14/nodejs-is-almost-gonna-kill-php/#comments</comments>
		<pubDate>Fri, 15 Oct 2010 00:50:07 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://garrettbluma.com/?p=361</guid>
		<description><![CDATA[A few weeks back I posted that: NodeJS is gonna kill PHP There are some merits to that statement. NodeJS is moving along quickly, with new modules getting added daily. Many of the web methodologies transition easily to Node Javascript is a strong language with a strong history of development. Asynchronous from the top to the bottom. AWESOME! YOU GET TO USE ALL THE JAVASCRIPT YOU'VE EVER WRITTEN. (emphasis added) Atwood's Law (Anything that can be written in Javascript, will be written in Javascript) PHP is unable to advance. At the same time, I (almost) never consider an argument valid [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks back I posted that:</p>
<blockquote><p>NodeJS is gonna <strong>kill</strong> PHP</p></blockquote>
<p>There are some merits to that statement.</p>
<ul>
<li>NodeJS is moving along quickly, with new modules getting added daily.</li>
<li>Many of the web methodologies transition easily to Node</li>
<li>Javascript is a strong language with a strong history of development.</li>
<li>Asynchronous from the top to the bottom. AWESOME!</li>
<li>YOU GET TO USE ALL THE JAVASCRIPT YOU'VE EVER WRITTEN. (emphasis added)</li>
<li><a href="http://www.codinghorror.com/blog/2007/07/the-principle-of-least-power.html">Atwood's Law</a> (Anything that <em>can</em> be written in Javascript, <em>will</em> be written in Javascript)</li>
<li>PHP is unable to advance.</li>
</ul>
<p>At the same time, I (almost) never consider an argument valid unless there are counter-examples which help to paint a complete picture. If all I see is perfect, I must not be living in reality. As a side note, this is why if you ever listen to two programmers argue, you'll inevitably find that they will swap roles and start arguing against their original idea. It's really pretty funny if you watch for it. Regardless, I think the same rule is at play. We all want to explore the problem domain.</p>
<p>So what <em>are</em> the downsides to NodeJS (and <em>yes</em>, they do exist):</p>
<ul>
<li><strong>Non-Classical inheritance structure </strong>— It's hard enough teaching someone inheritance, I won't even venture to try to explain prototypes.</li>
<li><strong>Heavy usage of anonymous functions</strong> — Another tricky thing to teach.</li>
<li><strong>Lack of a sponsor company</strong> to direct development in advantageous directions</li>
<li><strong>Will probably never catch on in enterprise environments</strong> (due to last point)</li>
</ul>
<p>The nice thing about these problems that they are all pretty easy to overcome. John Resig has written a handy<a href="http://ejohn.org/blog/simple-javascript-inheritance/"> class that emulates classical inheritance</a>. And anonymous functions can be rewritten to work as named functions, so that's out. What's left is the difficult problem of having a stable platform that can be used by enterprise environments. In the end this is a social problem and it will just take successful companies to take the leap and others to follow.</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2010/10/14/nodejs-is-almost-gonna-kill-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Shrink Javascript with Diffable</title>
		<link>http://garrettbluma.com/2010/07/09/shrink-javascript-with-diffable/</link>
		<comments>http://garrettbluma.com/2010/07/09/shrink-javascript-with-diffable/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 17:57:51 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://garrettbluma.com/?p=281</guid>
		<description><![CDATA[It's been some time since we've seen any new javascript minifiers out there. Google Closure was probably the most recent but many argue that was basically a re-hash of Yahoo's YUI Compressor. This is something different. As web applications get better, there is more Javascript. Caching has been a big help to this—even though only effective for about 40-60% of your audience. The problem with caching however, is that when a new version of the code is released the user must download all of it again. Diffable JS makes this less of an issue becuase the user might only need [...]]]></description>
			<content:encoded><![CDATA[<p>It's been some time since we've seen any new javascript minifiers out there. <a href="http://code.google.com/closure/compiler/">Google Closure</a> was probably the most recent but many argue that was basically a re-hash of Yahoo's <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>.</p>
<p><a href="http://www.stevesouders.com/blog/2010/07/09/diffable-only-download-the-deltas/">This is something different</a>.</p>
<p>As web applications get better, there is more Javascript.</p>
<p>Caching has been a big help to this—even though only <a href="http://www.yuiblog.com/blog/2007/01/04/performance-research-part-2/">effective for about 40-60% of your audience</a>. The problem with caching however, is that when a new version of the code is released the user must download all of it again.</p>
<p><a href="http://www.stevesouders.com/blog/2010/07/09/diffable-only-download-the-deltas/">Diffable JS</a> makes this less of an issue becuase the user might only need to download 10KB of changes instead of 200KB. It also sticks close to #1 rule of web developement: <a href="http://developer.yahoo.com/performance/rules.html">make browsers download as few files as possible</a>.</p>
<p>I think this project is awesome and I need to spend some time giving this a proper look-over.</p>
<p>Diffable JS: <a href="http://www.stevesouders.com/blog/2010/07/09/diffable-only-download-the-deltas/">http://www.stevesouders.com/blog/2010/07/09/diffable-only-download-the-deltas</a></p>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2010/07/09/shrink-javascript-with-diffable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Closure Review</title>
		<link>http://garrettbluma.com/2010/01/29/google-closure-review/</link>
		<comments>http://garrettbluma.com/2010/01/29/google-closure-review/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 01:03:15 +0000</pubDate>
		<dc:creator>Garrett Bluma</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[closure]]></category>

		<guid isPermaLink="false">http://garrettbluma.com/?p=189</guid>
		<description><![CDATA[So when Google released their Closure library almost three months ago I thought to myself: "Huh, that looks pretty cool. A modular, lightweight framework that has great UI tools. What's not to love!?" I wanted then to write a post back then detailing how excited I was about it, but enough people wrote good pieces early on ( here, here, and here) and I didn't want to add to the noise. In the meantime, I decided to use Google's Closure in one of my projects. I needed to build an RIA (Rich Internet Application) type website that needed to dynamically [...]]]></description>
			<content:encoded><![CDATA[<p>So when Google released their <a href="http://code.google.com/closure/library/">Closure library</a> almost three months ago I thought to myself:</p>
<blockquote><p>"Huh, that looks pretty cool. A modular, lightweight framework that has great UI tools. What's not to love!?"</p></blockquote>
<p>I wanted then to write a post back then detailing how excited I was about it, but enough people wrote good pieces early on ( <a href="http://www.sitepoint.com/blogs/2009/11/12/google-closure-how-not-to-write-javascript/">here</a>, <a href="http://googlecode.blogspot.com/2009/11/introducing-closure-tools.html">here</a>, and <a href="http://www.tripwiremagazine.com/2009/11/first-impressions-looking-into-google-closure-im-impressed.html">here</a>) and I didn't want to add to the noise.</p>
<p>In the meantime, I decided to use Google's Closure in one of my projects. I needed to build an RIA (Rich Internet Application) type website that needed to dynamically pull in a lot of data. Having gotten through most of that project I feel like I can substantiate a review of the framework.</p>
<h3>Great for UI, not so great for the basics</h3>
<p>I initially got exicited about Closure becuase of the quality of UI elements that Google was distributing with the API. I assumed that everything has this same level of abstraction from the nitty-gritty and would simplify my code.</p>
<p><em>The failings of Closure exist in the simple tasks not the complicated ones</em>, <a href="#html_insertion">adding HTML to the DOM</a>, <a href="#ajax_requests">doing an Ajax request</a>, and <a href="#selection">even element selection</a>. I'll go into detail about each of these.</p>
<h3 id="html_insertion">HTML Insertion</h3>
<p>It's easy to use <tt>element.innerHTML</tt>, but some work needs to be done to allow those added element to respond to events in all browsers. For example, IE6 will not register an event fired by an element created via <tt>innerHTML</tt>. If, however, that <tt>innerHTML</tt> is applied to an element outside the DOM and afterwards added via <tt>appendChild</tt>, then it works.</p>
<p>The following is a comparison of the same code:</p>
<p><strong>Raw Javascript (5 steps)</strong></p>
<pre><code class="javascript">var html = "&lt;ul&gt;&lt;li&gt;a&lt;/li&gt;&lt;li&gt;b&lt;/li&gt;&lt;li&gt;c&lt;/li&gt;&lt;/ul&gt;";
var el = document.getElementById( 'id_of_element' );
var container = document.createElement( 'div' );
container.innerHTML = html;
el.appendChild( container );
</code></pre>
<p><strong>Google Closure (4 steps)</strong></p>
<pre><code class="javascript">var html = "&lt;ul&gt;&lt;li&gt;a&lt;/li&gt;&lt;li&gt;b&lt;/li&gt;&lt;li&gt;c&lt;/li&gt;&lt;/ul&gt;";
var el = goog.dom.$('id_of_element');
var fragment = goog.dom.htmlToDocumentFragment( html );
el.appendChild( fragment );
</code></pre>
<p><strong>jQuery (2 steps)</strong></p>
<pre><code class="javascript">$('#id_of_element').html(
    "&lt;ul&gt;&lt;li&gt;a&lt;/li&gt;&lt;li&gt;b&lt;/li&gt;&lt;li&gt;c&lt;/li&gt;&lt;/ul&gt;"
);
</code></pre>
<h3 id="ajax_requests">Doing an Ajax Request (specifically JSON):</h3>
<p>Here is a quick example of handling an Ajax request w/ some minor JSON validation. You don't use <tt>eval()</tt> do you?</p>
<p><strong>Raw javascript</strong><small><em>To be fair I don't know if this one works</em></small></p>
<pre><code class="javascript">// Assumes we have a valid XmlHttp object via GetXmlHttpObject()
xmlHttp=GetXmlHttpObject();
xmlHttp.open("GET","form.php?format=json",true);
xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4) {
        var data = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
	    text.replace(/"(\\.|[^"\\])*"/g, ''))) &amp;&amp;
            eval('(' + text + ')');
        // …
    }
});
</code></pre>
<p><strong>Google Closure (4 steps)</strong></p>
<pre><code class="javascript">goog.net.XhrIo.send( "form.php?format=json", function( event ) {
    if ( event.isSuccess() ) {
        var data = event.target.getResponseJson();
        // ...
    }
);
</code></pre>
<p><strong>jQuery (2 steps)</strong></p>
<pre><code class="javascript">$.getJSON('form.php?format=json', function(data) {
    // ...
});
</code></pre>
<h3 id="selection">Element Selection</h3>
<p>I'll admit, this is an unfair test since jQuery will always win this one. But the point is that <em>Google doesn't even try to make this easier for the programmer</em>. Aside from some convenience functions there is nothing special. In my mind this proves the point that Google is much more focused on solving the complex problems and not the simple ones.</p>
<p><strong>Raw Javascript</strong></p>
<pre><code class="javascript">var el = document.getElementById('id_of_element');
var myDivs = []; // … just not worth writing this by hand
</code></pre>
<p><strong>Google Closure</strong></p>
<pre><code class="javascript">var el = goog.dom.$('id_of_element');
var myDivs = goog.dom.getElementsByTagNameAndClass('div','menu-item');
</code></pre>
<p><strong>jQuery</strong></p>
<pre><code class="javascript">var el = $('#id_of_element');
var myDivs = $("div.menu-item");
</code></pre>
<h3>Conclusion</h3>
<p>It's not that Google Closure is bad, it's not. And don't discredit it because I don't want to use it. There are a ton of great applications for it and I am very happy they released it. The main issue as I see it, is that just isn't designed for rapid development — a feature I put high emphasis on. I don't want to downplay any of their hard work but from my perspective I don't see as much value in it as I used to.</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettbluma.com/2010/01/29/google-closure-review/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 4/17 queries in 0.003 seconds using memcached
Object Caching 371/401 objects using memcached

Served from: garrettbluma.com @ 2012-05-21 02:51:24 -->
