<?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>Outside the Box() &#187; extcore</title>
	<atom:link href="http://www.sporcic.org/tag/extcore/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sporcic.org</link>
	<description>Blog of Tim Sporcic</description>
	<lastBuildDate>Tue, 13 Jul 2010 14:57:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Slick Speed</title>
		<link>http://www.sporcic.org/2009/04/slick-speed/</link>
		<comments>http://www.sporcic.org/2009/04/slick-speed/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 04:16:10 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[extcore]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.sporcic.org/?p=307</guid>
		<description><![CDATA[One of the big questions that people have had about ExtCore is why didn&#8217;t it make use of the Sizzle selector engine. That was one of the questions I wanted to get answered at the Ext Conference last week, and I managed to pin down one of the core developers to get an answer. Their [...]]]></description>
			<content:encoded><![CDATA[<p>One of the big questions that people have had about <a href="http://extjs.com/products/extcore/">ExtCore</a> is why didn&#8217;t it make use of the <a href="http://sizzlejs.com/">Sizzle</a> selector engine. That was one of the questions I wanted to get answered at the <a href="http://extjs.com/conference/">Ext Conference</a> last week, and I managed to pin down one of the core developers to get an answer. Their opinion was that Sizzle is too large and too slow. I don&#8217;t really care about the size aspect. They all tend to pack down into the 25K range, but I was interested in the speed comment. Like a lot of folks, I was led to believe that Sizzle had a lot of, well, sizzle. So in the interest of getting to the bottom of the story, I did a little unscientific testing of my own using <a href="http://github.com/kamicane/slickspeed/tree/master">Slickspeed</a>, which tests selector engine performance.</p>
<p>I grabbed the latest of the main libraries: ExtCore (beta1), <a href="http://jquery.com/">JQuery 1.3.2</a>, <a href="http://www.dojotoolkit.org/">Dojo Core 1.3.0</a>, <a href="http://www.prototypejs.org/">Prototype 1.6.0.3</a> and the Sizzle engine by itself. I ran Sizzle by itself because although JQuery uses Sizzle, the version of Sizzle in JQuery 1.3.2 is 0.93 while the current version on the Sizzle website is version 1.0. I used the latest version of Slickspeed and made three runs in IE8, Firefox 3.0.8 and Chrome 1.0.154.3. Yes, I disabled Firebug in Firefox. My dev desktop is a rather beefy Windows Vista 64-bit machine with a quad-core 2.66ghz CPU and 8GB of RAM. I did a complete page refresh between runs to start relatively clean. I was going to relaunch the browser between runs, but it ended up not making much of a difference.</p>
<p>First up was the latest and greatest from Microsoft, Internet Explorer 8. </p>
<ul>
<li><strong>Prototype:</strong> 440ms</li>
<li><strong>Dojo:</strong> 61ms</li>
<li><strong>JQuery:</strong> 48ms</li>
<li><strong>ExtCore:</strong> 80ms</li>
<li><strong>Sizzle:</strong> 46ms</li>
</ul>
<p><a href="http://www.sporcic.org/wp-content/uploads/2009/04/ie8.png"><img src="http://www.sporcic.org/wp-content/uploads/2009/04/ie8-152x300.png" alt="ie8" title="ie8" width="152" height="300" class="alignnone size-medium wp-image-311" /></a></p>
<p>The image shows the results from the last run. I was actually surprised that IE8 did reasonably well. One thing is clear, friends don&#8217;t let friends use Prototype with Internet Explorer. </p>
<p>Firefox was a slightly different story. The selector engine in Prototype still got its clock cleaned, and ExtCore swapped around with JQuery and Sizzle:</p>
<ul>
<li><strong>Prototype:</strong> 145ms</li>
<li><strong>Dojo:</strong> 64ms</li>
<li><strong>JQuery:</strong> 77ms</li>
<li><strong>ExtCore:</strong> 49ms</li>
<li><strong>Sizzle:</strong> 71ms</li>
</ul>
<p><a href="http://www.sporcic.org/wp-content/uploads/2009/04/ff3.png"><img src="http://www.sporcic.org/wp-content/uploads/2009/04/ff3-154x300.png" alt="ff3" title="ff3" width="154" height="300" class="alignnone size-medium wp-image-314" /></a></p>
<p>It was interesting both Sizzle implementations slow down in Firefox. I would wager that the Sizzle folks made a conscious decision to optimize the core selector engine for the most widely used browser (Internet Explorer).  ExtCore leaps ahead with Firefox 3, while Dojo is still pretty consistently finishing in the middle. Oh, and friends don&#8217;t let friends use Prototype with Firefox either.</p>
<p>Chrome is an absolutely game-changing stunner of a browser. Based on the selector benchmarks, the developers for all these engines should be offering to have children for the Chrome developers:</p>
<ul>
<li><strong>Prototype:</strong> 13ms</li>
<li><strong>Dojo:</strong> 7ms</li>
<li><strong>JQuery:</strong> 8ms</li>
<li><strong>ExtCore:</strong> 13ms</li>
<li><strong>Sizzle:</strong> 8ms</li>
</ul>
<p><a href="http://www.sporcic.org/wp-content/uploads/2009/04/chrome.png"><img src="http://www.sporcic.org/wp-content/uploads/2009/04/chrome-157x300.png" alt="chrome" title="chrome" width="157" height="300" class="alignnone size-medium wp-image-318" /></a></p>
<p>Even lowly Prototype with Chrome makes any of the other libraries running in Firefox look like they&#8217;re standing still. Chrome is simply ungodly fast with all them. ExtCore could probably still use some tweaking, but we&#8217;re talking about a 7ms delta between the fastest and slowest.</p>
<p>So the Ext team&#8217;s claims for Sizzle being slower are only partially true. Sizzle appears to be faster in Internet Explorer, while the story flips around in Firefox where ExtCore is faster. All of them, even Prototype, are fast in Chrome. Pray for the day when Chrome takes over the world. Until that time, It looks like all them (Dojo, JQuery/Sizzle, ExtCore) are good in IE and Firefox, with the nod going to JQuery/Sizzle for Internet Explorer, the browser market share leader. And you really, really don&#8217;t want to use Prototype until all your clients have moved to a modern browser with native selector engines, or Chrome. </p>
<p>One glaring omission is that I didn&#8217;t test with IE7 or IE6. Using either of those browsers is also on my &#8220;friends don&#8217;t let friends&#8230;&#8221; list. It would be safe to say that they would both be slower. As I don&#8217;t have either installed on any of my computers, I would be happy to add an update for anyone who wants to run the tests themselves.</p>
<p>The Ext team earns some slack in their Internet Explorer performance as they are only a beta compared to the others. I&#8217;ll rerun the test again when ExtCore goes GA. And on a final note, here is the <a href='http://www.sporcic.org/wp-content/uploads/2009/04/config.ini'>config.ini</a> file for Slickspeed in case anyone wants to try the benchmark themselves, or you can grab the whole <a href='http://www.sporcic.org/wp-content/uploads/2009/04/slickspeed.zip'>Slickspeed</a> install with the selector engines configured.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sporcic.org/2009/04/slick-speed/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Beyond the Core</title>
		<link>http://www.sporcic.org/2009/04/beyond-the-core/</link>
		<comments>http://www.sporcic.org/2009/04/beyond-the-core/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 02:13:18 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[extcore]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.sporcic.org/?p=260</guid>
		<description><![CDATA[In my earlier post, I compared the new Ext Core JavaScript library with JQuery to demonstrate how close they are on core functionality. I explicitly kept the scope narrowed down to areas where the two libraries overlapped, and my conclusion was that both are winners but I prefer Ext Core since I use ExtJS and [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://www.sporcic.org/2009/04/ext-core/">earlier post</a>, I compared the new <a href="http://extjs.com/products/extcore/">Ext Core</a> JavaScript library with <a href="http://jquery.com/">JQuery</a> to demonstrate how close they are on core functionality. I explicitly kept the scope narrowed down to areas where the two libraries overlapped, and my conclusion was that both are winners but I prefer Ext Core since I use <a href="http://extjs.com/products/extjs/">ExtJS</a> and prefer the coding style. </p>
<p>In this post, I want to get in to demonstrating some of the features of Ext Core that are either coded differently from JQuery or that the base JQuery library does not implement. The excellent Ext.Core <a href="http://extjs.com/products/extcore/manual/">manual</a> has more detail on all the functions, so I&#8217;ll just bring attention to some of cool functionality I like. </p>
<h3>Base Class Enhancements</h3>
<p>One feature that might be controversial for some developers is that Ext Core augments some of the base JavaScript objects to ensure some features are present across implementations and to add some useful helper methods. The JavaScript Augmentation section of the manual has details on all the enhanced methods. Function, Array and String are the three base objects that get augmented.</p>
<p>For example, the String object is augmented with a static <code>format()</code> method that essentially allows the String to function like a typical printf function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> dest <span style="color: #339933;">=</span> <span style="color: #3366CC;">'World'</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> greeting <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Hello'</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> msg <span style="color: #339933;">=</span> String.<span style="color: #660066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'{0}, {1}!'</span><span style="color: #339933;">,</span>greeting<span style="color: #339933;">,</span> dest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// msg contains &quot;Hello, World!&quot;</span></pre></div></div>

<p>The Array object is augmented with <code>indexOf()</code> and <code>remove()</code> methods, and the Function object itself picks up several OO-centric functions. </p>
<p>The reasoning behind the augmentations are in the manual. I have mixed feelings on augmenting the language&#8217;s base objects, but the features are appreciated.</p>
<h3>Namespaces</h3>
<p>Using a namespace mechanism so that all your variables don&#8217;t pollute the global namespace is something every JavaScript coder should be doing. There are plenty of code snippets out there to demonstrate how this is done, but Ext Core makes it easy for you by including namespace support as a part of the library. All this is handled through the <code>Ext.namespace()</code> static method.</p>
<p>Take a look at the sample below. The comments indicate the filenames:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// first.js</span>
Ext.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'First'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
First.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Tim'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// second.js</span>
Ext.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Second.<span style="color: #660066;">sayHello</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> String.<span style="color: #660066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello, {0}'</span><span style="color: #339933;">,</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// main.js</span>
Ext.<span style="color: #660066;">onReady</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	Second.<span style="color: #660066;">sayHello</span><span style="color: #009900;">&#40;</span> First.<span style="color: #000066;">name</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The three JavaScript files don&#8217;t even need to be imported in this order. Everything happens through the namespace references declared at the tops of the files and managed by Ext Core. In this case, objects called First and Second were created under window, and the sayHello method and &#8216;name&#8217; variable were placed under them. This means our code only added two variables to the global space. This didn&#8217;t make a difference with only two variable declarations, but can have a huge impact with a typical application.</p>
<p>Namespaces can be hierarchical, so you can limit the global pollution to a single entry. For example, you can define a namespace like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Application.Init'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ext Core will create all the intermediate namespaces, so you could places variables under both <code>Application.Init</code> and <code>Application</code> with this single declaration. This provides a similar naming hierarchy to what you would find in Java packages or C# namespaces.</p>
<h3>Encode and Decode</h3>
<p>Ext Core provides helper methods to encode and decode both JSON and URL-encoded data. The <code>Ext.encode</code> and <code>Ext.decode</code> will encode or decode JSON objects to and from Strings. This is useful for the AJAX methods, as I demonstrated in my other post. In the current beta, the encode and decode methods aren&#8217;t implemented yet, but they are in the documentation, so I&#8217;m expecting to see them before the final release.</p>
<p>The <code>Ext.urlEncode</code> and <code>Ext.urlDecode</code> methods will encode or decode JSON objects to URL-encoded strings. One typical example is to decode query string parameters. For example, if the page URL was this: <code>http://mycoolapp.com?name=Tim&#038;lang=Java</code>, you could easily decode the query string into a JSON object using this snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">decode</span><span style="color: #009900;">&#40;</span> document.<span style="color: #660066;">location</span>.<span style="color: #660066;">search</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> String.<span style="color: #660066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello, {0}'</span><span style="color: #339933;">,</span> params.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Yes, this is a bit of a hack. I didn&#8217;t do error checking to ensure there was a value for search before using substr(). The substr() is necessary when working with a query string because the search value will start with a question mark (?), which the <code>Ext.urlDecode</code> method won&#8217;t strip off. </p>
<h3>Templates</h3>
<p>Ext Core thankfully includes Templates, a feature generously carried down from ExtJS. Templates simplify the repetitive generation of HTML fragments, which is something that typically happens in AJAX intensive web application. The Ext.Template class allows you to define an HTML fragment as a template, using tokens which will be replaced with the values from a JSON object. For example, here is a code sample of a Template used to format an RSS feed from Slashdot that I turned into a JSON object:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Feed.data is an array of JSON objects that look like this:</span>
<span style="color: #006600; font-style: italic;">// {title: 'title', link: 'link', description: 'description'}</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> template <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Template</span><span style="color: #009900;">&#40;</span>
            <span style="color: #3366CC;">'&lt;div class=&quot;story&quot;&gt;'</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'&lt;h3&gt;&lt;a href=&quot;{link}&quot;&gt;{title}&lt;/a&gt;&lt;/h3&gt;'</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'{description}'</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// stories is the id of the empty div on the page</span>
<span style="color: #003366; font-weight: bold;">var</span> stories <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'stories'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Ext.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>Feed.<span style="color: #660066;">data</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    template.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>stories<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This snippet also demonstrates the <code>Ext.each()</code> helper method for iterating over the contents of an array. You can download the full snippet <a href="http://www.sporcic.org/wp-content/uploads/2009/04/feed.zip">here</a> to play with. </p>
<p>As Ext Core is still in beta, there is a disconnect between the API documentation and the actual implementation. If the Ext.Template class is updated to correspond to the documentation, there are also some neat formatting effects that can be applied. For example, instead of the placeholder <code>{description}</code>, you could use <code>{description:ellipsis(20)}</code> which will truncate any string longer than 20 characters and place ellipsis at the end of the string. </p>
<p>I&#8217;ve covered a few of the cool features to make your JavaScript code easier and more maintainable. Ext Core also has some neat OO functionality that I&#8217;ll cover in another post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sporcic.org/2009/04/beyond-the-core/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
