<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: jQuestion</title>
	<atom:link href="http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml/feed" rel="self" type="application/rss+xml" />
	<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml</link>
	<description>You tell that other boy, not to touch the woodwork...</description>
	<pubDate>Fri, 21 Nov 2008 18:46:31 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7-hemorrhage</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: David Mark</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-590655</link>
		<dc:creator>David Mark</dc:creator>
		<pubDate>Wed, 29 Oct 2008 05:45:11 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-590655</guid>
		<description>Right on.  The jQuery library is a terrible liability.  Using it on the public Internet is madness.  The browser sniffing alone ensures that.

And those ridiculous patterns with the $ are often described as "efficient" by jQuery proponents.  Oh brother.

And then there is the "less code" nonsense.  If you start out with a huge library, there isn't much room for your code anyway.

And its only 15K!  Yeah, right.  Even if it was, that is 15K too much.

Anything to convince incapable people to take up browser scripting.  You can't miss the influence when surfing the Web these days.</description>
		<content:encoded><![CDATA[<p>Right on.  The jQuery library is a terrible liability.  Using it on the public Internet is madness.  The browser sniffing alone ensures that.</p>
<p>And those ridiculous patterns with the $ are often described as &#8220;efficient&#8221; by jQuery proponents.  Oh brother.</p>
<p>And then there is the &#8220;less code&#8221; nonsense.  If you start out with a huge library, there isn&#8217;t much room for your code anyway.</p>
<p>And its only 15K!  Yeah, right.  Even if it was, that is 15K too much.</p>
<p>Anything to convince incapable people to take up browser scripting.  You can&#8217;t miss the influence when surfing the Web these days.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tychay</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-387739</link>
		<dc:creator>tychay</dc:creator>
		<pubDate>Mon, 17 Mar 2008 18:14:46 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-387739</guid>
		<description>…and to the shell scripter. Where did you think the choice of $ came from? I’ll hazard a guess it was because some PHP/Perl/Shell scripter was coding Javascript and found out that naming variables with $ still executed correctly.

In any case, this hypothetical Javascript nerd is abstracted from the cost of the function, which is large in the case of prototype and extreme in the case of jQuery. In the case of jQuery it also “screams ‘namespace.’”

YUI doesn't use it. Neither does DojoToolkit. Showing that, in fact, the most popular libraries of today &lt;strong&gt;do not&lt;/strong&gt; use this function.</description>
		<content:encoded><![CDATA[<p>…and to the shell scripter. Where did you think the choice of $ came from? I’ll hazard a guess it was because some PHP/Perl/Shell scripter was coding Javascript and found out that naming variables with $ still executed correctly.</p>
<p>In any case, this hypothetical Javascript nerd is abstracted from the cost of the function, which is large in the case of prototype and extreme in the case of jQuery. In the case of jQuery it also “screams ‘namespace.’”</p>
<p>YUI doesn&#8217;t use it. Neither does DojoToolkit. Showing that, in fact, the most popular libraries of today <strong>do not</strong> use this function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Crowley</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-387664</link>
		<dc:creator>Richard Crowley</dc:creator>
		<pubDate>Mon, 17 Mar 2008 16:09:42 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-387664</guid>
		<description>Just have to point out that $ to a PHP/Perl programmer looks like a variable but to EVERYONE ELSE it doesn't.  To JavaScript nerds it actually screams FUNCTION at them, so not a bad thing that all of the libraries use it.</description>
		<content:encoded><![CDATA[<p>Just have to point out that $ to a PHP/Perl programmer looks like a variable but to EVERYONE ELSE it doesn&#8217;t.  To JavaScript nerds it actually screams FUNCTION at them, so not a bad thing that all of the libraries use it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tychay</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-384309</link>
		<dc:creator>tychay</dc:creator>
		<pubDate>Wed, 12 Mar 2008 16:37:45 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-384309</guid>
		<description>@PrettyCoder: No problem! No need to apologize as you bring up an interesting point.

To the first example. Nice catch with the "rel=external" instead of my use of "class" and it also points out an error in my code above since class is in the attributes of link. It should be links.attributes.rel with a match in there. However, I think you need to benchmark your jQuery version to understand my point (abstraction costs).

To the second. As mentioned before, I wouldn't code this way, I was trying to show how a shortcut will build a bad habit in a bad programmer, here is how I would code it.

var link = document.links('blah');
link.href='http://www.example.com/';
var link_style = link.style;
link_style.display='none';
link_style.visibility='hidden';

(The last three lines would probably be…
YAHOO.util.Dom.addClass(link,'hidden');
sacrificing some speed for clarity (in markup, not in Javascript… big difference btw).)

I suggest you benchmark that also, though the difference in this case will be minimal.

…

On a personal (read opinionated) note, just because it is one line of code doesn’t make it any faster to execute, nor, in my opinion, more readable. It is the case with functional languages, and functional-style approaches, that it is quite often, slower. I have found that it is also less readable to others than more explicit approaches.

It is, no doubt, much prettier. However, if I thought coding was artful, I’d be a perl coder.</description>
		<content:encoded><![CDATA[<p>@PrettyCoder: No problem! No need to apologize as you bring up an interesting point.</p>
<p>To the first example. Nice catch with the &#8220;rel=external&#8221; instead of my use of &#8220;class&#8221; and it also points out an error in my code above since class is in the attributes of link. It should be links.attributes.rel with a match in there. However, I think you need to benchmark your jQuery version to understand my point (abstraction costs).</p>
<p>To the second. As mentioned before, I wouldn&#8217;t code this way, I was trying to show how a shortcut will build a bad habit in a bad programmer, here is how I would code it.</p>
<p>var link = document.links(&#8217;blah&#8217;);<br />
link.href=&#8217;http://www.example.com/&#8217;;<br />
var link_style = link.style;<br />
link_style.display=&#8217;none&#8217;;<br />
link_style.visibility=&#8217;hidden&#8217;;</p>
<p>(The last three lines would probably be…<br />
YAHOO.util.Dom.addClass(link,&#8217;hidden&#8217;);<br />
sacrificing some speed for clarity (in markup, not in Javascript… big difference btw).)</p>
<p>I suggest you benchmark that also, though the difference in this case will be minimal.</p>
<p>…</p>
<p>On a personal (read opinionated) note, just because it is one line of code doesn’t make it any faster to execute, nor, in my opinion, more readable. It is the case with functional languages, and functional-style approaches, that it is quite often, slower. I have found that it is also less readable to others than more explicit approaches.</p>
<p>It is, no doubt, much prettier. However, if I thought coding was artful, I’d be a perl coder.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PrettyCoder</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-384138</link>
		<dc:creator>PrettyCoder</dc:creator>
		<pubDate>Wed, 12 Mar 2008 08:46:21 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-384138</guid>
		<description>Sorry couldn't resist:

jQuery.noConflict();

&#62; for (var i in document.links) { // technically a for-do is marginally faster
&#62;     var link = document.links[i];
&#62;     if (link.class !== 'external') { continue; }
&#62;     // better and more DOM scripted to replace the below with a YAHOO.lang.augmentObject
&#62;     link.onclick = function() { return confirm('You are going to visit: ' + link.href); }
&#62; }

jQuery('a[rel*="external"], a.external').click(function(){
    return confirm('You are going to visit: ' + this.href);
});

&#62; $('#blah').href = 'http://www.example.com/';
&#62; $('#blah').style.display= 'none';
&#62; $('#blah').style.visibility = 'hidden';

jQuery('#blah').attr('href', 'http://www.example.com/').hide();</description>
		<content:encoded><![CDATA[<p>Sorry couldn&#8217;t resist:</p>
<p>jQuery.noConflict();</p>
<p>&gt; for (var i in document.links) { // technically a for-do is marginally faster<br />
&gt;     var link = document.links[i];<br />
&gt;     if (link.class !== &#8216;external&#8217;) { continue; }<br />
&gt;     // better and more DOM scripted to replace the below with a YAHOO.lang.augmentObject<br />
&gt;     link.onclick = function() { return confirm(&#8217;You are going to visit: &#8216; + link.href); }<br />
&gt; }</p>
<p>jQuery(&#8217;a[rel*="external"], a.external&#8217;).click(function(){<br />
    return confirm(&#8217;You are going to visit: &#8216; + this.href);<br />
});</p>
<p>&gt; $(&#8217;#blah&#8217;).href = &#8216;http://www.example.com/&#8217;;<br />
&gt; $(&#8217;#blah&#8217;).style.display= &#8216;none&#8217;;<br />
&gt; $(&#8217;#blah&#8217;).style.visibility = &#8216;hidden&#8217;;</p>
<p>jQuery(&#8217;#blah&#8217;).attr(&#8217;href&#8217;, &#8216;http://www.example.com/&#8217;).hide();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Braden</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-382778</link>
		<dc:creator>Braden</dc:creator>
		<pubDate>Mon, 10 Mar 2008 22:17:59 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-382778</guid>
		<description>Wow, you're right--the documentation is really slow. &lt;a href="http://remysharp.com/jquery-api/" rel="nofollow"&gt;Remy Sharp's jQuery API browser&lt;/a&gt; is a pretty good interface once it loads, but yeah, the PHP docs can't be beat. (Especially with a Firefox keyword for "p" to "http://php.net/%s".)

$().ajaxSubmit is from the form plugin, so I guess it's not jQuery itself, but the form plugin is only 8.3 KB compressed.

It's pretty easy to use "jQuery" as the namespace instead, but I'm a fan of fewer keystrokes.</description>
		<content:encoded><![CDATA[<p>Wow, you&#8217;re right&#8211;the documentation is really slow. <a href="http://remysharp.com/jquery-api/" rel="nofollow">Remy Sharp&#8217;s jQuery API browser</a> is a pretty good interface once it loads, but yeah, the PHP docs can&#8217;t be beat. (Especially with a Firefox keyword for &#8220;p&#8221; to &#8220;http://php.net/%s&#8221;.)</p>
<p>$().ajaxSubmit is from the form plugin, so I guess it&#8217;s not jQuery itself, but the form plugin is only 8.3 KB compressed.</p>
<p>It&#8217;s pretty easy to use &#8220;jQuery&#8221; as the namespace instead, but I&#8217;m a fan of fewer keystrokes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tychay</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-382739</link>
		<dc:creator>tychay</dc:creator>
		<pubDate>Mon, 10 Mar 2008 21:20:37 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-382739</guid>
		<description>@Braden I don't think the slowness is a problem with the Javascript, but a problem with the appserver. Something is really slow, especially when the content on the site is mostly static. I was just teasing about that part. ;-) But also implying something: PHP adoption, as ugly as the language is, is very fast because the docs are very extensive, URL searchable, and very, very fast.

I wasn't aware of $().ajaxSubmit(). I knew only about $.ajax() which seemed like Ajax.Request() in prototype. I haven't decided whether the $ object as a namespace is a really good idea or highly annoying, yet. It’s definitely a clever idea.

I'll be the first to admit that there is a lot in jQuery I'm not familiar with. I sort of made my bed with YUI and live with it. Its Connection Manager is too lightweight relative to most, but it gets the job done with minimal hassle and not that many libraries are dependent on it.

Thanks for your comments on my programming posts. I should mention that I often don't mean half of what I say as harshly as I say it. Mostly I write those things to get people thinking about things, even if they don't agree with me. The unwritten motto of this blog is: “Write to create context for another to think.” And I hope I do that.</description>
		<content:encoded><![CDATA[<p>@Braden I don&#8217;t think the slowness is a problem with the Javascript, but a problem with the appserver. Something is really slow, especially when the content on the site is mostly static. I was just teasing about that part. <img src='http://terrychay.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> But also implying something: PHP adoption, as ugly as the language is, is very fast because the docs are very extensive, URL searchable, and very, very fast.</p>
<p>I wasn&#8217;t aware of $().ajaxSubmit(). I knew only about $.ajax() which seemed like Ajax.Request() in prototype. I haven&#8217;t decided whether the $ object as a namespace is a really good idea or highly annoying, yet. It’s definitely a clever idea.</p>
<p>I&#8217;ll be the first to admit that there is a lot in jQuery I&#8217;m not familiar with. I sort of made my bed with YUI and live with it. Its Connection Manager is too lightweight relative to most, but it gets the job done with minimal hassle and not that many libraries are dependent on it.</p>
<p>Thanks for your comments on my programming posts. I should mention that I often don&#8217;t mean half of what I say as harshly as I say it. Mostly I write those things to get people thinking about things, even if they don&#8217;t agree with me. The unwritten motto of this blog is: “Write to create context for another to think.” And I hope I do that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Braden</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-382726</link>
		<dc:creator>Braden</dc:creator>
		<pubDate>Mon, 10 Mar 2008 20:49:34 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-382726</guid>
		<description>Not a problem.

The documentation says that $(window).load() doesn't fire until "the user agent finishes loading all content within a document, including window, frames, objects and images." (The advantage over a plain window.onload being multiple bindings handling.)

I'm not aware of an onavailable or oncontentready equivalent. I wouldn't be surprised to see libraries moving toward event delegation for ultra-speedy bindings. (It'll be as responsive as &#60;input onclick=""&#62;! The future is here!)

Yeah, to be honest, jQuery UI isn't half as mature as the base--they started fresh about a year ago. They're putting a lot of focus into it right now, though. Frankly, I don't think you give the core framework enough credit for saving developer hassle; $().ajaxSubmit() in particular is a beautiful example of abstraction from browser incompatibilities in Ajax and event handling.

I'd be interested to look into those horrifically slow demos. I'd bet money, though, that the problem isn't too many document.getElementById() calls. =)

While I'm leaving a comment, by the way, I really enjoy your programming posts. +1 funny, +1 insightful. Thanks for blogging.</description>
		<content:encoded><![CDATA[<p>Not a problem.</p>
<p>The documentation says that $(window).load() doesn&#8217;t fire until &#8220;the user agent finishes loading all content within a document, including window, frames, objects and images.&#8221; (The advantage over a plain window.onload being multiple bindings handling.)</p>
<p>I&#8217;m not aware of an onavailable or oncontentready equivalent. I wouldn&#8217;t be surprised to see libraries moving toward event delegation for ultra-speedy bindings. (It&#8217;ll be as responsive as &lt;input onclick=&#8221;"&gt;! The future is here!)</p>
<p>Yeah, to be honest, jQuery UI isn&#8217;t half as mature as the base&#8211;they started fresh about a year ago. They&#8217;re putting a lot of focus into it right now, though. Frankly, I don&#8217;t think you give the core framework enough credit for saving developer hassle; $().ajaxSubmit() in particular is a beautiful example of abstraction from browser incompatibilities in Ajax and event handling.</p>
<p>I&#8217;d be interested to look into those horrifically slow demos. I&#8217;d bet money, though, that the problem isn&#8217;t too many document.getElementById() calls. =)</p>
<p>While I&#8217;m leaving a comment, by the way, I really enjoy your programming posts. +1 funny, +1 insightful. Thanks for blogging.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tychay</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-382700</link>
		<dc:creator>tychay</dc:creator>
		<pubDate>Mon, 10 Mar 2008 19:59:01 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-382700</guid>
		<description>@Braden Really sorry about the deletion. If I had marked it as SPAM, I could have recovered but delete was delete.

Good point about onDOMReady (via $.ready()). If I'm designing an ad server, I might wish to still have the ads and such load onLoad instead. In YUI, at least, they also have onAvailable and onContentReady which are probably more appropriate for certain forms of DOM scripting. I assume they have those in jQuery?

I wasn't aware of the jQuery UI library. I might have been more aware of it if every tutorial didn’t espouse the base framework and if each page didn’t take over six seconds to load on Firefox. ;-)</description>
		<content:encoded><![CDATA[<p>@Braden Really sorry about the deletion. If I had marked it as SPAM, I could have recovered but delete was delete.</p>
<p>Good point about onDOMReady (via $.ready()). If I&#8217;m designing an ad server, I might wish to still have the ads and such load onLoad instead. In YUI, at least, they also have onAvailable and onContentReady which are probably more appropriate for certain forms of DOM scripting. I assume they have those in jQuery?</p>
<p>I wasn&#8217;t aware of the jQuery UI library. I might have been more aware of it if every tutorial didn’t espouse the base framework and if each page didn’t take over six seconds to load on Firefox. <img src='http://terrychay.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Braden</title>
		<link>http://terrychay.com/blog/article/prototype-jquery-abstraction-costs.shtml#comment-382535</link>
		<dc:creator>Braden</dc:creator>
		<pubDate>Mon, 10 Mar 2008 16:14:49 +0000</pubDate>
		<guid isPermaLink="false">http://terrychay.com/blog/?p=687#comment-382535</guid>
		<description>Thanks for letting me know that you didn't just reject it as dumb.

"Yeah, because nobody," I said, "would want to use a tool that made it easy for incompetent developers to fake it. PHP, say?"

As Mark pointed out, developers who think about what they're doing will cache query results, whether by chaining or temporary variables. And if you're reasonable, jQuery gives you a lot of elegance without noticeable delay on the client. This, for example, is quite readable and performant, I think:

$(function() {
  $('form.commentdelete').submit(function () {
    if (!confirm('Are you sure you want to delete this comment?')) {return false;}
    markFormActive(this);
    var self = this;
    $(this).ajaxSubmit({
      success: function(data, stat) {
        $(self).parents('.comment').fadeRemove();
        clearAjaxMsg();
        unmarkFormActive(self);
      },
      error: function(xhr, stat, e) {
        clearAjaxMsg();
        displayAjaxErr('Comment deletion failed.', stat, xhr);
        unmarkFormActive(self);
      }
    });
});

I'd bet that in most cases, jQuery's automatic binding to onDOMReady rather than onload alone adds more perceived responsiveness than using document.links/forms/images would.

Also, jQuery UI's calendar and autocomplete plugins, as examples of GUI widgets, are quite polished and degrade beautifully. For more complicated widgets, jQuery works well with Ext.</description>
		<content:encoded><![CDATA[<p>Thanks for letting me know that you didn&#8217;t just reject it as dumb.</p>
<p>&#8220;Yeah, because nobody,&#8221; I said, &#8220;would want to use a tool that made it easy for incompetent developers to fake it. PHP, say?&#8221;</p>
<p>As Mark pointed out, developers who think about what they&#8217;re doing will cache query results, whether by chaining or temporary variables. And if you&#8217;re reasonable, jQuery gives you a lot of elegance without noticeable delay on the client. This, for example, is quite readable and performant, I think:</p>
<p>$(function() {<br />
  $(&#8217;form.commentdelete&#8217;).submit(function () {<br />
    if (!confirm(&#8217;Are you sure you want to delete this comment?&#8217;)) {return false;}<br />
    markFormActive(this);<br />
    var self = this;<br />
    $(this).ajaxSubmit({<br />
      success: function(data, stat) {<br />
        $(self).parents(&#8217;.comment&#8217;).fadeRemove();<br />
        clearAjaxMsg();<br />
        unmarkFormActive(self);<br />
      },<br />
      error: function(xhr, stat, e) {<br />
        clearAjaxMsg();<br />
        displayAjaxErr(&#8217;Comment deletion failed.&#8217;, stat, xhr);<br />
        unmarkFormActive(self);<br />
      }<br />
    });<br />
});</p>
<p>I&#8217;d bet that in most cases, jQuery&#8217;s automatic binding to onDOMReady rather than onload alone adds more perceived responsiveness than using document.links/forms/images would.</p>
<p>Also, jQuery UI&#8217;s calendar and autocomplete plugins, as examples of GUI widgets, are quite polished and degrade beautifully. For more complicated widgets, jQuery works well with Ext.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
