<?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>Infrequently Noted &#187; javascript</title>
	<atom:link href="http://infrequently.org/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://infrequently.org</link>
	<description>Alex Russell on browsers, standards, and the process of progress.</description>
	<lastBuildDate>Thu, 16 May 2013 00:07:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Cassowary on NPM</title>
		<link>http://infrequently.org/2013/02/cassowary-on-npm/</link>
		<comments>http://infrequently.org/2013/02/cassowary-on-npm/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 14:48:16 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://infrequently.org/?p=1988</guid>
		<description><![CDATA[I continue to work on-and-off on the JS Cassowary port and now, thanks to some help from Isaac, new packages are up on NPM. The API is still marginally unstable and I expect we&#8217;ll be undergoing re-licensing sometime in the near future, but it&#8217;s very near a 0.1 release.]]></description>
				<content:encoded><![CDATA[<p>I continue to work on-and-off on the JS <a href="https://github.com/slightlyoff/cassowary-js-refactor">Cassowary port</a> and now, thanks to some help from <a href="http://izs.me/">Isaac</a>, <a href="https://npmjs.org/package/cassowary">new packages are up on NPM</a>. The API is still marginally unstable and I expect we&#8217;ll be undergoing re-licensing sometime in the near future, but it&#8217;s very near a 0.1 release.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2013/02/cassowary-on-npm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Class Warfare</title>
		<link>http://infrequently.org/2012/04/class-warfare/</link>
		<comments>http://infrequently.org/2012/04/class-warfare/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 12:23:41 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://infrequently.org/?p=1845</guid>
		<description><![CDATA[We've been debating various forms of classes in JS since the late '90s. That's right; we've been circling this drain for <em>more than a decade</em>...some worry that a form of <code>class</code> in ES6 that doesn't make coffee for you while also shooting rainbows out of it's behind won't be worth the syntactic space it takes up....Rainbow-shooting technology takes a while to build, meanwhile, wouldn't it be great if we could get a cup of joe around here? ]]></description>
				<content:encoded><![CDATA[<p>And so we&#8217;re at an impasse.</p>
<p>At the last TC39 meeting, after spending what felt like an eternity on the important topic of UTF-16 encoding, the last day hastily ended with two topics that simply could not be any more urgent: can we get something done about data mutation observation &#8212; the underpinnings for every data binding system worth a damn &#8212; and classes.</p>
<p>As you might imagine, classes got at least one cold shoulder, but this time we were able to suss out the roots of the objection: the latest majority-agreed proposal (&#8220;<a href="http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes" target="_new">Maximally Minimal Classes</a>&#8220;) isn&#8217;t &#8220;high water mark&#8221; classes and, since so much has been given up to get <em>something</em> moved down the field, classes are no longer worth having. In this post I&#8217;ll outline a bit of the debate so far, current state, and hopefully convince you that the anti-classicist&#8217;s arguments are weak.</p>
<p>But first: why classes at all?</p>
<p>There&#8217;s an ambient argument in the JS world that &#8220;we don&#8217;t need no stinking classes&#8221;. That all we must do to save the language is teach people the zen of function objects and closures and all will be well with the world&#8230;and if we lose some people, so what? I don&#8217;t want to tar everyone who sympathizes with the beginning of that sentiment with the obvious negatives of the last bit, but that&#8217;s the overall gist I get. In this view, classes are an unnecessary and lead people to consider JS code the &#8220;wrong&#8221; way. I&#8217;ve written before about how in ES6 <a href="http://infrequently.org/2011/09/why-class-doesnt-mean-what-you-think-it-means/"><em>class means function</em></a>, but that doesn&#8217;t mollify the discontent.</p>
<p>But then why any language feature at all? Why isn&#8217;t assembler good enough for everyone? Or C? Or <a href="https://developers.google.com/native-client/">C++</a>?</p>
<p>Turns out the answer is &#8220;human frailty&#8221;. Or put a different way, the process of cognition depends on very limited amounts of short-term stack space in our wetware, and computing languages are about making the <em>computer</em> hospitable for the <em>human</em>, not about telling the system what to do. Our tradeoffs in languages would look much different if we could all easily recall 20 or 30 things at a time instead of 5-10. Languages are tools for freeing creative people from registers and stacks and heaps and memory management and all the rest; all while trying to keep the creative process grounded in the reality that it&#8217;s memory words in a Von Neumann architecture; without that grounding we&#8217;d end up too disconnected from the system to deliver anything practical.</p>
<p>Abstractions, high-level semantics, types&#8230;they&#8217;re all pivots, ways of considering <em>sets</em> of things while working with an individual example of that thing mentally. You don&#8217;t consider every case all at once and don&#8217;t remember everything about the system at one time; instead you focus on the <em>arguments</em> to the current <em>function</em> which creates it&#8217;s own <em>scope</em>. All of these mechanisms create ways of limiting what you need to think about. They ease the burden of associating some things with other things by allowing you to consider smaller cases and allowing you to create or break limitations as they become variously helpful and harmful to getting something done. And we have <em>lots</em> of words to describe the things we find painful about dealing with the overhead of remembering; of a lack of directness and locality: &#8220;spaghetti code&#8221;, &#8220;unmaintainable&#8221;, &#8220;badly factored&#8221;, &#8220;tightly coupled&#8221;, etc. Where there&#8217;s a new fad in programming, odds are high that it is being touted as a solution to some aggregate behavior which causes a reasonable local decision to become globally sub-optimal. This is what language features are for and why, when you see yourself using the same patterns over and over again, something is deeply wrong.</p>
<p>I&#8217;ll say this again (and imagine me saying it sloooooowly): languages evolve in response to the pain caused by complexity. The corollary is that language which don&#8217;t evolve to remove complexity, or which add it in day-to-day usage cause pain. Pain is almost always bad.</p>
<p>Complexity takes many forms, but the process of disambiguation when looking at a syntactic form that relies on a pattern is one of the easiest to take off the table. You&#8217;ll see this in my work in lots of areas: Web Components make the relationship between markup and eventual behavior less ambiguous when you read the HTML, Shadow DOM creates an isolation boundary for CSS and HTML that make it easier to consider a &#8220;thing&#8221; in isolation when building and using them, classes in JS make it easier to read some bit of code and not be tripped up by the many meanings of the word <code>function</code>, and many of the features I&#8217;ve advocated for in CSS (mixins, hierarchy, variables) are factoring mechanisms that make it simpler to pivot between repeated stuff and the ad-hoc visual semantics of the document that mean so much to the design language.</p>
<p>Not only should we write off the luddites, we should consider every step towards lower complexity <em>good</em> and steps towards complexity and slower understanding to be <em>bad</em> and actively harmful. Tortured claims about how &#8220;you aren&#8217;t going to need those things&#8221; need to be met with evidence; in this case, what do the pervasive libraries in the ecosystem do? Yeah, those are complexity to be taken off the table. The agenda is clear.</p>
<p>But back to classes and JS.</p>
<p>We&#8217;ve been debating various forms of classes in JS since the late &#8217;90s. That&#8217;s right; we&#8217;ve been circling this drain for <em>more than a decade</em>. In that time, nearly every permutation of class system that I&#8217;m familiar with has been debated as the rightful heir to the reserved <code>class</code> keyword. From a parallel inheritance structure (non-prototypal) to &#8220;just prototypes like we have them today&#8221;, from &#8220;classes as constructor body&#8221; to &#8220;classes as object literals with constructors&#8221;, from frozen to gooey and unbaked, from classes as nominal types to totally untyped, we&#8217;ve seen it all. In all of this, the only constant has been failure. TC39 has continued, for more than a decade, to fail to field <em>any</em> class syntax (yes, I have my slice of blame-cake right here). In that time, JS has gone from being important to being <em>critical</em> to the construction of large systems; both on the client and the server. As this has happened, we&#8217;ve seen <code>function</code> pressed into service not only as lambda and method, but module, class, and pretty much every other form of ad-hoc composition system that&#8217;s needed at any point. We&#8217;re overdue for adding language-level support for all of these things. The committee has shown great ability to extend and expand upon idioms already in the language, taking syntax as a starting point and using it create new room for reducing pain (the spread operator and destructuring are great examples). Yet still many on the committee, notably Luke Hoban of Microsoft and Waldemar Horwat of Google, worry that a form of <code>class</code> in ES6 that doesn&#8217;t make coffee for you while also shooting rainbows out of it&#8217;s behind won&#8217;t be worth the syntactic space it takes up. I would have worried about this too back in &#8217;08 when I first attended a TC39 meeting, but no longer. This is a group that is good at incremental change. Rainbow-shooting technology takes a while to build; meanwhile, wouldn&#8217;t it be great if we could get a cup of joe around here? We&#8217;ve waited long enough to get something meaningful to build on and with. <em>I</em> want a hell of a lot more than what the Maximally Minimal Classes proposal adds, but they&#8217;re a starting point, and there will be more ES versions.</p>
<p>So that&#8217;s Argument #1: people will hate us if <code>class</code> doesn&#8217;t do enough.</p>
<p>True, perhaps, but they will hate us anyway. Add classes and Mikeal Rogers personally organizes the pitchfork and torch distribution points and leads the march. Don&#8217;t add classes and the world at large thinks of JS as a joke and a toy &#8212; where&#8217;d that giant library/transpiler get to, anyway? You need <em>something</em> after all. Add them and Mikeal can keep not using classes to his heart&#8217;s content, and if we add classes in the style I prefer (and which Max/Min Classes embody), he can use them <em>as</em> old-skool functions and never care how they were declared; all the while making JS more productive for folks who don&#8217;t want to buy into a whole lifestyle to get a job done.</p>
<p>What&#8217;s Argument #2? That instances created from classes aren&#8217;t frozen. That is to say, it&#8217;s still possible to add new properties to them later. You know, like every other JS object.</p>
<p>If you&#8217;re thinking &#8220;yes, but isn&#8217;t there Object.freeze() already?&#8221;, you&#8217;re not alone. What you&#8217;re witnessing here is a debate about what&#8217;s considered good, not what&#8217;s possible. You can manually freeze/seal objects to your heart&#8217;s content, but what the (tiny) minority that is strenuously making argument #2 is demanding is that nobody be allowed to use the word <code>class</code> to create a constructor function body <em>unless the resulting object is automatically frozen</em>. They are willing to hold up the entire train until this preference is mollifed, and are unhappy with any short syntax which does not bless their preferred style.</p>
<p>In fairness, I also would be grumpy to see things go a direction I don&#8217;t prefer, but consider the following syntaxes that could be deployed in a future version to create frozen classes, none of which are precluded by the Max/Min proposal:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// &quot;const&quot; causes instances to have their properties </span>
<span style="color: #006600; font-style: italic;">// frozen on exiting the constructor</span>
<span style="color: #000066; font-weight: bold;">const</span> <span style="color: #FF0000;">class</span> Point <span style="color: #009900;">&#123;</span>
  constructor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Declaring a const properties member causes the</span>
<span style="color: #006600; font-style: italic;">// constructor to check for those only, freezing exiting</span>
<span style="color: #006600; font-style: italic;">// the constructor</span>
<span style="color: #FF0000;">class</span> Point <span style="color: #009900;">&#123;</span>
  constructor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">const</span> properties <span style="color: #009900;">&#123;</span>
     <span style="color: #006600; font-style: italic;">// Object literal</span>
     ...
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And I&#8217;m sure you can think of a couple of others. The essential distinguishing feature, and the thing that is holding the entire train up, is that the word <code>class</code> without any embellishment whatsoever doesn&#8217;t work this way. Yes, I know it sounds crazy, but that&#8217;s where we&#8217;re at. You can help, though. Erik Arvidsson has implemented Max/Min classes in <a href="http://code.google.com/p/traceur-compiler/">Traceur</a> and you can try it out in the live <a href="http://traceur-compiler.googlecode.com/git/demo/repl.html">repl</a>. If you like/hate it, won&#8217;t you please let the <a href="https://mail.mozilla.org/listinfo/es-discuss">es-discuss mailing list</a> know? Or just post in the comments here for posterity. We know that these classes need <em>many</em> more features, but your thoughts about this syntax as a starting point couldn&#8217;t be more timely.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2012/04/class-warfare/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Bedrock</title>
		<link>http://infrequently.org/2012/04/bedrock/</link>
		<comments>http://infrequently.org/2012/04/bedrock/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 05:41:28 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[dhtml]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[openweb]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://infrequently.org/?p=1789</guid>
		<description><![CDATA[Jetlag has me in its throes which is as good an excuse as any to share what has been keeping me up many nights over the past couple of years; a theory of the web as a platform. I had a chance last week to share some of my thinking here to an unlikely audience [...]]]></description>
				<content:encoded><![CDATA[<p>Jetlag has me in its throes which is as good an excuse as any to share what has been keeping me up many nights over the past couple of years; a theory of the web as a platform.</p>
<p>I had a chance last week to share some of my thinking here to an unlikely audience at <a href="http://www.eclipsecon.org/2012/keynotes">EclipseCon</a>, a wonderful experience for which my thanks go to Mike Milinkovich and Ian Skerrett for being crazy enough to invite a &#8220;web guy&#8221; to give a talk.</p>
<p>One of the points I tried (and perhaps failed) to make in <a href="http://infrequently.org/12/eclipsecon/#1">the talk</a> was that in every platform that&#8217;s truly a <em>platform</em> it&#8217;s important to have a stable conceptual model of what&#8217;s &#8220;down there&#8221;. For Java that&#8217;s not the language, it&#8217;s the JVM. For the web&#8230;well&#8230;um. Yes, it bottoms out at C/C++, but that&#8217;s mostly observable through spooky action at a distance. The expressive capacity of C/C++ show up as limitations and mismatches in web specs all the time, but the essential semantics &#8212; C/C++ is just words in memory that you can do whatever you please with &#8212; are safely hidden away behind APIs and declarative forms that are unfailingly high-level. Until they aren&#8217;t. And you can forget about composition most of the time.</p>
<p>For a flavor of this, I always turn back to <a href="http://blog.j15r.com/">Joel Webber&#8217;s</a> question to me several years ago: why can&#8217;t I over-ride the rendering of a border around an HTML element?</p>
<p>It&#8217;s a fair question and one I wrote off too quickly the first time he posed it. We have <code>&lt;canvas&gt;</code> which lets us draw lines however we like, so why can&#8217;t we override the path painting for borders? Why isn&#8217;t it just a method you implement like in Flex or Silverlight?</p>
<p>Put another way: there are some low level APIs in the web that <em>suggest</em> that such power should be in the hands of us mortals. When using a low-level thing, you pay-as-you-go since lower-level things need more code (latency and complexity)&#8230;but that&#8217;s a choice. Today&#8217;s web is often mysteriously devoid of the sort of sane layering, <em>forcing</em> you to re-build parallel systems to what&#8217;s already in the browser to get a job done. You can&#8217;t just subclass the right thing or plug into the right lifecycle method most of the time. Want a <code>&lt;canvas&gt;</code>? Fine. There you go. Want a <code>&lt;span&gt;</code>? Hot <code>&lt;span&gt;</code>s coming up! But don&#8217;t go getting any big ideas about using the drawing APIs from <code>&lt;canvas&gt;</code> to render your <code>&lt;span&gt;</code>. Both are magic in their own right and for no reason other than that&#8217;s the way it has always been.</p>
<p>The craziest part in all of this is that JavaScript <em>does</em> exist in the web so you can strictly speaking do whatever you want. Goodness knows that when the platform fails us today, we&#8217;re all-too-willing to just throw JS at it. It&#8217;s crazy, in this context then, that spec authors seem to be trying to uphold a golden principle: JavaScript <em>doesn&#8217;t</em> exist. Writing it out of the story allows you to just claim that your bit of the system is magic and that it doesn&#8217;t need an exposed lifecycle and plug-in architecture. New things can just be bolted onto the magic, no layering required. It&#8217;s magical turtles all the way down.</p>
<p>You can see why people who think in terms of VM&#8217;s and machine words might find this a bit <em>ahem</em> limiting.</p>
<p>But how much should we &#8220;web people&#8221; care about what they think? After all, &#8220;real programmers&#8221; have been predicting the imminent death of this toy browser thing for so long that I&#8217;m forgetting exactly when the hate took its various turns through the 7 stages; &#8220;Applets will save us from this insanity!&#8221;&#8230;&#8221;Ajax is a hack&#8221;&#8230;&#8221;just put a compiler in front of it and treat it as the dumbest assembler ever&#8221; (which is at least acceptance, of a sort). The web continues to succeed in spite of all of of this. So why bother with the gnashing of teeth?</p>
<p>Thanks to <a href="http://httparchive.org/trends.php">Steve Souders, I have an answer</a>: every year we&#8217;re throwing more and more JS on top of the web, dooming our best intended semantic thoughts to suffocation in the Turing tar pit. Inexorably, and until we find a way to send less code down the wire, us is them, and more so every day.</p>
<p><img style="height: 300px; width: 450px;" src="http://chart.apis.google.com/chart?chd=t:-1|12,11,12,12,12,12,12,12,12,12,13,13,13,13,13,14,14,13,14,14,14,14,14,13,14,14,14,14,14,14,14,14|-1|113,113,115,115,116,117,117,119,121,123,125,125,126,128,131,135,139,137,140,144,147,148,152,155,161,167,172,170,173,175,179,180&amp;chxl=0:|+%7C11%2F30%7C+%7C+%7C1%2F21%7C+%7C+%7C2%2F26%7C+%7C+%7C4%2F15%7C+%7C+%7C6%2F1%7C+%7C+%7C7%2F15%7C+%7C+%7C9%2F1%7C+%7C+%7C10%2F15%7C+%7C+%7C12%2F1%7C+%7C+%7C1%2F15%7C+%7C+%7C3%2F1&amp;chxt=x,y,r&amp;chs=450x300&amp;cht=lxy&amp;chco=E63C0B,982807&amp;chm=N,E63C0B,0,1::3,12,,h::8|N**kB,982807,1,1::3,12,,h::8&amp;chds=9,99,0,30,9,99,100,200&amp;chts=982807,24&amp;chtt=JS+Transfer+Size+%26+JS+Requests&amp;chma=5,5,5,25&amp;chls=1,6,3|1&amp;chxr=1,100,200,20|2,0,30,10&amp;chxs=1,982807,11.5,-0.5,lt,982807,982807|2,E63C0B,11.5,-0.5,lt,E63C0B,E63C0B&amp;chxtc=0,4|1,4&amp;chxp=0&amp;chdl=JS+Requests|JS+Transfer+Size+(kB)&amp;chdlp=bv|r"/></p>
<p>Let that picture sink in: at 180KB of JS on average, script isn&#8217;t some helper that gives meaning to pages in the breech, it <em>is</em> the meaning of the page. Dress it up all you like, but that&#8217;s where this is going.</p>
<p>Don&#8217;t think 180KB of JS is a lot? Remember, that&#8217;s <em>transfer size</em> which accounts for gzipping, not total JS size. Oy. And in most cases that&#8217;s more than 3x the size of the HTML being served (both for the page and for whatever iframes it embeds). And that&#8217;s not all; it&#8217;s worse for many sites which should know better. Check out those loading &#8220;filmstrip&#8221; views for <a href="http://httparchive.org/viewsite.php?pageid=905867">gawker</a>, <a href="http://httparchive.org/viewsite.php?pageid=903377">techcrunch</a>, and <a href="http://httparchive.org/viewsite.php?pageid=903208">the NYT</a>. You might be scrolling down, looking at the graphs, and thinking to yourself &#8220;looks like Flash is the big ticket item&#8230;&#8221;, and while that&#8217;s true in absolute terms, Flash isn&#8217;t what&#8217;s blocking page loads. <a href="http://httparchive.webpagetest.org/video/compare.php?tests=120315_8F_QAVB-r:1-c:0">JS is</a>.</p>
<p>And what for? What&#8217;s all that code doing, anyway?</p>
<p>It&#8217;s there for three reasons: first, to clean up the messes that browser vendors aren&#8217;t willing or able to clean up for themselves; second, to provide an API that becomes the new platform, and lastly to provide the app-specific stuff you are trying to get across. Only the last one is strictly valuable. You&#8217;re not including JQuery, Backbone, Prototype or Dojo into your pages <em>just</em> because you like the API (if you are, stop it). You&#8217;re doing it because the combination of API and even behavior across browsers makes them the <em>bedrock</em>. They are the new lisp of application construction; the common language upon which you and your small team can agree; just don&#8217;t expect anyone else to be able to pick up your variant without squinting hard.</p>
<p>This is as untenable as it is dangerous. It was this realization that set me and <a href="https://plus.google.com/111648463906387632236/posts">Dimitri Glazkov</a> off to build a team to do something about it more than a year and a half ago. The results are showing up now in the form of <a href="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/explainer/index.html">Web Components and Shadow DOM</a>, <a href="http://www.youtube.com/watch?v=eRZ4pO0gVWw">Mutation Observers</a> as plumbing for <a href="http://code.google.com/p/mdv/">Model Driven View</a>, and a host of new CSS capabilities and JavaScript language expressiveness wins. If that sounds like a huge pile of seemingly un-related work, let me walk back to one of the motivating questions and then I&#8217;ll fast forward to the approach:</p>
<blockquote><p>What would it mean to be able to subclass an HTML Element?</p></blockquote>
<p>We observed that most of what the current libraries and frameworks are doing is just trying to create their own &#8220;widgets&#8221; and that most of these new UI controls had a semantic they&#8217;d like to describe in a pretty high-level way, an implementation for drawing the current state, and the need to parent other widgets or live in a hierarchy of widgets.</p>
<p>Heeeeeyyyyyy&#8230;.wait a minute&#8230;that sounds a lot like what HTML does! And you even have HTML controls which generate extra elements for visual styling but which you can&#8217;t access from script. This, BTW, is what you want when building your own controls. Think the bullets of list items or the sliders generated by <code>&lt;input type="range"&gt;</code>. There are even these handy (<a href="http://infrequently.org/2011/10/real-constructors-webidl-last-call/">non-constructable!?!</a>) constructors for the superclasses in JS already.</p>
<p>So what would you need access to in order to plug into that existing system? And how should it be described? This, by the way, is the danger zone. Right about this point in the logical chain most folks tend to fall back to what they know best: C++ hacker? Give &#8216;em a crappy C++-inspired high-level-ish JS API that will make the people yelling loudest stop beating you up. Declarative guy? Force everyone to describe their components as separate documents and&#8230;yeah. XUL. You get the idea. JavaScript person? Demand the lowest level API and as much unwarranted power as possible and pretend you don&#8217;t need the browser. JS libraries are the &#8220;fuck it, we&#8217;ll do it live!&#8221; of the web.</p>
<p>None of these are satisfying. Certainly not if what we want is a platform of the sort you might consider using &#8220;naked&#8221;. And if your &#8220;platform&#8221; always needs the same shims here and polyfills there, let me be candid: it ain&#8217;t no platform. It&#8217;s some timber and bolts out of which you can make a nice weekend DIY project of building a real platform.</p>
<p>So we need to do better.</p>
<p>What does better look like?</p>
<p>Better is layered. Better is being able to just replace what you need, to plug in your own bits to a whole that supports that instead of making you re-create everything above any layer you want to shim something into. This is why mutable root prototypes in JS and object mutability in general are such cherished and loathed properties of the web. It <em>is</em> great power. It&#8217;s just a pity we need it so often. Any plan for making things better that&#8217;s predicated on telling people &#8220;oh, just go pile more of your own parallel systems on top of a platform that already does 90% of what you need but which won&#8217;t open up the API for it&#8221; is <b><em>DOOMED</em></b>.</p>
<p>Thus began a archaeology project, one which has differed in scope and approach from most of the recently added web capabilities I can think of, not because it&#8217;s high-level or low-level, but because it is layered. New high-level capabilities are added, but instead of then poking a hole nearly all the way down to C++ when we want a low-level thing, the approach is to look at the high-level thing and say:</p>
<blockquote><p>How would we describe what it&#8217;s doing at the next level down in an API that we could expose?</p></blockquote>
<p>This is the reason low-level-only API proposals drive me <em>nuts</em>. New stuff in the platform tends to be driven by <em>scenarios</em>. You want to do a thing, that thing probably has some UI (probably browser provided), and might invoke something security sensitive. If you start designing at the lowest level, throwing a C++ API over the wall, you&#8217;ve turned off any opportunity or incentive to layer well. Just tell everyone to use the very fine JS API, after all. Why should anyone want more? (hint: graph above). Instead of opening doors, though, it&#8217;s mostly burden. Everything you have to do from script is expensive and slow and prone to all sorts of visual and accessibility problems by default. If the browser can provide common UI and interaction for the scenario, isn&#8217;t that better <em>most</em> of the time? Just imagine how much easier it would be to build an app if the initial cut at location information had been <code>&lt;input type="location"&gt;</code> instead of the <a href="http://dev.w3.org/geo/api/spec-source.html">Geolocation API we have now</a>. True, that input element would need lots of configuration flags and, eventually, a fine-grained API&#8230;if only there were a way to put an API onto an HTML element type&#8230;hrm&#8230;</p>
<p>In contrast, if we go declarative-only we get a lot of the web platform today. Fine at first but horrible to work with over time, prone to attracting API barnacles to fill perceived gaps, and never quite enough. The need for that API keeps coming back to haunt us. We&#8217;re gonna need both sides, markup and imperative, sooner or later. A framework for thinking about what that might look like seems in order. Our adventure in excavation with Web Components has largely been a success, not because we&#8217;re looking to &#8220;kernalize the browser&#8221; in JS &#8212; good or bad, that&#8217;s an idea with serious reality-hostile properties as soon as you add a network &#8212; but because when you force yourself to think about what&#8217;s <em>already</em> down there as an API designer, you start making connections, finding the bits that are latent in the platform and should be used to explain more of the high level things in terms of fewer, more powerful primitives at the next layer down. This isn&#8217;t a manifesto for writing the whole world in JS; it&#8217;s a reasonable and practical approach for how to succeed by starting high and working backwards from the 80% use-case to something that eventually has most of the flexibility and power that high-end users crave.</p>
<p>The concrete steps are:</p>
<ol>
<li>Introduce new platform capabilities with high-level, declarative forms. I.e., <em><b>invent new tags and attributes</b></em>. DOM gives you an API for free when you do it that way. Everyone&#8217;s a winner.
</li>
<li>When the thing you want feels like something that&#8217;s already &#8220;down there&#8221; somewhere, try to <em><b>explain</b></em> the bits that already exist in markup in terms of a lower-level JS or markup primitive. If you can&#8217;t do that or you think your new API has no connection to markup, go back to step 1 and start again.
</li>
<li>When it feels like you&#8217;re inventing new language primitives in DOM just to get around JS language limitations, <em><b>extend the language</b></em>, not the API
</li>
</ol>
<p>On the web, JavaScript <em>is</em> what&#8217;s down there. When it&#8217;s not, we&#8217;re doing it wrong. It has taken me a very long time to understand why the Java community puts such a high premium on the &#8220;pure java&#8221; label, and fundamentally what it says to others in the community is &#8220;I appealed to no gods and no magic in the construction of this, merely physics&#8221;. That&#8217;s a Good Thing (TM), and the sort of property that proper platforms should embody to the greatest extent possible.</p>
<p>And this brings me to my final point. C/C++ might be what&#8217;s &#8220;down there&#8221; for web browsers, but that&#8217;s also been true of Java. What separates the web and Java, however, is that the Java community sees their imperative abstraction that keeps them from having to think about memory correctness (the JVM) as an <em>asset</em> and many &#8220;web people&#8221; think of JS as pure liability. I argue that because of the &#8220;you&#8217;re gonna need both sides&#8221; dynamic, trying to write JS out of the picture is a dumb as it is doomed to fail. JavaScript <em>is</em> what&#8217;s &#8220;down there&#8221; for the web. The web has an imperative backbone and we&#8217;re never going to expose C/C++ ABI for it, which means JS is our imperative successor. The archaeological dig which is adding features like Web Components is providing more power to JS by the day and if we do this right and describe each bit as a layer with an API that the one above builds on, we can see pretty clearly how the logical regress of the &#8220;you must use JS to implement the whole browser&#8221; isn&#8217;t insane. JS itself is implemented as C/C++, so there&#8217;s always room for the mother tongue and of course many of the APIs that we interact with from JS must be C/C++; you can&#8217;t write it out of the story &#8212; but that doesn&#8217;t mean we need to design our APIs there or throw bad design decisions over the wall for someone else to clean up. It is high time we started designing low-level stuff for the web in idiomatic JS (not IDL), start describing the various plug-in points for what they are. We can provide power from our imperative abstraction <em>to</em> and <em>through</em> our declarative layer in ways that make both high and low-level users of the web platform more able to interoperate, build on each other&#8217;s work, and deliver better experiences at reasonable cost. That&#8217;s the difference between a minefield and a platform. Only one of them is reasonable to build on.</p>
<p>The trash truck just came by which means it&#8217;s 6AM here in almost-sunny London. WordPress is likewise telling me that I&#8217;m dangerously out of column-inches, so I guess I&#8217;ll see if I can&#8217;t get a last hour or two of sleep before the weekend is truly over. The arguments here may not be well presented, and they are subtle, but layering matters. We don&#8217;t have enough of it and when done well, it can be a powerful tool in ending the battle between imperative and declarative. I&#8217;ll make the case some other time for why custom element names are a good idea, but consider it in the layered context: if I could subclass <code>HTMLElement</code> from JavaScript in the natural way, why can&#8217;t I just put a new tag name in the map the parser is using to create instances of all the other element types? Aside from the agreement about the names, what makes the built-in elements so special, anyway?</p>
<p>Cognitive dissonance, ahoy! You&#8217;re welcome ;-)</p>
<p><b>Note:</b> this post has evolved in the several days since its initial posting, thanks largely to feedback from <a href="https://plus.google.com/112108146349792378878/posts">Annie Sullivan</a> and <a href="http://souders.org/">Steve Souders</a>. But it&#8217;s not their fault. I promise.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2012/04/bedrock/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Misdirection</title>
		<link>http://infrequently.org/2012/02/misdirection/</link>
		<comments>http://infrequently.org/2012/02/misdirection/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 23:04:26 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[chrome]]></category>
		<category><![CDATA[economics]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[licensing]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[openweb]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://infrequently.org/?p=1724</guid>
		<description><![CDATA[As the over-heated CSS vendor prefix debate rages, I can&#8217;t help but note the mounting pile of logical fallacies and downright poor reasoning being deployed. Some context is in order. Your Moment Of Zen The backdrop to this debate is that CSS is absolutely the worst, least productive part of the web platform. Apps teams [...]]]></description>
				<content:encoded><![CDATA[<p>As the over-heated CSS vendor prefix debate rages, I can&#8217;t help but note the mounting pile of logical fallacies and downright poor reasoning being deployed. Some context is in order.</p>
<h3>Your Moment Of Zen</h3>
<p>The backdrop to this debate is that CSS is <em>absolutely</em> the worst, least productive part of the web platform. Apps teams at Google are fond of citing the meme that &#8220;CSS is good for documents, but not for apps&#8221;. I push back on this, noting the myriad ways in which CSS is <em>abysmal</em> for documents. That isn&#8217;t to minimize the pain it causes when building apps, it&#8217;s just that the common wisdom is that CSS surely must be <em>fantastic</em> for <em>somebody else</em>. Once we find that person, I&#8217;ll be sure to let you know. In the mean time we should contemplate how very, very far behind the web platform is in making it delightful to build the sorts of things that are work-a-day in native environments.</p>
<p>But it&#8217;s worse than simply being under-powered: CSS has the weakest escape hatches to imperative code and demands the most world-view contortion to understand its various layout modes and their interactions. Imagining a more congruent system isn&#8217;t hard &#8212; there are many in the literature, might I humbly suggest that now might be a good time to read <a href="http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.101.4819">Badros &#038; Borning</a>? &#8212; and even CSS could be repaired were we able to iterate quickly enough. Things have been moving faster lately, but fast enough to catch up with the yawning gap in platform capabilities? We&#8217;ll come back to the speed/scale of change later.</p>
<p>For now, consider that the debate (as <a href="http://folktrash.com/css-vendor-prefixes/">captured by Nate Vaughn</a>) is about the <em>retrospective</em> implications of the few things that have already gotten better for some set of developers in <em>some</em> situations. That this sort of meaningful progress (corners, gradients, animations, transitions, flexing boxes, etc.) is rare makes the debate all the more bone-chilling to me. We finally got a few of the long list of things we&#8217;ve been needing for a decade or more, and now because the future is unevenly distributed, we&#8217;re about to blow up the process that enabled even that modicum of progress? How is it we&#8217;re extrapolating causality about engine usage from this unevenness, anyhow? None of this is obvious to me. The credible possibility of losing prefixes as a way to launch-and-iterate is mind-exploding when you realize that the salient competition isn&#8217;t other browsers, it&#8217;s <em>other platforms</em>. Either the proponents of squatting other vendor&#8217;s prefixes haven&#8217;t thought this through very hard or they&#8217;re bad strategists on behalf of the web as a platform&#8230;not to mention their own products. The analysis that we&#8217;re being asked to accept rests on an entire series of poor arguments. Lets start with the&#8230;</p>
<h3>Uncomfortable Assumptions</h3>
<p>In an <a href="http://www.alistapart.com/articles/the-vendor-prefix-predicament-alas-eric-meyer-interviews-tantek-celik/">interview out yesterday with Eric Meyer</a>, <a href="http://tantek.com/">Tantek Çelik of Mozilla</a> tried to present this debate as a question of barriers to the adoption of non-WebKit based browsers, specifically <a href="http://www.mozilla.org/en-US/mobile/">Firefox Mobile</a>. Opera has made a similar case. What they ommit is that the only platforms where they can credibly ship such browsers are Android and S60 (a dead end). That&#8217;s <a href="http://en.wikipedia.org/wiki/File:World-Wide-Smartphone-Market-Share.png">a large (and growing) chunk</a> of the world&#8217;s handsets &#8212; good news for me, as I now work on Chrome for Android here in London &#8212; but for whatever reason it appears that <a href="http://marketshare.hitslink.com/browser-market-share.aspx?qprid=0&#038;qpcustomd=1">iOS users surf a whole lot more</a>.</p>
<p>Let that sink in: on the devices that are the source of most mobile web traffic today, it&#8217;s not <em>even possible</em> to install a browser based on a different engine, at least not without a proxy architecture like the one used in the excellent <a href="https://market.android.com/details?id=com.opera.mini.android&#038;hl=en">Opera Mini</a> or <a href="http://amazonsilk.wordpress.com/">Amazon&#8217;s Silk</a>. iOS and Windows Phone are both locked-down platforms that come with only one choice of engine (if not browser shell). When folks from the vendors who want to appropriate others&#8217; prefixes talk about &#8220;not being able to compete&#8221;, remember that competition <em>isn&#8217;t even an option</em> for the most active users of mobile browsers. And it&#8217;s prefixes that are keeping us down? We must go deeper.</p>
<p>The tension comes into focus when we talk in terms of <b>conversion</b>, <b>retention</b>, and <b>attrition</b>. Conversions are users who, if able, <em>switch</em> to a new product from an old one. Retention is a measure of how many of those users <em>continue to use</em> the product after some period of time. Today (and since Windows first included a browser), the <em>single largest factor</em> in the conversion of users to new browsers is <em>distribution with an OS</em>. This is the entire rationale behind the <a href="http://arstechnica.com/microsoft/news/2010/02/microsofts-eu-browser-ballot-approved-arrives-march-1.ars">EU&#8217;s browser choice UI, mandated on first start of new Windows installs</a>. Attrition is the rate at which users stop choosing to use your product day after day, and for most desktop installed software, attrition is <em>shockingly</em> high after 3 to 6 months. The attrition rate is usually measured by cohorts over time; users who installed on the same day/week/month to measure what % of that group continue to use the product over increasingly long periods of time. The rate of decay falls, but the overall attrition invariably continues to rise. You might not get un-installed, but that doesn&#8217;t mean you&#8217;ll still be the go-to icon on the user&#8217;s home screen or desktop. Eventually every device is recycled, wiped, or left for history in a drafty warehouse and along with it, your software. A key factor in getting attrition under control for Chrome has been evangelism to improve site compatibility, e.g. &#8220;I&#8217;m not using your browser because my bank website doesn&#8217;t work with it&#8221;. That argument &#8212; that site compatibility is key to ensuring a competitive landscape for what otherwise are substitutes &#8212; puts the entire thing in some perspective. Attrition isn&#8217;t the same thing as conversion, and conversion is driven primarily by integrations and advertising. Implicit in the arguments by Tantek and others is a sub-argument of the form:</p>
<blockquote><p>Our product would have measurably more users if sites were more compatible.</p></blockquote>
<p>Thanks to what we know about what drives conversions, in the short run this is simply false. Long term, what invariably gives you more users is <em>starting with more users</em>. The set of things that are most effective at convincing users to swap browsers, even for a day, include: advertising, word-of-mouth, a superior product, distribution/bundling, and developer advocacy. Depressingly, only one of those involves <em>actually being a better product</em>, and the prerequisite for all of them is the ability to switch (thanks, Android team!). There&#8217;s a similar dynamic at work when doing advocacy to web developers: if you&#8217;re nowhere in their browser stats, they&#8217;re adding support for a standard or worse a second prefix in order to do service to a cause, not because it&#8217;s <em>measurably good for them</em>. Clearly, that&#8217;s going to be somewhat less effective. Where, then, is the multi-million dollar advertising campaign for Fennec? The carrier and OEM rev-share deals for bundling on new Android phones? Hmm. To hear Tantek et. al. tell it, non-WebKit-based browsers would be prevalent on mobile if only it weren&#8217;t for those damned browser prefixes causing users of other browsers to receive different experiences! Also, those kids and that damned dog.</p>
<p>Over the long haul compatibility can have a dramatic effect on the rate of attrition by changing the slope of the curve &#8212; which, remember, is a rate with decay and not a single % &#8212; but it begs the next uncomfortable question: what do we mean by &#8220;compatibility&#8221; here? What sorts of incompatibility <em>cause</em> attrition? Is it content that looks <em>slightly worse</em> but still essentially works (think grey PNG backgrounds on IE6) or does it simply turn you away, not allow you to play in any way, and generally fails (think the ActiveX dependencies of yore)?</p>
<h3>Inaccessible or Ugly?</h3>
<p>Eric was good enough to call out what I view as a key point in this debate: what sort of &#8220;broken&#8221; are we talking about? Tantek responded with a link to side-by-side screenshots of various properties rendered on <a href="http://people.mozilla.com/~atrain/mobile/Evangelism/chrome-compare/chrome-compare.html">Chrome for Android&#8217;s Beta and current Fennec</a>. In some of these cases we may be looking at Fennec bugs. <a href="http://wordpress.com">WordPress.com</a> serves the same content to Fennec which seems to bork what <code>float: left;</code> means. That, or some media query is preventing the main blocks from being floated; it&#8217;s hard to tell which from a quick <code>view-source:</code>. For the versions of google.* included in the list, the front end is simply serving the desktop version to Fennec which makes the wonky button rendering even stranger. Is there room to improve what gets sent to Fennec? You bet, but that&#8217;s not what&#8217;s being argued in the main. Ask yourself this: is what you see on that page worth destroying the prefix system for? &#8216;Cause that&#8217;s what the advocates of prefix-squatting would have you believe. In effect, they&#8217;re suggesting that <em>nothing</em> will cause developers to test on non-pervasive engines, a deeply fascinating assertion. Even if we accept it, it doesn&#8217;t point clearly to a single tactic to resolve the tension. It certainly doesn&#8217;t argue most strongly for prefix-squatting.</p>
<p>An important point Eric failed to follow up on was Tantek&#8217;s assertion that Mozilla will be cloaking user-agent strings. Does he imagine that the only thing that might be cause someone to send different content is CSS support? API support for things like touch events differs, the performance characteristics of device classes and browsers vary wildly, and application developers are keen to deliver known-good, focused experiences. The <a href="http://code.google.com/mobile/articles/webapp_fixed_ui.html">endless saga of <code>position: fixed;</code> as plumbed by Google teams</a> and others is a story of competing constraints: browser vendors optimize for content, content fights back. Repeat. What does Mozilla imagine is going to happen here? Maintained content will react to the browser usage of end-users (and as we&#8217;ve covered, compat != conversions). Unmaintained content, well, that&#8217;s what fallback is all about. And bad things deserve to lose. Assuming that your browser is 100% compatible with developer expectations and testing if you only switch the UA and implement a few prefixes is NPAPI-level crazy all over again, and it&#8217;s entirely avoidable. Tantek and Brendan, of all people, should be able to reason that far. I guess they&#8217;ll find out soon enough &#8212; although we will have all been made poorer for it.</p>
<p>Now, what about the related argument that Mozilla &#038; Co. are only going to be doing this for properties which are &#8220;stable&#8221; (nevermind their actual <a href="http://www.w3.org/Style/CSS/current-work">standardization status</a>)? The argument says that because something hasn&#8217;t changed in another vendor&#8217;s prefixed version in a while, it must be safe to squat on. Not only is this (again) incredibly short-sighted, it says that instead of forcing a standard over the line and clobbering both developers and other vendors with the dreaded label of &#8220;proprietary&#8221; (the usual and effective tactic in this situation), they&#8217;re instead willing to <em>claim ownership and therefore blame</em> for the spread of this soon-to-be-proprietary stuff, all the while punting on having an independent opinion about how the features should be structured and giving up on the standards process&#8230;and all for what?</p>
<h3>Product vs. Platform</h3>
<p>Perhaps there wasn&#8217;t space in Tantek&#8217;s interview with Eric, but both of them chose not to be introspective about the causes of WebKits use in so many mobile browsers, with Tantek merely flagging the use of a single engine by multiple products as &#8220;a warning sign.&#8221; But a warning of what, exactly? Eric didn&#8217;t challenge him on this point, but I sorely wish he had. Why did Safari, the Android Browser, Chrome, Silk, Black Berry, and many others all pick WebKit as the basis for their mobile browsers?</p>
<p>WebKit <em>isn&#8217;t a browser</em>. It&#8217;s just not. To make a browser <em>based</em> on WebKit, one might bring along <em>at least</em> the following bits of infrastructure which WebKit treats as bits to be plugged in:</p>
<ul>
<li>Networking</li>
<li>Caches of some sort</li>
<li>Graphics rendering</li>
<li>A build system</li>
<li>POSIX or other platform plumbing</li>
</ul>
<p>And that&#8217;s a <em>minimum</em>. Competitive ports tend to include WebSQL, LocalStorage, and Indexed DB back-ends, video codecs, 3D infrastructure (deeply non-trivial), perhaps an alternative JavaScript engine (V8 or other), and alternative/additional image decoders (e.g., <a href="http://code.google.com/speed/webp/">WebP</a>). All of that is in addition to needing to create your own UI for bookmarking, navigation, etc. WebKit is an <em>engine</em>, not a fully-functioning vehicle. Therein may lay some of the difference in the relative success of the WebKit and Gecko on mobile to date. Want to build a Gecko-based browser? Great, first clone <a href="https://wiki.mozilla.org/Mobile/Build/Fennec#Install_build_dependencies_.28non-Maemo.29">the <em>entire Firefox codebase</em> from Mercurial</a>, then layer your stuff on top/around. Oh, wait, things might not cleanly be factored to allow you to plug in your own X, Y, or Z? Your builds take forever? Welcome to life in the Mozilla universe where your product is always second fiddle to Firefox. Now, that&#8217;s not by way of criticism, mind you. <em>It is entirely reasonable</em> for a product like Firefox not to pay coordination costs with other vendors/users of their code. God knows the overhead over here in WebKit land of trying to keep the menagerie of ports building against all changes is downright daunting. Mozilla (the organization) has made choices that prioritized the success of their <em>product</em> (Firefox) over their <em>codebase</em> (Gecko). WebKit was structured as platform only (no product), both forcing enormous costs onto every port while also freeing them from swimming upstream against a single product&#8217;s imperatives in the codebase.</p>
<p>What we&#8217;re witnessing isn&#8217;t open vs. closed, it&#8217;s differences in initial cost of adoption. In JS terms, it&#8217;s jQuery (focused core, plugins for everything else) vs. Sencha or Dojo (kitchen sink). Entirely different target users, and both will find their place. Nobody should be shocked to see smaller, more focused bits of code with good plugin characteristics spreading as the basis for new projects. The Mozilla Foundation wants to help prevent monoculture? In addition to making the Firefox product a success, there are concrete engineering things they can do to make Gecko more attractive to the next embedder, Firefox-branded or not. I haven&#8217;t heard of progress or prioritization along those lines, but I&#8217;m out of the loop. Perhaps such an effort is underway, if so, I applaud it. Whatever the future for Gecko, Product success isn&#8217;t related to platform success as a first approximation. Having a good, portable, pluggable core increases the odds of success in evolutionary terms, but it&#8217;s absolutely not determinant; see MSIE.</p>
<p>Speaking of IE&#8230;I respect those guys a lot, but the logical leap they&#8217;re asking us to swallow is that <em>the reason people return Windows Mobile phones is that some CSS doesn&#8217;t work</em>. That&#8217;s what attrition means on a platform where they&#8217;re the only native runtime. Data would change my mind, but it&#8217;s a hell of a lot to accept without proof.</p>
<h3>The Time Component</h3>
<p>Lets take a step back and consider Tantek&#8217;s claim that Mozilla has gotten very little traction in evangelizing multi-prefix or prefix-free development for the past year: Firefox for Android has been available since Oct. 2010 and stable for just 6 months. Opera Mobile on Android has been stable for just over a year. IE 9 (the only IE for mobile you could ever seriously consider not serving fallback experiences to) only appeared with Windows Phone 7.5 (aka &#8220;Mango&#8221;), shipped to users an <em>entire</em> 6 months ago.</p>
<p>And we expect webdevs to have updated all their (maintained) content? Never mind the tenuous correlation between the sorts of soft incompatibilities we&#8217;re seeing at the hands of CSS and user attrition; the argument that even this lesser form of harm hasn&#8217;t been blunted by evangelism appears suspect. Taking the incompatibilities seriously, I can quickly think of several other measures which are preferable to destroying the positive incentives towards standardization the prefix system creates (from least to most drastic):</p>
<ul>
<li>Continued evangelism to web developers with particular focus on major sites</li>
<li>Political pressure on browser vendors to start dropping prefixes (i.e., we&#8217;d all be <em>equally</em> disadvantaged until users pick up the standard version)</li>
<li>UA spoofing <em>without</em> prefix squatting</li>
<li>Blacklists to trigger alternative identity (UA/prefixes) on a subset of sites</li>
</ul>
<p>All of these are less blow-up-the-world than what MSFT, Mozilla, and Opera are proposing. It&#8217;s not even an exhaustive list. I&#8217;m sure you can think of more. Why these have either been not considered or dismissed remains a mystery.</p>
<h3>It&#8217;s More Complicated Than That</h3>
<p>In all of this, we&#8217;re faced with an existential question: what right do web developers have to shoot themselves in the foot? Is there a limit to that right? What sort of damage do we allow when some aspect of the system fails or falls out of kilter for some period of time? It&#8217;s a question with interesting parallels in other walks of life (for a flavor, substitute &#8220;web developers&#8221; with &#8220;banks&#8221;).</p>
<p>Can we show active harm to other browsers from the use of prefixes? The data is at best unclear. Arguing that any harm rises to a level that would justifies destroying the prefixes system entirely is rash. I argued many of the reasons for this in my <a href="http://infrequently.org/2011/11/vendor-prefixes-are-a-rousing-success/">last post</a>, but lets assume in our mental model that developers respond to incentives in <em>some</em> measure. If, concurrently with achieving as-yet un-managed distribution, Mozilla et. al. implement others&#8217; prefixes, what should we expect developers to do in response? After all, they will have reduced whatever tension might have been created by content that &#8220;looked wonky&#8221; and, where standards exist, will have reduced the incentive to switch to the standard version.</p>
<p>Now lets play the model one more turn of the wheel forward too: assume that Chrome or Safari (or both!) act in good faith and contemplate removing the <code>-webkit-*</code> prefix support for standardized features at a quick clip&#8230;and Mozilla doesn&#8217;t. You see how this quickly leads to a Mexican standoff: web developers won&#8217;t stop using prefixed versions because those are the way you get 100% support (thanks to Mozilla&#8217;s support for them); vendors won&#8217;t un-prefix things because <em>others</em> who squat their prefixes will then have a compatibility advantage; and nobody will be keen to add new things behind prefixes because they can no longer be assumed to be experiments that can change. Lose, lose, lose.</p>
<p>Some on the other side of the debate are keen to cite game theory as a support for their course of action, but the only conclusion I can draw is that their analysis must be predicated on a set of user and developer motivations that are entirely unlike the observable world we inhabit.</p>
<h3>A Call To Reason, Not Arms</h3>
<p>Based on a better understanding of the landscape, what should the various parties do to make the world better for themselves now and in the long run and for the web as a platform?</p>
<ul>
<li><b>Web Devs</b>: first, do no harm; test in multiple runtimes, pointedly including a &#8220;fallback&#8221;. Then enhance with prefixes. Do not apologize for giving some (or even many) of your users a better experience. That, after all, is your <em>job</em>. But know this: prefixed properties are not supported, <em>will</em> go away, and when something you didn&#8217;t test the fallback for falls over, it&#8217;s <em>your</em> fault.</li>
<li><b>Browser Vendors</b>: invest in advocacy and distribution enhancing moves for your product before threatening to blow up effective standards policies. If you&#8217;re going to implement a prefixed version, please have a different opinion or push to ram a standard through to Recommendation ASAP. Incompatible right-hand-sides help developers understand that things are still evolving. <em>DO NOT</em> squat on prefixes. It&#8217;s both relative ineffective and will make developer&#8217;s lives harder when they want to <em>legitimately</em> move to standard or support your prefixes.</li>
<li><b>Vendor CSS WG Reps</b>: get it through your heads, you&#8217;re <em>behind</em>. It&#8217;s not quaint and it&#8217;s not excusable. The platform needs more powerful CSS features, and stat. It&#8217;s long past time to start stealing good ideas from the pre-processors. Appeals to a lack of manpower to implement must never block others and shouldn&#8217;t block standardization, so please stop making them. If you care about the platform&#8217;s success, let those who are able and willing to take risks do so.</li>
<li><b>The CSS WG (as a whole)</b>: get the lead out. It&#8217;s not exclusively the W3C&#8217;s fault that things are slow, but the current MTTR (Mean Time To Recommendation) is still glacial. It is unreasonable to expect vendors to drop prefix support immediately upon standardization, but the W3C has a role here to advocate for quick sunsetting. Daniel Glazman is, as ever, right on most of this, but more can be done to streamline the process post CR.</li>
<li><b>The WebKit Project</b>: Add build flags to allow WebKit-based products to enable/disable vendor prefix support independently.</li>
<li><b>Chrome/Safari/Other-prefix-supporting-browsers</b>: Sunset prefixes as soon as is practicable post-standardization. Similarly, don&#8217;t ship prefixed features you&#8217;re not willing to be on the hook for via your reps to the CSS WG. Disabling them may be painful, but it&#8217;s the only good-faith thing to do.</li>
</ul>
<h3>Endnotes</h3>
<p>I&#8217;ve left a lot out of this post, but it&#8217;s too long already. I do truly hope it&#8217;s the last I write on prefixes because, as I said up front, we have <em>much</em> bigger fish to fry. Stat. Prefixes <em>do</em> work, they&#8217;re essential to delivering a future platform that can compete, and yes, they should be torn down at the same pace they&#8217;re erected.</p>
<p>A few things that folks have asked about as tangents to this debate:</p>
<ul>
<li>It&#8217;s never a good thing for there to be homogeneity in the experimentation phase. The <em>explicit goal</em> of the prefixes system is to enable diversity of early opinion and fast coalescing around the best answer, thereby enabling the writing of a standard which is likely to need less revising and iteration. Diversity provides some value, the market tests the alternatives, and we deliver the most value we can over time through the <em>standard</em> version. It has always been thus, but prefixes make it less risky&#8230;assuming we don&#8217;t start stepping on everyone else&#8217;s toes.</li>
<li>If the reasoning behind prefixes is to set up and tear down large-scale experiments, iterate, and collect feedback then Lea&#8217;s <a href="http://leaverou.github.com/prefixfree/">-prefix-free</a> approach and PPK&#8217;s <a href="http://www.quirksmode.org/blog/archives/2012/02/alpha_and_beta.html"><code>-alpha-*</code>/<code>-beta-*</code></a> proposals are equally counter-productive and should be avoided at all costs. Making prefixes less painful to use reduces the natural incentives for migrating to a standard while blindly assuming the same right-hand for a future standard version as we have for <em>some</em> prefixed versions is plainly idiotic. What were they thinking?</li>
<li><code><a href="http://felipe.wordpress.com/2012/02/02/a-proposal-to-drop-browser-vendor-prefixes/">@-vendor-unlock</a></code> is only slightly smarter, but in every possible way inferior to <a href="http://lists.w3.org/Archives/Public/www-style/2011Mar/0478.html">CSS Mixins</a>. Would that the WG spent as much time on Mixins as they have on this prefix kerfuffle.</li>
<li>Yes, I was in Paris when the CSS WG F2F was happening. No, I wasn&#8217;t at the meetings. Duty (Chrome for Android) called.</li>
<li>If you&#8217;ve read this far, congrats. You may be the only one. I&#8217;ve been assured by CSS WG delegates that nobody cares what I think, which statistically seems to just be rounding down by a tiny bit. Fair enough.</li>
</ul>
<p><em><b>Update</b>: <a href="http://infrequently.org/2012/02/misdirection/comment-page-1/#comment-239566">Michael Mullany of Sencha adds epicly good, epicly long context about what causes developers to target UAs and what the incentives that&#8217;ll change their minds about supporting a given browser really are.</a></em></p>
<p><em>Thanks to <a href="http://fberriman.com/">Frances Berriman</a>, <a href="http://jakearchibald.com/">Jake Archibald</a>, <a href="http://gent.ilcore.com/">Tony Gentilcore</a>, and <a href="http://www.xanthir.com/blog/">Tab Atkins</a> for reviewing earlier versions of this post. Errors of fact and form are all mine, however. Updated occasionally for clarity and to remove typos.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2012/02/misdirection/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Real Constructors &amp; WebIDL Last Call</title>
		<link>http://infrequently.org/2011/10/real-constructors-webidl-last-call/</link>
		<comments>http://infrequently.org/2011/10/real-constructors-webidl-last-call/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 14:10:03 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://infrequently.org/?p=1693</guid>
		<description><![CDATA[For those who haven&#8217;t been following the progress of WebIDL &#8212; and really, how could you not? An IDL? For the web? I&#8217;d like to subscribe to your newsletter&#8230; &#8212; the standard is now in last call, which is W3C for &#8220;alllllllllllmost done&#8221;. Which it is not. Before I get to why, let me first [...]]]></description>
				<content:encoded><![CDATA[<p>For those who haven&#8217;t been following the progress of WebIDL &#8212; and really, how could you not? An IDL? For the web? I&#8217;d like to subscribe to your newsletter&#8230; &#8212; the standard is now in <a href="http://www.w3.org/TR/2011/WD-WebIDL-20110927/">last call</a>, which is W3C for &#8220;<em>alllllllllllmost</em> done&#8221;.</p>
<p>Which it is not.</p>
<p>Before I get to why, let me first say some nice, well-earned things about WebIDL: first, it has helped us out of the ad-hoc IDL sludge that used to be how APIs for JavaScript have been exposed in the past. It has shaved off many sharp edges and is giving spec authors a single dialect in which to write their API descriptions. From a browser perspective, this is a <em>Very</em> Good Thing (TM). Next, the draft in question contains some wonderful changes from the status quo, particularly the <a href="http://www.w3.org/TR/2011/WD-WebIDL-20110927/#interface-prototype-object">addition of a sane prototype to all WebIDL-specified objects</a>.</p>
<p>That all sounds good, so what&#8217;s missing?</p>
<p>In a word, constructors.</p>
<p>Well, a lot more than that, but I&#8217;d settle for constructors. Functionally speaking, it boils down to the fact that WebIDL makes spec authors do extra work to make something like this sane:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">new</span> HTMLDivElement<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Why doesn&#8217;t this work today? Funny story&#8230;see, HTML defines <a href="http://www.w3.org/TR/html5/grouping-content.html#htmldivelement">HTMLDivElement</a> as a regular WebIDL interface. WebIDL doesn&#8217;t really have the notion of concrete classes, just interfaces with and without constructors. Since the HTML spec is just doing what most specs will do &#8212; adding the smallest IDL you can get away with &#8212; the JS usability of this API is left in limbo; neither clearly HTML5&#8242;s responsibility nor WebIDL&#8217;s.</p>
<p>So what should a contentious version of HTML5 do? One answer is to specify a constructor, turning the IDL from this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="idl" style="font-family:monospace;"><span style="color: #990078; font-weight: bold">interface</span> HTMLDivElement <span style="color: #66cc66;">:</span> HTMLElement <span style="color: #808080;">&#123;</span><span style="color: #808080;">&#125;</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>to this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="idl" style="font-family:monospace;"><span style="color: #808080;">&#91;</span>Constructor<span style="color: #808080;">&#93;</span>
<span style="color: #990078; font-weight: bold">interface</span> HTMLDivElement <span style="color: #66cc66;">:</span> HTMLElement <span style="color: #808080;">&#123;</span><span style="color: #808080;">&#125;</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>Repeat ad-infinitum for each and every interface that <em>should</em> be constructable in every single spec that browser vendors ever implement. Don&#8217;t miss any! And please make sure that all your spec editors are on-board with good JS APIs as a goal! As it stands today, WebIDL doesn&#8217;t even force most spec authors to consider the question &#8220;do I need a constructor here?&#8221; &#8212; spoiler: <em>yes</em> &#8212; let alone the obvious follow-ups like &#8220;what arguments should one take?&#8221;.</p>
<p>The obvious better answer here is to flip the default on interfaces, causing them to generate constructors by default unless turned off with <code>[NoConstructor]</code> attributes or specified as <code>partial</code> interfaces (i.e., mixins or traits).</p>
<p>Cameron McCormack who is heading up the WebIDL effort <a href="http://twitter.com/#!/heycam/status/118784862164484096">tweeted in response to my exasperation</a> that:</p>
<blockquote><p>I think a &#8220;W3C Web API design guidelines&#8221; document would be a perfect place for such a recommendation.</p></blockquote>
<p>For serious? Such a document might be useful (and I&#8217;m working on something that might pass as a first draft), but what&#8217;s the argument against flipping the default here? This isn&#8217;t a dissent on the facts of the situation: most WebIDL &#8220;interfaces&#8221; that are exposed to JS are things that could be easily <code>new</code>&#8216;d up to useful ends. Most specs flub this in spectacular style. Most spec authors seem entirely ignorant of the problem and the design language of WebIDL continues to lead down a primrose copy-and-paste path that has little overlap with sanity. So why punt the decision? And why did it take and act of coordination with TC39 to get the prototype thing fixed?</p>
<h3>And Why Are We Having This Discussion Anyway?</h3>
<p>WebIDL, for all of its virtues, is deeply confused.</p>
<p>If you&#8217;re reading any of the stuff in the HTML5 spec that&#8217;s describing its API this way, it&#8217;s hard to see how it would have any sane relationship to JavaScript. Sure, you could argue that there might be other languages that matter, other languages for which you&#8217;d need to be able to generate some API, but none of them rise to anything like the importance of JavaScript. It <em>is</em> the programming language of the web, so if WebIDL has any animating force at all, it&#8217;s JS. Then there&#8217;s the &#8220;accident of history&#8221; aspect. Early DOM was specified as a form of IDL in part because there was some expectation that other languages would need to consume it and IDL was how C++ hackers (who still make up the entire set of people working on browser engines) are/were comfortable in describing their FFIs thanks to the legacy of COM/CORBA. <a href="http://www.w3.org/TR/2011/WD-WebIDL-20110927/#java-binding">Hilarious examples of multi-language-ism still persist in the WebIDL spec</a> for no apparent reason whatsoever, warping the entire design around the altar of an ideal that is either quixotic or vestigial depending on which argument you give more weight. </p>
<p><a href="http://lists.w3.org/Archives/Public/public-script-coord/2011JulSep/thread.html#msg114">Since the debate was re-kindled thanks to a debate at a TC39 meeting in July</a>, I&#8217;ve been on the receiving end of more than one webdev&#8217;s rant about DOM&#8217;s JS incoherence, generally taking the form:</p>
<blockquote><p>Why the *#!*?^@$ isn&#8217;t DOM just #@!*@ing specified in JavaScript?</p></blockquote>
<p>To be honest, I have no answer aside from pointing to the IDL history, the fact that browser hackers don&#8217;t tend to write JS so don&#8217;t feel the pain, and noting that WebIDL <em>is</em> better in some important ways. Certainly these interfaces <em>could</em> be specified in a subset of JS with annotations for where native behavior is required. But their larger lament has merit too: seamlessness with JS is the bar WebIDL should be judged by. I.e. does it help spec authors do the right thing by JS devs? Or does it lead them down paths that make their generated APIs stick out like sore thumbs, full of anti-social/alien behavior such that you can&#8217;t think of them as &#8220;regular&#8221; JS?</p>
<p>Yes, constructors are only one minor step toward reaching this aspiration, but the fact that WebIDL has gotten to last-call without a reasonable solution to them speak volumes. If WebIDL <em>isn&#8217;t</em> animated by the need of JS developers, it would be good if that could be loudly called out somewhere so that the community can have the spirited debate that this point demands. If it is, can we please get on discussing how best to ensure that most &#8220;interfaces&#8221; generate constructors and stop punting?</p>
<p>Either way, WebIDL isn&#8217;t done yet.</p>
<p><b>Update:</b> It occurred to me, as part of the discussion in the comments, that the provision against <code>new</code> with a class or type of any type is completely non-sensical in JS, as is the lack of <code>call()</code> and <code>apply()</code> methods on them. Idiomatic subclassing requires that the mixin-style be available, which uses <code>ClassName.call(this)</code>. This is what you&#8217;d do with things that are &#8220;virtual&#8221; or &#8220;partial&#8221; interfaces if you&#8217;re describing them in actual JS. And there&#8217;s no real problem with folks <code>new</code>-ing them up. Doesn&#8217;t happen, doesn&#8217;t matter. Strong restrictions against it are, to quote Andrew DuPont, anti-social. Long story short: <b><em>there is absolutely no reason whatsoever to disable construction on any WebIDL interface. It&#8217;s deeply non-sensical from the JavaScript perspective.</em></b></p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2011/10/real-constructors-webidl-last-call/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Cutting The Interrogation Short</title>
		<link>http://infrequently.org/2011/01/cutting-the-interrogation-short/</link>
		<comments>http://infrequently.org/2011/01/cutting-the-interrogation-short/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 22:21:04 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://infrequently.org/?p=1560</guid>
		<description><![CDATA[I&#8217;ve been having a several-day mail, IRC, and twitter discussion with various folks about performance and the feature detection religion technique, particularly on mobile where CPU ain&#8217;t free. So what&#8217;s the debate? I say you shouldn&#8217;t be running tests in UA&#8217;s where you can dependably know the answer a-priori. Wait, what? Why does Alex Russell [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been having a several-day mail, IRC, and twitter discussion with various folks about performance and the feature detection <strike>religion</strike> technique, particularly on mobile where CPU ain&#8217;t free. So what&#8217;s the debate? I say you shouldn&#8217;t be running tests in UA&#8217;s where you can dependably know the answer a-priori.</p>
<p>Wait, what? Why does Alex Russell hate feature testing, kittens, and cute fuzzy ducklings?</p>
<p>I don&#8217;t. <a href="http://paulirish.com/">Paul</a> warned me that my approach isn&#8217;t going to be popular at first glance, but hear me out. My assumptions are as follows:</p>
<ul>
<li>Working is better than busted</li>
<li>Fast is better than slow</li>
<li>No browser vendor changes the web-facing features in a given version. Evar. Does not happen</li>
</ul>
<p>If you buy those, then I think we can all get some satisfaction by retracing our steps and asking, seriously, what <em>is</em> the point of feature testing?</p>
<p>Ok, I&#8217;ll go first: feature testing is motivated by a desire not to be busted, particularly in the face of new versions of UA&#8217;s which will (hopefully) improve standards support and reduce the need for hacks in the first place. Sensible enough. Why should users wait for a new version of your library just &#8217;cause a new browser was released or because you didn&#8217;t test on some version of something.</p>
<p>Extra bonus: if you don&#8217;t mind running them every time, you can write just the feature test and your work is done now and in the future! Awesome! Except some of us do mind. Yes, things are now resilient in the face of new UA&#8217;s and new versions of old ones, but only on the back of testing for everything you need ever time you load a library on a page. Slowly. Veeerrrrry slooowly.</p>
<p>Paul suggested that some library could use something like Local Storage to cache the results of these tests locally, but this hardly seems like an answer. First, what if the user upgrades their browser? Guess you have to cache and check against the UA string anyway. And what about the cost of going to storage? Paul reported that these tests can be <em>wicked</em> expensive to run at all, on the order of 30ms for the full suite (which you hopefully won&#8217;t hit&#8230;but sheesh). Reported worst-case for <a href="https://github.com/phiggins42/has.js/">has.js</a> is even worse. But apparently going to Local Storage is <em>also</em> expensive. And we&#8217;re still running all these tests in the fast path the first time anyway. If we think that they&#8217;re so expensive that we want to cache the results, why don&#8217;t we think they&#8217;re so expensive that we don&#8217;t want to run them in the common case?</p>
<p>Now for a modest proposal: <b>feature tests should only ever be run <em>when you don&#8217;t know what UA you&#8217;re running in</em></b>.</p>
<p>Feature testing libraries should contain pre-built caches &#8212; the kind that come with the library, not the kind that get built on the client &#8212; but they should only be consulted for UA versions that you <em>know</em> you know. If we assume that behavior for UA/version combination never changes, we&#8217;ve got ourselves a get-out-of-jail free card. Libraries can have <code>O(1)</code> behavior in the common case and in the situations where feature testing would keep you from being busted, you&#8217;re still not busted.</p>
<p>So what&#8217;s the cost to this? Frankly, given the size of some of the feature tests I&#8217;ve seen, it&#8217;s going to be pretty minimal vs. the bloat the feature tests add. All performance work is always a tradeoff, but if your library thinks it&#8217;s important not to break <em>and</em> to be fast, then I don&#8217;t see many alternatives. New versions of libraries can continue to update the caches and tests as necessary, keeping the majority of users fast, while at the same time keeping things working in hostile or unknown environments.</p>
<p>Anyhow, if you&#8217;re a library author or maintainer, please please <em>please</em> consider the costs of feature tests, particularly the sort that mangle DOM and or read-back computed layout values. Going slow hurts users, hurts the web, and hurts the culture of performance that&#8217;s so critical to keeping the platform a viable contender for the next generation of apps. We owe it to users to go faster.</p>
<p><b>A quick aside</b>: I hesitated writing this for the same reasons that Paul cautioned me about how unpopular this was going to be: there&#8217;s a whole lot of know-nothing advocacy that&#8217;s still happening in the JS/webdev/design world these days, and it annoys me to no end. I&#8217;m not sure how our community got so religious and fact-disoriented, but it has got to stop. If you read this and your takeaway was &#8220;Alex Russell is against feature testing&#8221;, then you&#8217;re part of the problem. Think of it like a feature test for bogosity. Did you pass? If so, congrats, and thanks for being part of the bits of the JavaScript universe that I like.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2011/01/cutting-the-interrogation-short/feed/</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>JavaScript UXO Removal Updated</title>
		<link>http://infrequently.org/2010/09/javascript-uxo-removal/</link>
		<comments>http://infrequently.org/2010/09/javascript-uxo-removal/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 21:07:00 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[dom]]></category>

		<guid isPermaLink="false">http://infrequently.org/?p=1425</guid>
		<description><![CDATA[JavaScript is a lovable language. Real closures, first class functions, incredibly dynamic behavior&#8230;it&#8217;s a joy when you know it well. Less experienced JS programmers often feel as though they&#8217;re waltzing in a minefield, though. At many steps along the path to JS enlightenment everything feels like it&#8217;s breaking down around you. The lack of block [...]]]></description>
				<content:encoded><![CDATA[<p>JavaScript is a lovable language. Real closures, first class functions, incredibly dynamic behavior&#8230;it&#8217;s a joy when you know it well.</p>
<p>Less experienced JS programmers often feel as though they&#8217;re waltzing in a minefield, though. At many steps along the path to JS enlightenment everything feels like it&#8217;s breaking down around you. The lack of block lexical scope sends you on pointless errands, the various OO patterns give you fits as you try to do anything but what&#8217;s in the examples, and before you know it even the trusty &#8220;dot&#8221; operator starts looking suspect. What do you <em>mean</em> that <code>this</code> doesn&#8217;t point to the object I got the function from?</p>
<p>Repairs for some of the others are on the way in ES6 so I want to focus on the badly  botched situation regarding &#8220;promiscuous <code>this</code>&#8220;, in particular how ES5 has done us few favors and why we&#8217;re slated to continue the cavalcade of failure should parts of the language sprout auto-binding.</p>
<p>Here&#8217;s the problem in 5 lines:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  _counter<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
  inc<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._counter<span style="color: #339933;">++;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
node.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> obj.<span style="color: #660066;">inc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>See the issue? <code>obj.inc</code> results in a reference to the <code>inc</code> method <em>without</em> any handle or reference to its original context (<code>obj</code>). This is asymmetric with the behavior we see when we directly call methods since in that case the dot operator populates the <code>ThisBinding</code> scope. We can see it clearly when we assign to intermediate variables:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> _counter <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// global &quot;_counter&quot;, we'll see why later</span>
<span style="color: #000066; font-weight: bold;">var</span> inc <span style="color: #339933;">=</span> obj.<span style="color: #660066;">inc</span><span style="color: #339933;">;</span>
obj.<span style="color: #660066;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 1</span>
obj.<span style="color: #660066;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 2</span>
inc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 1</span></pre></td></tr></table></div>

<p>Reams have been written on the topic, and ES5&#8242;s belated and weak answer is to directly transcribe what JS libraries have been doing by providing a <code>bind()</code> method that returns <em>a new function object</em> that carries the correct <code>ThisBinding</code>. Notably, you can&#8217;t un-bind a bound function object, nor can you treat a bound function as equal to its unbound ancestor. This, then, is just an API formalism around the pattern of using closures to carry the <code>ThisBinding</code> object around:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> bind <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>obj<span style="color: #339933;">,</span> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000066; font-weight: bold;">return</span> obj<span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>obj<span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Event handling now looks like:</span>
<span style="color: #006600; font-style: italic;">//   node.addEventListener(&quot;click&quot;, bind(obj, &quot;inc&quot;));</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">var</span> inc <span style="color: #339933;">=</span> bind<span style="color: #009900;">&#40;</span>obj<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;inc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
obj.<span style="color: #660066;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 1</span>
obj.<span style="color: #660066;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 2</span>
inc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 3</span>
&nbsp;
inc <span style="color: #339933;">===</span> obj.<span style="color: #660066;">inc</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// false</span></pre></td></tr></table></div>

<p>ES5&#8242;s syntax is little better but it is built-in and can potentially perform much better:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> inc <span style="color: #339933;">=</span> obj.<span style="color: #660066;">inc</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// In a handler:</span>
node.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> obj.<span style="color: #660066;">inc</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Syntax aside, we didn&#8217;t actually solve the big problems since unbound functions <em><b>can still exist</b></em>, meaning we still have to explain to developers that they need to think of the dot operator doing different things based on what charachters happen to come <em>after</em> the thing on the right-hand side of the dot. Worse, when you get a function it can either be strongly-bound (i.e., it breaks the <code>.call(otherThis, ...)</code> convention) or unbound &#8212; potentially executing in the &#8220;wrong&#8221; <code>ThisBinding</code>. And there&#8217;s no way to tell which is which.</p>
<p>So what would be better?</p>
<p>It occurs to me that what we need isn&#8217;t automatic binding for some methods, syntax for easier binding, or even automatic binding for all methods. No, what we really want is <em>weak binding</em>; the ability to retrieve a function object through the dot operator and have it do the right thing <em>until you say otherwise</em>.</p>
<p>We can think of weak binding as adding an annotation about the source object to a reference. Each de-reference via [[Get]] creates a new weak binding which is then used when a function is called. This has the side effect of describing current [[Get]] behavior when calling methods (since the de-reference would carry the binding and execution can be described separately). As a bonus, this gives us the re-bindability that JS seems to imply should be possible thanks to the <code>.call(otherThis)</code> contract:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> o <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  log<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">msg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  msg<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;hello, world!&quot;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">var</span> o2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  msg<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;howdy, pardner!&quot;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
o.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// &quot;hello, world!&quot;</span>
o2.<span style="color: #660066;">log</span> <span style="color: #339933;">=</span> o.<span style="color: #660066;">log</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// calling log through o2 replaces weak binding</span>
o2.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// &quot;howdy, pardner!&quot;</span></pre></td></tr></table></div>

<p>But won&#8217;t this break the entire interwebs!?!?</p>
<p>Maybe not. Hear me out.</p>
<p>We&#8217;ve already seen our pathological case in earlier examples. Here&#8217;s the node listener use-case again, this time showing us exactly what context is being used for unbound methods:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">body</span>.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span> <span style="color: #339933;">==</span> document.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// true in Chrome and FF today</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We can think of dispatch of the event calling the anonymous function with explicit <code>ThisBinding</code>, using something like <code>listener.call(document.body, evt);</code> as the call signature for each registered handler in the capture phase. Now, it&#8217;s pretty clear that this is whack. DOM dispatch changing the <code>ThisBinding</code> of passed listeners is an incredibly strange side-effect and means that even if we add weak binding, this context doesn&#8217;t change. At this point though we can clearly talk about the DOM API bug in the context of sane, consistent language behavior. The fact that event listeners won&#8217;t preserve weak binding and will continue to require something like this is an issue that can be wrestled down in <em>one</em> working group:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">node.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> 
       <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>otherThis<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
       <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The only case I can think of when weak bindings will change program semantics is when unbound method calls in the global object do work on <code>this</code> in a way that is intentional. We have this contrived example from before too, but as you can see, it sure looks like a bug, no?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> _counter <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// a.k.a.: &quot;this._counter&quot;, a.k.a.: &quot;window._counter&quot;</span>
<span style="color: #000066; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  _counter<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
  inc<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._counter<span style="color: #339933;">++;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">var</span> inc <span style="color: #339933;">=</span> obj.<span style="color: #660066;">inc</span><span style="color: #339933;">;</span>
obj.<span style="color: #660066;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 1</span>
obj.<span style="color: #660066;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 2</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>obj._counter<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>._counter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 2, 0</span>
inc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 1</span>
inc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 2</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>obj._counter<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>._counter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 2, 2</span></pre></td></tr></table></div>

<p>If this turns out to be a problem in real code, we can just hide weak bindings behind some <code>use</code> directive.</p>
<p>Weak binding now gives us a middle ground: functions that are passed to non-pathological callback systems &#8220;do the right thing&#8221;, most functions that would otherwise need to have been bound explicitly can Just Work (and can be rebound to boot), and the wonky [[Get]] vs. [[Call]] behavior of the dot operator is resolved in a tidy way. One less bit of unexploded ordinance removed.</p>
<p>So the question now is: why won&#8217;t this work? TC39 members, what&#8217;s to keep us from doing this in ES6?</p>
<p><b>Update:</b> Mark Miller flags what looks to be a critical flaw:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  callbacks<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  register<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>func<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> i <span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">callbacks</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">callbacks</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
obj.<span style="color: #660066;">register</span><span style="color: #009900;">&#40;</span>foo.<span style="color: #660066;">bar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Does the wrong thing!</span></pre></td></tr></table></div>

<p>The problem here is our call into each of the callback functions which still execute in the scope of the wrong object. This means that legacy code still does what it always did, but that&#8217;s just as broken as it was. We&#8217;d still need new syntax to make things safe. Ugg.</pre>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2010/09/javascript-uxo-removal/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ending The ga.js Wait</title>
		<link>http://infrequently.org/2009/04/ending-the-gajs-wait/</link>
		<comments>http://infrequently.org/2009/04/ending-the-gajs-wait/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 04:10:16 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=908</guid>
		<description><![CDATA[Google Analytics is ubiquitous, not least of all because it&#8217;s better at what it does than most of the alternatives. Also, it doesn&#8217;t require any install or maintenance. And it&#8217;s free. What&#8217;s not to like? Frankly, not much, but if I had to nit pick, I&#8217;d note that the worst part of Google Analytics is [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.google.com/analytics/">Google Analytics</a> is ubiquitous, not least of all because it&#8217;s better at what it does than most of the alternatives. Also, it doesn&#8217;t require any install or maintenance. And it&#8217;s free. What&#8217;s not to like?</p>
<p>Frankly, not much, but if I had to nit pick, I&#8217;d note that the worst part of Google Analytics is the <a href="http://www.google-analytics.com/ga.js"><code>ga.js</code></a> script that does the actual tracking of content. It&#8217;s not bad, in and of itself, but it tends to load slowly. There are several reasons for this:</p>
<ul>
<li><b>Another DNS lookup to resolve <code>http://www.google-analytics.com/</code></b>. This DNS entry is likely to be &#8220;warm&#8221; given how frequently <code>ga.js</code> is used on the web, but as <a href="http://blog.chromium.org/2008/09/dns-prefetching-or-pre-resolving.html">Jim Roskind explained on the Chromium blog</a>, it&#8217;s the outliers that kill you.</li>
<li><b>It&#8217;s kinda big</b>. At 9K on the wire (22K unzipped), <code>ga.js</code> is kinda chunky for what it does most of the time, namely tracking a single page load.</li>
<li><b>The <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingOverview.html">default instructions</a> are bone-headed</b>. They direct you to do a <code>document.write()</code> which is a blocking, synchronous operation WRT page loading. This is tres <a href="http://raibledesigns.com/rd/entry/oscon_2008_even_faster_web">dumb</a>. Reasonable people should just include <code>ga.js</code> with a <code>&lt;script&gt;</code> tag, but nearly nobody does. Turns out that sane defaults still matter.</li>
<li><b>Load times seem totally random.</b> As with DNS lookup, <code>ga.js</code>&#8216;s latency varies wildly. This isn&#8217;t backed up by anything empirical, but many pages feel blocked by <code>ga.js</code> for a near eternity.</li>
</ul>
<p>So how to fix this? Dojo 1.3&#8242;s <code>dojox.analytics.Urchin</code> to the rescue!  Given that I was going to be including Dojo on the page to do other things anyway, I can use 1.3&#8242;s new Urchin system to help amortize the cost of using Google Analytics. The code running on this blog now includes the following code (more or less):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;
  src=&quot;http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js&quot;&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
  dojo.addOnLoad(function(){
    setTimeout(function(){
      dojo.require(&quot;dojox.analytics.Urchin&quot;);
      dojo.addOnLoad(function(){
        var tracker = new dojox.analytics.Urchin({
          acct: &quot;UA-XXXXXX-X&quot; // your tracking # here
        });
      });
    }, 100);
  });
&lt;/script&gt;</pre></td></tr></table></div>

<p>You can see the real thing by looking at the bottom of this page which pulls in <a href="http://alex.dojotoolkit.org/wp-content/themes/sandbox/custom.js">custom.js</a> which includes this logic. <a href="http://higginsforpresident.net/2008/06/google-analytics-after-onload/">Pete Higgins blogged about how the module works when he first wrote it</a>, and the strategy is to load Dojo from a CDN (since the page wanted it for other things) and wait until after the page has loaded to include <code>ga.js</code>. This delayed loading ensures that the page is responsive before we start doing anything related to tracking. The nested calls to <code>dojo.addOnLoad</code> show how we can wait for one set of modules to finish before kicking off another group, and in this case we also wait until after the page is responsive to load <code>dojox.analytics.Urchin</code>. This module further delays loading of <code>ga.js</code>, meaning that it doesn&#8217;t matter how long it takes for things like DNS to resolve and for Google to serve <code>ga.ja</code> since it&#8217;s not ever blocking the user.</p>
<p>Looking at the &#8220;before&#8221; and &#8220;after&#8221; shots in firebug gives you some idea of how this technique can really make a difference:</p>
<div style="padding-left: 50px; font-style: italic;">
<div id="attachment_940" class="wp-caption aligncenter" style="width: 310px"><a href="http://alex.dojotoolkit.org/wp-content/uploads/2009/04/before_loading_detail.png"><img src="http://alex.dojotoolkit.org/wp-content/uploads/2009/04/before_loading_detail-300x103.png" alt="onload waits for ga.js" title="before_loading_detail" width="300" height="103" class="size-medium wp-image-940" /></a><p class="wp-caption-text">onload waits for ga.js</p></div></p>
<p><div id="attachment_941" class="wp-caption aligncenter" style="width: 310px"><a href="http://alex.dojotoolkit.org/wp-content/uploads/2009/04/loading_detail.png"><img src="http://alex.dojotoolkit.org/wp-content/uploads/2009/04/loading_detail-300x102.png" alt="using dojox.analytics.Urchin, we can get a responsive page and *then* track usage" title="loading_detail" width="300" height="102" class="size-medium wp-image-941" /></a><p class="wp-caption-text">using dojox.analytics.Urchin, we can get a responsive page and *then* track usage</p></div>
</div>
<p>We get page tracking and the user gets an interactive page faster. Rad.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2009/04/ending-the-gajs-wait/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Census 2: More Than Just A Pretty Graph</title>
		<link>http://infrequently.org/2008/12/census-2-more-than-just-a-pretty-graph/</link>
		<comments>http://infrequently.org/2008/12/census-2-more-than-just-a-pretty-graph/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 15:59:07 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[community]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=849</guid>
		<description><![CDATA[Numbers without context are lies waiting to be repeated.]]></description>
				<content:encoded><![CDATA[<p>Benchmarks are hard, particularly for complex systems. As a result, the most hotly contested benchmarks tend not to be representative of what makes systems faster for real users. Does another 10% on <a href="http://www.tpc.org/default.asp">TPC</a> really matter to most web developers? And should we really pay any attention to how <em>any</em> JS VM does on <a href="http://shootout.alioth.debian.org/">synthetic language benchmarks</a>?</p>
<p>Maybe.</p>
<p>These things matter only in regards to how well they represent end-user workloads and how trustworthy their findings are. The first is much harder than the second, and end-to-end benchmarking is pretty much the only way to get there. As a result, sites like <a href="http://www.tomshardware.com/">Tom&#8217;s Hardware</a> focus on application-level benchmarks while still publishing &#8220;low level&#8221; numbers. Venerable test suites like <a href="http://en.wikipedia.org/wiki/SPECint">SPECint</a> have even moved toward running &#8220;full stack&#8221; style benchmarks which may emphasize a particular workload but are broad enough to capture the wider system effects which matter in the real world.</p>
<p>Marketing departments also like small, easily digestible, whole numbers. Saying something like &#8220;200% Faster!&#8221; sure sounds a lot better than &#8220;on a particular test which is part of a larger suite of tests, our system ran in X time vs. Y time for the competitor&#8221;. Both may be true, but the second statement gives you some context. Preferably even that statement would occur above an actual table of numbers or graphs. Numbers without context are lies waiting to be repeated.</p>
<p>With all of this said, <a href="http://www.jamesward.com/blog/">James Ward&#8217;s</a> <a href="http://jamesward.com/census">Census</a> benchmark makes a valiant stab at a full-stack test of data loading and rendering performance for RIA technologies. Last month <a href="http://dojotoolkit.org/2008/11/05/flash-flex-versus-open-web-ajax">Jared</a> dug further into the numbers and found the methodology wanting, but given some IP issues couldn&#8217;t patch the sources himself. Since I wasn&#8217;t encumbered in the same way I thought I might as well try my hand at it, but after hours of attempting to get the <a href="http://sourceforge.net/projects/flexapps">sources to build</a>, I finally gave up and decided to re-write the tests. The result is <a href="http://textterm.com/census.html">Census 2</a>.</p>
<p><a href="http://textterm.com/census.html"><img src="http://alex.dojotoolkit.org/wp-content/uploads/2008/12/census2_main_small.png" style="border: 0px;"/></a></p>
<p>There are several goals of this re-write:</p>
<ul>
<li><b>Fairness.</b> Tests need to be run multiple times for them to be representative in any way. Likewise, systems not being directly tested need to be factored out as much as possible. C2 does this by reducing the number of dependencies and running tests (at least) 5 times and discarding outliers before reporting an average. I&#8217;ve also worked to make sure that the tests put the best foot forward for all of the tested technologies.</li>
<li><b>Hackability.</b> Benchmarks like Census serve first as a way for decision makers to understand options but second as a way for developers to know how they&#8217;re doing. Making it trivial to add tests helps both audiences.</li>
<li><b>Portability.</b> The test suite should run nearly everywhere with a minimum of setup and fuss. This ensures that the largest numbers of people can benefit from the fairness and hackability of the tests.</li>
</ul>
<p>The results so far have been instructive. On smaller data sets HTML wins hands-down for time-to-render, even despite its disadvantage in over-the-wire size. For massive data sets, pagination saves even the most feature-packed of RIA Grids, allowing the Dojo Grid to best even XSLT and a more compact JSON syntax. Of similar interest is the delta between page cycle times on modern browsers vs their predecessors. Flex can have a relatively even performance curve over host browsers, but the difference between browsers today is simply stunning.</p>
<p>Given the lack of an out-of-the-box paginating data store for Flex, RIAs built on that stack seem beholden to either Adobe&#8217;s <a href="http://www.adobe.com/products/livecycle/dataservices/">LCDS licensing</a> or are left to build ad-hoc pagination into apps by hand to get reasonable performance for data-rich business applications. James Ward has already exchanged some mail with me on this topic and it&#8217;s my hope that we can show how to do pagination in Flex without needing LCDS in the near future. </p>
<p>The tests aren&#8217;t complete. There&#8217;s still work to do to get some of the SOAP and AMF tests working again. If you have ideas about how to get this done w/o introducing a gigantic harball of a Java toolchain, I&#8217;m all ears. Also on the TODO list is an <a href="http://code.google.com/appengine/">AppEngine app</a> for recording and analyzing test runs so that we can say something interesting about performance on various browsers. </p>
<p>Census 2 is very much <a href="http://code.google.com/p/census2/">an open source project</a> and so if you&#8217;d like to get your library or technology tested, please don&#8217;t hesitate to send me mail or, better yet, attach patches to the <a href="http://code.google.com/p/census2/issues/list">Bug Tracker</a>.</p>
<p><b>Update:</b> I failed to mention earlier that one of the largest changes in C2 vs. Census is that we report <em>full page cycle times</em>. Instead of reporting just the &#8220;internal&#8221; timings of an RIA which has been fully boostrapped, the full page times report the full time from page loading to when the output is responsive to user action. This keeps JavaScript frameworks (or even Flex) from omitting from the reports the price that users pay to download their (often sizable) infrastructure. There&#8217;s more work to do in reporting overall sizes and times (&#8220;bandwidth&#8221; numbers don&#8217;t report gzipped sizes, e.g.), but if you want the skinny on real performance, scroll down to the red bars. That&#8217;s where the action is.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2008/12/census-2-more-than-just-a-pretty-graph/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Why Are We Even Having This Discussion?</title>
		<link>http://infrequently.org/2008/10/why-are-we-even-having-this-discussion/</link>
		<comments>http://infrequently.org/2008/10/why-are-we-even-having-this-discussion/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 21:47:43 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[blog chatter]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[acorn]]></category>
		<category><![CDATA[policy]]></category>
		<category><![CDATA[rights]]></category>
		<category><![CDATA[voting]]></category>

		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=807</guid>
		<description><![CDATA[Content after the jump due to the public policy nature of the post. Here we go again. Every four years we go into the partisan spasms of a heat-not-light [dis]enfranchisement &#8220;debate&#8221;. What&#8217;s perpetually lost is any coherent discussion of the causes of the debate. As with gerrymandering, the causes are structural and neither party feels [...]]]></description>
				<content:encoded><![CDATA[<p>Content after the jump due to the public policy nature of the post.</p>
<p><span id="more-807"></span></p>
<p><a href="http://www.nytimes.com/2008/10/17/opinion/17fri1.html?_r=1&#038;ref=opinion&#038;oref=slogin">Here we go again.</a></p>
<p>Every four years we go into the partisan spasms of a heat-not-light [dis]enfranchisement &#8220;debate&#8221;. What&#8217;s perpetually lost is any coherent discussion of the causes of the debate. As with <a href="http://en.wikipedia.org/wiki/Gerrymandering">gerrymandering</a>, the causes are structural and neither party feels it would serve them to effectively deal with the situation at it&#8217;s roots. Not because solving the problem wouldn&#8217;t be better for everyone (in both cases, it objectively would), but because <em>it would change the game, and our 2-party system is nothing if not over-specialized to the current rules of the game</em>. In this sense, both redistricting reform (killing gerrymandering dead) and automatic voter registration systems cause the old rules to lose their hold, instantly changing the calculus of holding on to power. Automatic registration via so-called &#8220;motor-voter&#8221; laws, registration with passport applications, automatic updates with change-of-address on US mail, and other sensible policies are opposed by partisans of <em>both</em> parties because they have the potential to allow discontent to cause large swings in electorate behavior. Today, between the systematic disenfranchisement caused by requiring citizens to register to vote and the effective gerrymandering-based dampening of popular will, <em>enormous</em> changes in <em>likely voter</em> feelings about the direction of the country (or, less often, a locality/district) are required to break an incumbent&#8217;s grip on power. As an example, the <a href="http://www.pollingreport.com/right.htm">&#8220;right-track/wrong-track&#8221; polling numbers</a> in 2006 said that nearly 70% of Americans thought the country was on the wrong track. That feeling swept the Democrats into a razor-thin congressional majority (which the Republicans have been filibustering to death ever since), but in a 2:1 year, wouldn&#8217;t you expect a similar landslide in Congress? Perhaps not in the Senate where fewer seats are up for a vote as a structural hedge against change, but certainly we should have collectively turned enough of the bums out to make the remaining ones fear for their jobs. As it happened, in a race with 33 seats up for discussion (15 held by Republicans), <em><a href="http://en.wikipedia.org/wiki/United_States_Senate_elections,_2006">only 5 of the bums lost their seats</a></em>. Now compare that to the most recent pre-Bush period of comparable &#8220;right-track/wrong-track&#8221; numbers: the Republican revolution&#8221; of &#8217;94. <a href="http://en.wikipedia.org/wiki/United_States_Senate_elections,_1994">On that basis it becomes evident that a shift in power half-again as large &ndash; based on the same &#8220;market fundamentals&#8221; &ndash; was <em>at least</em> justified</a>. 8 seats changed hands in &#8217;94 vs. 5 in &#8217;06. The difference? A census and therefore a chance for many states to gerry&#8230;.er&#8230;redistrict. The calcifying power of&#8230;um&#8230;power worked its magic 2 years ago and the Senate is deadlocked as a result.</p>
<p>All of these effects cause fewer parts of the country to be competitive. If you support competition in markets (as I do), then there&#8217;s no higher calling than supporting a competitive marketplace for ideas, and both parties are doing their best to stifle the pricing function of our public policy market. No wonder then that Republicans think they can steal (or at least dispute) an election by challenging voters in Ohio, despite <a href="http://www.talkingpointsmemo.com/archives/237825.php">many discredited attempts in the past to find large-scale vote fraud</a>. Eight years of intense Republican scrutiny into the non-issue has utterly failed to turn up any massive conspiracy or even credible small-scale fraud. Remember, pressuring US AG&#8217;s to prosecute thin or non-existent voter fraud cases &ndash; then firing them when they couldn&#8217;t find any and/or wouldn&#8217;t make them up &ndash; is what got Alberto Gonzalez hauled before congress for months on end, eventually leading to his disgraced resignation and continuing questions as to the impartiality of the DOJ. This isn&#8217;t a winner of an issue for the GOP, but it sure is an effective way to try to keep the under-informed from coming to the polls and having their votes counted. And they know it. Scare-tactics and fear-mongering as [keep|get]-out-the-vote strategy. Democrats, naturally, feel that their on-the-ground vote registration in targeted areas can be an effective weapon in distorting the outcome.</p>
<p>Either way, it&#8217;s shameful.</p>
<p>The Democratic approach is perhaps less reprehensible since the folks who are registered can vote however they please, but there&#8217;s no denying the attempt at demographic distortion. But why should citizens need to register as a separate process from establishing residency, getting mail, or a driver&#8217;s license anyway? And why isn&#8217;t <a href="http://en.wikipedia.org/wiki/Election_Day_Registration">same-day registration</a> the law of the land? If Wyoming can do it, why not New York and California? </p>
<p>Fundamentally, all the objections to broad enfranchisement end in a large-scale IT problem&#8230;but not a particularly hard one. What I&#8217;m not hearing from nearly anyone is a recognition that this shouldn&#8217;t be a debate that happens in a functioning democracy. That we have it on a quadrennial basis is simply an embarrassing acknowledgment that our democracy is <em>not</em> functioning.</p>
<p>If McCain really wants to put &#8220;country first&#8221; and be a maverick, he&#8217;d be bringing this up as an urgent topic of national debate. It would certainly be better than the sleazy <a href="http://tpmelectioncentral.talkingpointsmemo.com/2008/10/did_mccain_hire_same_firm_to_d.php">robo-call effort</a> his campaign is now investing in. And if Obama wanted to build real credibility with Americans about his willingness to effect real change, shouldn&#8217;t he start here? Certainly it&#8217;s a better use of the national discourse than <a href="http://www.nytimes.com/2008/10/17/us/politics/17webplumber.html?ref=politics">helping McCain draw unwarranted (and likely un-wanted) attention to a plumber.</a> And where the hell is the 4th Estate when we need them?</p>
<p>Oh, right. Camped out on some plumber&#8217;s lawn.</p>
<p>Luckily, I happen to live in California where the Governor (who I disagree with more than not) <a href="http://www.voterguide.sos.ca.gov/title-sum/prop11-title-sum.htm">has put redistricting reform on the ballot in the form of Prop. 11</a>. I&#8217;ll be voting &#8220;yes&#8221; on 11, if only to make it that less likely that 4 years from now we&#8217;ll have to have this &#8220;discussion&#8221; again.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2008/10/why-are-we-even-having-this-discussion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;Action Oriented Programming&#8221;</title>
		<link>http://infrequently.org/2008/10/action-oriented-programming/</link>
		<comments>http://infrequently.org/2008/10/action-oriented-programming/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 16:40:13 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[closures]]></category>

		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=783</guid>
		<description><![CDATA[It&#8217;s good to be back in SF after a pretty hectic week in Boston for Dojo Developer Days and The Ajax Experience. There&#8217;s a lot to say about them, which hopefully I&#8217;ll get to in a longer post. Our first DDD event under Pete&#8216;s excellent leadership was a success and Dojo and SitePen very well [...]]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s good to be back in SF after a pretty hectic week in Boston for Dojo Developer Days and The Ajax Experience. There&#8217;s a lot to say about them, which hopefully I&#8217;ll get to in a longer post. Our first DDD event under <a href="http://higginsforpresident.net/">Pete</a>&#8216;s excellent leadership was a success and Dojo and SitePen very well represented at the conference.</p>
<p>While in Boston, <a href="http://blog.xdraw.org/">Gavin</a> and <a href="http://www.eyelevelpasadena.com/">Jill</a>  joined a gaggle of Dojo hackers at a dinner ostensibly to mourn my birthday (thanks to Dylan and Pete for organizing!) and in the course of conversation Jill asked something along the lines of:</p>
<blockquote><p>
So why do people get so excited about closures?
</p></blockquote>
<p>Which prompted a several of us to flail and flop gasping the salt flats of analogy like fish out of polite-conversation water. After about 10 minutes of this, Jill succinctly summed it all up in the form of a question:</p>
<blockquote><p>
Oh, so it&#8217;s like &#8220;action-oriented programming&#8221;?
</p></blockquote>
<p>This is perhaps the most insightful and succinct description I have ever heard of what JavaScript is all about.</p>
<p><b>Update:</b> <a href="http://tharpo.com">Jennifer</a> just played <a href="http://blogs.wnyc.org/radiolab/2008/07/29/tell-me-a-story/">this for me</a> and it gets right to the heart of this post: the important part of doing what we do with computers, and more importantly, with the web, is to give the power of Computer Science to real people&#8230;and it starts with insights like Jill&#8217;s that build a shared way of thinking and talking about the world. It makes me sad that many programmers miss that, but when non-programmers can share in the beauty and power of code, it does a lot to make it all seem worthwhile.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2008/10/action-oriented-programming/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Importance Of Chrome</title>
		<link>http://infrequently.org/2008/09/the-importance-of-chrome/</link>
		<comments>http://infrequently.org/2008/09/the-importance-of-chrome/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 23:28:44 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[dhtml]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[openweb]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[strategy]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=747</guid>
		<description><![CDATA[The rumors seem to have been true&#8230;the gBrowser is real. And it looks like it will simply be awesome. To my friends who have been toiling on it in deep secrecy for so very long, congratulations. Yes, yes, more to do, blah blah&#8230;screw that. You shipped! Huzzah! So what does Chrome mean for those of [...]]]></description>
				<content:encoded><![CDATA[<p>The rumors seem to have been true&#8230;<a href="http://googleblog.blogspot.com/2008/09/fresh-take-on-browser.html">the gBrowser is real</a>. And it looks like it will simply be awesome. To my friends who have been toiling on it in deep secrecy for so very long, congratulations. Yes, yes, more to do, blah blah&#8230;screw that. You shipped! Huzzah!</p>
<p>So what does Chrome mean for those of us who aren&#8217;t breaking out the champagne? Well, first, it&#8217;s the second sign (after <a href="http://gears.google.com/">Gears</a> and YBP (<a href="http://alex.dojotoolkit.org/2008/06/gears-de-brands-2/">har!</a>)) that the content authors are taking back the web from the &#8220;browser guys&#8221;. I&#8217;ve been fascinated for the last 6 months or so by the strategic mis-alignment which results when both the browsing and authoring experience in the hands of organizations only care about one but not the other. Mozilla gets paid by search-box revenue and users download it because it&#8217;s better for browsing, therefore Mozilla is incented to <a href="http://www.adaptivepath.com/aurora/">build new ways to browse</a>, but their investments in content are somewhat mis-aligned (and, frankly, <a href="http://labs.mozilla.com/">it shows</a>). Google and Yahoo, on the other hand, are critically dependent on the content getting better, so they produce plugins to augment HTML in un-intrusive ways. Chrome crosses over into the browser business <em>from the perspective of content</em>, and it also shows, albeit in a good-ish way. I guess we&#8217;ll need to wait and see how browsing-oriented Chrome gets (e.g., will it sprout an extensions platform &ndash; ala Firefox &ndash; or will the propsect of an ad-blocking plugin for the Google browser make that proposal D.O.A.?).</p>
<p>Regardless of how Chrome evolves as a product, the important question now is: how will it be distributed? The obviously non-evil thing to do is to say &#8220;look, it&#8217;s great, it&#8217;s free&#8221; and hope that the world discovers it on its own thanks to word-of-mouth and/or leverage of the Google brand. Given that Chrome delivers new awesome things which are end-user-visible (some &#8220;end-user-awesome&#8221;, if you will), there&#8217;s some real chance that Chrome can get to roughly Firefox level market-share without breaking too much of a sweat. Not that Firefox&#8217;s market share is anything to really covet, given that MoFo/MoCo have been toiling at it for a decade now. To get real, honest-to-god leverage out of this process, Chrome is going to need something like 60+% market share, and that means changing ingrained user habits. I put the probability of that happening without distribution channel love at roughly bupkis.</p>
<p>Microsoft killed Netscape by bundling the browser with the OS. Apple is <a href="http://marketshare.hitslink.com/report.aspx?sample=15&#038;qprid=22&#038;qpdt=1&#038;qpct=5&#038;qptimeframe=M&#038;qpsp=101&#038;qpnp=12&#038;qprid2=3&#038;qpcustom2=Firefox+3.0">making inroads by bundling</a>. Firefox is even <a href="http://marketshare.hitslink.com/report.aspx?sample=15&#038;qprid=22&#038;qpdt=1&#038;qpct=5&#038;qptimeframe=M&#038;qpsp=101&#038;qpnp=12&#038;qprid2=3&#038;qpcustom2=Firefox+3.0#">getting aggressive</a>. So where does this leave &#8220;don&#8217;t be evil&#8221;? Given the <a href="http://weblogs.java.net/blog/kgh/archive/2005/10/java_se_and_the.html">toolbar promotional deals</a> which Google has cut in the past, I think there&#8217;s some organizational capacity inside the Goog to use the distribution channels they&#8217;ve already created as a way of getting to critical mass. What I don&#8217;t see, though, is a view of how to bring the mission of Gears into alignment with Chrome (or vice versa). They&#8217;re both important, but Chrome is a long-term bet while Gears is the near-future solution. They are not in opposition, but their strategies for gaining leverage over the problems facing content authors are very different.</p>
<p>We need what Gears can offer to every browser <em>right now</em> while Chrome dukes it out for market share on the browsing experience merits. Hopefully, if nothing else, the Chrome installer will add Gears to other browsers on the system that users install Chrome to. Even if they don&#8217;t pick the googly experience for browsing day-to-day, perhaps Chrome can still serve to give new tools to the content-author side of the house. Other browser vendors won&#8217;t do such a thing since they win or loose on an exclusive &#8220;I must replace the other guy&#8221; basis. Here, Google (and by &#8220;Google&#8221;, I mean &#8220;the open web&#8221;) wins either way. Hopefully Google&#8217;s interest in making the content experience better trumps the &#8220;we&#8217;re all browser guys now&#8221; instinct in this case.</p>
<p>We&#8217;ll find out tomorrow, I guess. Here&#8217;s to hoping.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2008/09/the-importance-of-chrome/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Harmony Fallout</title>
		<link>http://infrequently.org/2008/08/harmony-fallout/</link>
		<comments>http://infrequently.org/2008/08/harmony-fallout/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 08:33:17 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[openweb]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=731</guid>
		<description><![CDATA[Lets end the silly meme that "Adobe lost" or that "Microsoft won". The game has hardly begun and it won't be settled in a standards body anyway. ]]></description>
				<content:encoded><![CDATA[<p>There&#8217;s a lot of weirdness going on around the Harmony announcement. <a href="http://whydoeseverythingsuck.com/2008/08/ru-roh-adobe-screwed-by-ecmascript.html">This post in particular</a> tries to dig into some of the wrangling that caused the ES4/3.1 split and what the Oslo resolution &#8220;means&#8221;, but I&#8217;m afraid that much of the analysis is being done without the benefit of an inside view of the WG process.</p>
<p>At the risk of talking too much out of school, I want to set the record straight in some ways. First, let me set some facts out:</p>
<ul>
<li>ES4, <a href="http://www.ecmascript.org/es4/spec/overview.pdf">as outlined last fall</a>, was <b>not</b> ActionScript 3. <em>Major</em> changes to the semantics of Adobe&#8217;s initial contribution ensured that any truly compliant ES4 implementation from Adobe would have required many concessions, including the inclusion of a client-side compiler. ES4 without <code>eval()</code> (ala AS3) would never have cut it as a &#8220;real&#8221; ES4.</li>
<li>Adobe had not donated &#8220;ActionScript 3&#8243; to Mozilla nor Open Sourced ActionScript 3. Adobe had donated a high-performance byte-code VM which a separate front-end compiler targeted. It is absolutely possible that the Tamarin VM can and will run <em>whatever</em> syntax for the next version of JavaScript is ratified. The design of the VM is, of course, predicated upon the language semantics but lets not confuse the front-end compiler and the language that it consumes with the VM and byte-code format which it executes. The front-end compiler was not donated to Mozilla (although something similar exists in the OSS&#8217;d Flex SDK) nor does it ship inside of the Flash player today. Adobe can continue to evolve their developer languages and byte-code VMs independently so long as they never ship an <code>eval()</code> feature. Even if they do, there are other (harder to swallow) options available, but no road is cut off to Adobe which was not already long-since abandoned in other ways by the ES4 process.</li>
<li>Like Adobe, Microsoft has jumped ahead in the evolution of JavaScript via the seemingly forgotten JScript.NET. Like Adobe, Microsoft has had to come back from that position to meet the web where it really is. Microsoft now ships 3 &ndash; yes, that&#8217;s right, <em>three</em> &ndash; JavaScript-ish languages which are capable of running in a browser:
<ul>
<li>JScript (via Windows Scripting Host)</li>
<li>JScript.NET</li>
<li>JScript for the DLR (via Silverlight)</li>
</ul>
<p>Make no mistake about it, these are all separate implementations which likely share little if any code. The DLR variant is even new in the last several years. Creating a new JavaScript compiler and runtime is not an overly onerous task for MSFT and clearly not one that will take a long time should the occasion arise. What&#8217;s confusing and can likely be tied to strategic wrangling is the puzzling lack of progress in the WSH version of JScript (the one everyone uses day-to-day). Any strategic discussion of JScript as a platform needs to start from this perspective.</li>
<li>Much in ES4 was new. The gradual typing system (which I&#8217;m a big supporter of) was something of a large-scale experiment coupled with as much rigor as I&#8217;ve ever seen in a standards body in proving things out in an RI. The Class system (which I wasn&#8217;t a big supporter of) needed to marry class-based inheritance to prototypal inheritance in ways which were new. ES4 contained many good features and syntactic forms which were borrowed from other places, but as Brendan Eich has said, it was a process of synthesis plus invention. In my opinion, much of the failure of ES4 as an initiative can be traced to significant failings of ActionScript 3 <em>as a language</em>. AS3 is a Java-like language with a Java-like execution model. JavaScript is a dynamic language with a dynamic execution model. The gulf in expectations between those camps turns up in every corner of the language design. For instance: what does it mean to load new code? Are classes forever &#8220;closed&#8221; or can they be re-opened? Do you <em>really</em> need the <code>static</code> and <code>final</code> keywords? Solving these issues in the context of the old is easy. In the context of the new, it&#8217;s hard. ES4 suffered because it had to do it in a new world which no one was yet writing code for.</li>
</ul>
<p>So, lets pop up and talk about strategy for a minute. Fundamentally, very little has changed in terms of available strategic options for any of the players:</p>
<ul>
<li>MSFT can still hold the web hostage to their ailing WSH VM by continuing to ignore its performance, regardless of bug fixes and syntactic updates. Doesn&#8217;t matter if it&#8217;s amputation or debilitating arthritis, crippled is crippled. For what it&#8217;s worth, my interactions with the MSFT reps on TC39 give me no reason to believe that they won&#8217;t be improving their VM.</li>
<li>Adobe can still chose to implement a language which implements an ECMA spec. They can do this any time they damn-well please. It may not align so cleanly with their current technology roadmap, but it&#8217;s absolutely feasible and when Mozilla ships a &#8220;regular JavaScript&#8221; front-end to the Tamarin back-end, it&#8217;ll be even easier. Note that this plan can be done in parallel with AS3 evolution since Tamarin (as a VM) need not be aware of any language semantics on its own.</li>
<li>Browser vendors can still wring large speedups out of ES3 and 3.1</li>
</ul>
<p>What died here wasn&#8217;t Adobe&#8217;s attempts to &#8220;own&#8221; a spec. If there were such hopes in play, they had been quietly put down one rational, backwards compatible decision after another in the year preceding the Oslo meeting. What died was an assumption that the web can evolve without implementations being out in front of the spec. AS3 was one implementation of a JavaScript-like language that might have been a contender for crown of &#8220;the next one&#8221;, but so was JScript.NET. That neither of them &#8220;won&#8221; simply because they had been built in good faith is as true a sign as I can find that the process is working. <a href="http://blogs.adobe.com/open/2008/08/blog_entry_dated_81408_715_pm.html">Adobe gets it</a>. Lets end the silly meme that &#8220;Adobe lost&#8221; or that &#8220;Microsoft won&#8221;. The game has hardly begun and it won&#8217;t be settled in a standards body anyway. What matters &ndash; and what we all need to keep our eyes keenly trained on &ndash; is what the big implementations do in the way of compatibility, performance, and feature set once ES3.1 arrives.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2008/08/harmony-fallout/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Transition</title>
		<link>http://infrequently.org/2008/08/transition/</link>
		<comments>http://infrequently.org/2008/08/transition/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 21:29:21 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[community]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[Dojo Foundaton]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=713</guid>
		<description><![CDATA[Two days ago I dusted off the rarely-used voting procedure for Dojo Foundation projects in order to kick off a transition that I&#8217;m very excited about: as of this afternoon, the committers of the Dojo project have elected Peter Higgins the new Project Lead for the toolkit project. I&#8217;ve had the pleasure of working with [...]]]></description>
				<content:encoded><![CDATA[<p>Two days ago I <a href="http://turtle.dojotoolkit.org/pipermail/dojo-contributors/2008-August/009571.html">dusted off the rarely-used voting procedure</a> for Dojo Foundation projects in order to kick off a transition that I&#8217;m very excited about: as of this afternoon, the committers of the Dojo project have <a href="http://turtle.dojotoolkit.org/pipermail/dojo-contributors/2008-August/009596.html">elected</a> <a href="http://higginsforpresident.net/">Peter Higgins</a> the new Project Lead for the toolkit project.</p>
<p>I&#8217;ve had the pleasure of working with Peter both in the Dojo project and at <a href="https://www.sitepen.com/">SitePen</a> and his energy and enthusiasm for making Dojo better and helping designers and developers work better together is infectious. </p>
<p>For anyone not familiar with Peter&#8217;s work, he&#8217;s been instrumental in the creation of the amazing <a href="http://dojocampus.org/">Dojo Campus</a> website (along with the <a href="http://blog.uxebu.com/">Uxebu chaps</a>) as well as being primary author of many DojoX components. His work in shepherding new contributors through the contributor to committer process is nearly legendary inside the project, and Peter has been a one-man outreach and support machine via the <a href="http://dojotoolkit.org/blog">Dojo blog</a> and his endless patience on the <a href="http://dojotoolkit.org/forum">forums</a> and IRC (#dojo on irc.freenode.net). I couldn&#8217;t be happier about where Dojo is headed under his direction.</p>
<p>There have already been some recurring questions about this transition amongst the committers and <a href="http://ajaxian.com/archives/open-web-podcast-episode-1-html-5-news-web-workers-w3c-selectors-and-dojo-happenings">on today&#8217;s Open Web podcast</a>, so let me quickly recap them here:</p>
<h3>Q: Will you still be involved in Dojo?</h3>
<p>Absolutely! I&#8217;m excited that Pete is taking on the figurehead and &#8220;vision thing&#8221; duties which is a role that he&#8217;s naturally suited to. Part of this transition is about me wanting more time to focus on experimental and edgy stuff that can make a huge difference in how we work with the web and I have no doubt that Peter is the right guy to help us grow the truly open Dojo community even further. He absolutely gets the importance of a truly open community, the need to be conservative about where IP comes from and meet our promises of backwards-compatibility, and how Dojo can make big changes in the lives of application developers and designers. I&#8217;m grateful to be have the opportunity to continue working with him on Dojo and will continue to do so in whatever capacity Peter deems appropriate.</p>
<h3>Q: Does this change your role at the Foundation?</h3>
<p>Nope. I&#8217;m still serving as President of the Dojo Foundation. This transition will allow me to also focus more time on ensuring that the Foundation is running well, that a new Board is elected soon, and that the Foundation&#8217;s other projects succeed on their own terms. The Foundation has always been about more than just giving Dojo a home, and we&#8217;re now looking to expand the umbrella of the Foundation to help nurture other JavaScript and Open Web projects more than ever.</p>
<h3>Q: Will you still be doing talks on Dojo?</h3>
<p>Yep, I&#8217;ll still be out there advocating the Dojo case, but you can expect to see Peter doing more of that over time as well. If you&#8217;re planning a conference and are looking for a cogent person to talk about Dojo, Peter is now your go-to guy. I&#8217;ve enjoyed having the opportunity to think and <a href="http://alex.dojotoolkit.org/?p=675">talk about where the Open Web is headed</a>, so I&#8217;ll also be doing a lot more of that. There are lots of meta-issues that this transition will let me work harder on, so expect more from me there.</p>
<p>My hat&#8217;s off to the Dojo community and Peter in particular. The work that has gone into 1.2 and will land in 1.3 and beyond under his direction really is changing the way we view what the web can and should be used for.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2008/08/transition/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>OSCON &#8217;08</title>
		<link>http://infrequently.org/2008/07/oscon-08/</link>
		<comments>http://infrequently.org/2008/07/oscon-08/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 01:31:39 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[community]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[licensing]]></category>
		<category><![CDATA[openweb]]></category>

		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=693</guid>
		<description><![CDATA[I&#8217;m leaving tomorrow for my yearly trek to Portland for OSCON. If you&#8217;re going, don&#8217;t hesitate to drop me a line if you want to catch up or RSVP for the Dojo meetup/dinner on Wed evening. Speaking as a member of the OSCON program committee, I&#8217;m very happy about the quality of the talks in [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m leaving tomorrow for my yearly trek to Portland for <a href="http://en.oreilly.com/oscon2008/public/content/home">OSCON</a>. If you&#8217;re going, don&#8217;t hesitate to drop me a line if you want to catch up or <a href="http://dojotoolkit.org/2008/07/17/ddd-4-5-portland-oregon">RSVP for the Dojo meetup/dinner on Wed evening</a>.</p>
<p>Speaking as a member of the OSCON program committee, I&#8217;m <em>very</em> happy about the quality of the talks in the web-ish tracks this year. There&#8217;s even a Dojo talk &ndash; even though for the first time in a long while, I won&#8217;t be giving any talks. The <a href="http://en.oreilly.com/oscon2008/public/schedule/speaker/6606">inimitable Matthew Russell</a>, author of ORA&#8217;s <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2FDojo-Definitive-Guide-Matthew-Russell%2Fdp%2F0596516487%2F&#038;tag=oreonbl-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325">Dojo: TDG</a> will be giving an awesome talk on 2D drawing with Dojo&#8217;s GFX system. I know he&#8217;s got some awesome demos worked up, so I can&#8217;t wait to see the talk. <a href="http://en.oreilly.com/oscon2008/public/schedule/speaker/6580">Gavin Doughtie</a>, occasional contributor to the GFX system, is also giving several talks that you&#8217;ll find me in. Should be a lot of fun.</p>
<p>On a more macro scale, though, I&#8217;ve started to become concerned that &#8220;Open Source&#8221; as a brand has lost its way. Those <a href="http://opensource.org/">who would speak for Open Source</a> have focused narrowly on licensing and have largely ignored the other social processes and artifacts that define what it means to contribute to OSS projects and how those artifacts lead to success or failure of projects, and therefore, of the movement such as it is. There&#8217;s a huge disconnect between what the letter of the Open Source law dictates (the licenses) and the social and process constraints that are required to build high-quality, trustable communities that ensure <a href="http://almaer.com/blog/being-open-is-hard-as-we-have-seen-this-week">100 point</a> OSS products, and many businesses have struck on these differences as a way to use the Open Source brand to imply or insinuate that users should trust their products more than is warranted. OSI&#8217;s failure to address this brand erosion has had some troubling effects in the small JavaScript corner of the OSS world of late, and I know we&#8217;re not alone. OSI has also proven completely impotent in preventing license proliferation, further eroding the Open Source brand. There are, of course, lots of folks who are also concerned about these thing, and so I&#8217;m excited to see <a href="http://en.oreilly.com/oscon2008/public/schedule/detail/4876">David Recordon</a> (of OpenID, etc. fame) giving a talk which looks to talk about some of the community aspects. I tend to blow off &#8220;community&#8221; talks at conferences, but given David&#8217;s use of the phrase &#8220;Open Web&#8221; and his unique perspective, I&#8217;ll be interested to see what he says. I&#8217;ll also be curious to see if and how any of this is discussed at the FLOSSCON meeting of OSS Foundation leaders tomorrow and Sunday.</p>
<p>If you&#8217;ll be in Portland next week, don&#8217;t hesitate to join us for the <code>dojo.dinner()</code> on Wed. I&#8217;m looking forward to seeing everyone again and talking though the issues. Should be a great time.</p>
]]></content:encoded>
			<wfw:commentRss>http://infrequently.org/2008/07/oscon-08/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
