<?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>Brendan Eich</title>
	<atom:link href="http://brendaneich.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://brendaneich.com</link>
	<description></description>
	<lastBuildDate>Sat, 29 Oct 2011 00:33:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JSConf.eu</title>
		<link>http://brendaneich.com/2011/10/jsconf-eu/</link>
		<comments>http://brendaneich.com/2011/10/jsconf-eu/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 00:33:47 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=1660</guid>
		<description><![CDATA[JSConf.eu 2011 was terrific, bigger and juicier than last year, with a strong sense of community felt from reject.js pre-conf: to start: to finish: Chris Williams makes a moving plea for an end to negativity, meaning trolling, flaming, mocking, and hating in online media. This sounds utopian, like &#8220;an end to history&#8221;. But it is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jsconf.eu/2011/">JSConf.eu 2011</a> was terrific, bigger and juicier than last year, with a strong sense of community felt from <a href="http://vimeo.com/29809448">reject.js pre-conf</a>:</p>
<p><iframe src="http://player.vimeo.com/video/29809448?title=0&amp;byline=0&amp;portrait=0" width="480" height="270" frameborder="0" allowFullScreen></iframe></p>
<p>to <a href="http://vimeo.com/29873668?utm_source=javascriptweekly&#038;utm_medium=email">start</a>:</p>
<p><iframe src="http://player.vimeo.com/video/29873668?title=0&amp;byline=0&amp;portrait=0" width="480" height="270" frameborder="0" allowFullScreen></iframe></p>
<p>to <a href="http://jsconf.eu/2011/an_end_to_negativity.html">finish</a>:</p>
<p><iframe src="http://blip.tv/play/hq0Kgtf%2BcAI.html" width="480" height="300" frameborder="0" allowfullscreen></iframe></p>
<p><a href="https://twitter.com/#!/voodootikigod">Chris Williams</a> makes a moving plea for an end to negativity, meaning trolling, flaming, mocking, and hating in online media.</p>
<p>This sounds utopian, like &#8220;an end to history&#8221;. But it is good as an aspiration, a constant reminder, since we&#8217;ve all seen how many people tend to be more negative online than they are in person. This isn&#8217;t just a matter of isolated individual behavior, free of cultural feedback loops. The <a href="http://en.wikipedia.org/wiki/Marshall_McLuhan">new media</a> reinforce <a href="http://en.wikipedia.org/wiki/Global_Village_%28term%29">tribalism</a>.</p>
<p>However, it is hard to be positive about <a href="http://www.toyota.com/itsacar/">some</a> <a href="http://www.toyota.com/itsacar/getchrome/">things</a>. I will persevere&#8230;.</p>
<p>JSConf.eu had too many <a href="https://docs.google.com/spreadsheet/pub?hl=en_US&#038;hl=en_US&#038;key=0AhO5JVicsAJOdDgzSHhCNVZscGpQcHE2LWpnaGhyUXc&#038;output=html">awesome talks</a> to cover without bi-locating. Mozillans were well-represented, including <a href="https://twitter.com/#!/dmandelin">dmandelin</a> and <a href="https://twitter.com/#!/iamdvander">dvander</a> on <a href="http://jsconf.eu/2011/javascript_jits.html">JavaScript</a> <a href="http://www.slideshare.net/iamdvander/js-math-jiting-jsconfeu">JITs</a>, <a href="https://twitter.com/#!/marijnjh">Marijn Haverbeke</a> on <a href="http://jsconf.eu/2011/dom_implementation_techniques.html">DOM implementation techniques</a>, <a href="https://twitter.com/#!/codepo8">Chris Heilmann</a> on <a href="http://www.wait-till-i.com/2011/10/05/jsconf-eu-community-js-reloaded-how-to-rock-as-a-movement/">Community JS reloaded &#8211; how to rock as a movement</a>, and <a href="https://twitter.com/andreasgal">Andreas Gal</a> on <a href="https://github.com/andreasgal/pdf.js">PDF.js</a>. <a href="https://twitter.com/#!/jmswisher">Janet Swisher</a> led the <a href="http://jsconf.eu/2011/mozilla_the_jsconf_eu_hacker_l.html">MDC doc sprint</a> in the Hacker Lounge.</p>
<p>I would like to single out <a href="http://syntensity.blogspot.com/">Alon Zakai</a>&#8216;s <a href="http://syntensity.com/static/jsconf_eu_Emscripten_lo.pdf">Emscripten talk</a>. <a href="https://github.com/kripken/emscripten">Emscripten</a> is an <a href="http://llvm.org/">LLVM</a>-to-JS compiler, which means it enables compiling C, C++, and Objective-C (and other languages with LLVM front ends) to JS. What&#8217;s more, interpreters written in C for Python, Ruby, and Lua have been compiled and <a href="http://repl.it">hosted</a> on the web.</p>
<p>Alon&#8217;s results are impressive, with lots of room for more wins. At JSConf.eu, jaws dropped and eyes were opened.</p>
<p>For my talk, I reprised some <a href="/2011/09/capitoljs-rivertrail/">CapitolJS</a> material, including the <a href="http://www.youtube.com/watch?v=QzOIydC2Has&#038;eurl=http%3A%2F%2Fbrendaneich.com%2F2011%2F09%2Fcapitoljs-rivertrail%2F&#038;feature=player_embedded">RiverTrail</a> demo, which won loud and enthusiastic applause when I clicked on the &#8220;Parallel&#8221; button.</p>
<p>(A few people asked afterward about whether the graphics was running on one of four cores. I&#8217;ll repeat the answer here: the <a href="https://github.com/RiverTrail/RiverTrail/tree/master/examples/idf-demo">particle system demo</a> uses <a href="http://www.khronos.org/webgl/">WebGL</a> targeting the GPU for rendering, and the four CPUs&#8217; <a href="http://en.wikipedia.org/wiki/SSE4">vector units</a> for n-body solving. All from deadlock-free, data-race-free, seemingly single-threaded JS.)</p>
<p>Here&#8217;s the video of my talk:</p>
<p><iframe src="http://blip.tv/play/hq0KgtmjAgI.html" width="480" height="300" frameborder="0" allowfullscreen></iframe><embed type="application/x-shockwave-flash" src="http://a.blip.tv/api.swf#hq0KgtmjAgI" style="display:none"></embed></p>
<p>The amazing <a href="https://twitter.com/#!/annalena">Anna Lena Schiller</a> created infographics for all the talks, on the spot &#8212; a truly impressive display of concentration and stamina. Here&#8217;s the one she did for my talk:</p>
<p><img src="/brendaneich_content/uploads/JSConf.eu-2011-InfoGraphic.jpg" height="304" width="500"></p>
<p>And here are the updated and new slides I presented, showing ES6 work-in-progress (none of it final, so don&#8217;t panic) and covering some current controversies.</p>
<p><img src="/brendaneich_content/uploads/JSLOL.007.png" height="432" width="576"></p>
<p>From <a href="https://mail.mozilla.org/pipermail/es-discuss/2011-October/016997.html">recent</a> <a href="https://mail.mozilla.org/pipermail/es-discuss/2011-October/017001.html">es-discuss</a> <a href="https://mail.mozilla.org/pipermail/es-discuss/2011-October/017014.html">messages</a>, I&#8217;m afraid that classes are on their way out of ES6. This seems a shame, and avoidable. In hindsight, we did not have all class advocates working in concert on the hard issues last year and earlier this year. But we also do not agree on what&#8217;s required for ES6, and some on TC39 view <a href="https://mail.mozilla.org/pipermail/es-discuss/2011-June/015559.html">minimizing</a> as future-hostile.</p>
<p>To be blunt, we lost some &#8220;classes&#8221; advocates who work for Google to <a href="http://dartlang.org/">Dart</a>. Others at Google on TC39 seem to want more out of ES6 classes than even Dart guarantees (see the future-hostile point above).</p>
<p>I&#8217;m not slamming Google as a company here, since it does still support people working on JS in TC39. I respect the people involved and believe they&#8217;re for the most part making their own choices. But Dart and other unrelated Google agenda items do impose clear and significant opportunity costs on Google&#8217;s standards actiivities.</p>
<p>To remain positive per &#8220;An End to Negativity&#8221;, I&#8217;ll simply conclude that we TC39ers should pay attention to Dart now that it is out, even though we&#8217;ve lost time and potential contributions.</p>
<p>The famous Tony Hoare quote that <a href="https://mail.mozilla.org/pipermail/es-discuss/2011-October/016966.html">Bill Frantz</a> cited, which argues for deferring classes, is this:</p>
<blockquote><p>When any new language design project is nearing completion, there is always a mad rush to get new features added before standardization. The rush is mad indeed, because it leads into a trap from which there is no escape. A feature which is omitted can always be added later, when its design and its implications are well understood. A feature which is included before it is fully understood can never be removed later.<br />
<cite> From C.A.R.Hoare&#8217;s 1980 ACM Turing Award Lecture</cite></p></blockquote>
<p>I agree with <a href="https://mail.mozilla.org/pipermail/es-discuss/2011-October/017007.html">Erik Arvidsson</a> that &#8220;[b]y not providing [class] syntax we are continuing to encourage a million incompatible &#8216;class&#8217; libraries.&#8221; I&#8217;m with Erik: I would still like to see TC39 agree on minimal classes. But not at any cost.</p>
<p>Onward to new proposals with sometimes-tentative syntax. I&#8217;m continuing to &#8220;live in a fishbowl&#8221; by showing these proposals, even though doing so risks drive-by misinterpretation that we have finalized the sum of all proposals.</p>
<p>So, please don&#8217;t freak out. Not all of this will make it as proposed. We may also make cuts. But it&#8217;s important to address the use-cases motivating these proposals, take in the fullness of the problem space and potential solutions, and do the <a href="/brendaneich_content/uploads/TXJS-Talk.008.png">hermeneutic spiral</a>.</p>
<p><img src="/brendaneich_content/uploads/JSLOL.008.png" height="432" width="576"></p>
<p>Apart from font issues that make <code>&lt;|</code> look lopsided or non-triangular, this proposal looks good. It replaces the main legitimate use-case for assigning to <code>__proto__</code>: presetting the prototype link in an object literal.</p>
<p><img src="/brendaneich_content/uploads/JSLOL.009.png" height="432" width="576"></p>
<p>Unlike <code>Object.extend</code>, <code>.{</code> copies only &#8220;own&#8221; properties from its right-hand-side object literal, and (this is a crucial difference) it also copies properties with <a href="wiki.ecmascript.org/doku.php?id=harmony:private_name_objects">private name object</a> keys (which are non-enumerable by definition). For example, <code>base.{[privateName]: value, publicName: value2}</code> given a private name object reference denoted <code>privateName</code> in scope.</p>
<p><img src="/brendaneich_content/uploads/JSLOL.010.png" height="432" width="576"></p>
<p><a href="http://www.norvig.com/design-patterns/">Design patterns</a> point to programming language bugs. Nevertheless, this class pattern shows clever work by <a href="http://www.wirfs-brock.com/allen/">Allen Wirfs-Brock</a>, decomposing classes-as-sugar into chained operator expressions. It&#8217;s still a bit verbose and error-prone in my opinion, and cries out for the ultimate sugar of minimal class syntax (if only we could agree on that).</p>
<p><img src="/brendaneich_content/uploads/JSLOL.011.png" height="432" width="576"></p>
<p>Much of the <a href="http://dartlang.org/">Dart</a> class syntax design looks good to me. Possibly TC39 can agree to adopt it, with necessary adjustments. It would still be sugar for constructors and prototypes.</p>
<p><img src="/brendaneich_content/uploads/JSLOL.012.png" height="432" width="576"></p>
<p><a href="wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax">Arrow function syntax</a> faces an uphill battle due to the combination of TC39&#8242;s agreement to <a href="https://mail.mozilla.org/pipermail/es-discuss/2008-October/007888.html">future-proof</a> by having an unambiguous <a href="http://en.wikipedia.org/wiki/LR%281%29">LR(1)</a> grammar (after ASI and with lookahead restrictions); mixed with the comma expression, <code>(a, b, c)</code>, which I copied into JS&#8217;s grammar straight from C (not from Java, which left it out, instead providing comma-separated special forms in a few contexts, e.g. <code>for(;;)</code> loop heads). You can&#8217;t have both, and we do not want to remove the comma expression in Harmony.</p>
<p><img src="/brendaneich_content/uploads/JSLOL.013.png" height="432" width="576"></p>
<p><img src="/brendaneich_content/uploads/JSLOL.014.png" height="432" width="576"></p>
<p>I&#8217;m quite in favor of <a href="wiki.ecmascript.org/doku.php?id=strawman:block_lambda_revival">block-lambdas</a>, and they meet formal approval from TC39&#8242;s strictest grammarian. Some still object to them as an alien DNA injection from Ruby and Smalltalk, both syntactically and (with <a href="http://gafter.blogspot.com/2006/08/tennents-correspondence-principle-and.html">Tennent Correspondence Principle</a> conformance regarding <code>return</code>, <code>break</code>, <code>continue</code>, and <code>this</code>) semantically.</p>
<p><img src="/brendaneich_content/uploads/JSLOL.015.png" height="432" width="576"></p>
<p>At this point, ES6 has no shorter function syntax. This seems like a loss, and fixable, to me. Your comments welcome, especially if they make novel distinctions that help forge consensus.</p>
<p><img src="/brendaneich_content/uploads/JSLOL.016.png" height="432" width="576"></p>
<p>During the talk and Q&#038;A, I recounted how the <a href="http://www.whatwg.org/">WHAT-WG</a> was <a href="/2004/06/the-non-world-non-wide-non-web/">created</a> to counteract a standards body gone wrong (the 2004-era W3C). I then raised the idea of a community-based group, a &#8220;JS-WG&#8221;, to augment the much healthier but still under-staffed <a href="/2011/08/my-txjs-talk-twitter-remix/">Ecma TC39 committee</a>.</p>
<p>Besides floating more ideas (really, the point is not to bikeshed endlessly or take in too many proposals to digest), a JS-WG worth organizing might actually develop draft specs and prototype implementation patches for JavaScriptCore, SpiderMonkey, and V8. The maintainers of those engines could use the help, and with patches and patched builds, we could scale up user testing beyond what&#8217;s in the cards now.</p>
<p><img src="/brendaneich_content/uploads/JSLOL.017.png" height="432" width="576"></p>
<p>I know it&#8217;s hard to believe, but people are finally realizing that with V8 prototyping alongside SpiderMonkey, ES6 is happening. It&#8217;ll be prototyped in pieces. I hope many will be &#8220;on by default&#8221; (e.g., not under a flag in Chrome) well before the new edition is standardized (end of 2013). That&#8217;s how we roll in Firefox with SpiderMonkey.</p>
<p>/be</p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2011/10/jsconf-eu/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>CapitolJS, RiverTrail</title>
		<link>http://brendaneich.com/2011/09/capitoljs-rivertrail/</link>
		<comments>http://brendaneich.com/2011/09/capitoljs-rivertrail/#comments</comments>
		<pubDate>Sat, 24 Sep 2011 02:11:54 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=1546</guid>
		<description><![CDATA[I took time away from the Mozilla all-hands last week to help out on-stage at the Intel Developer Forum with the introduction of RiverTrail, Intel&#8217;s technology demonstrator for Parallel JS &#8212; JavaScript utilizing multicore (CPU) and ultimately graphics (GPU) parallel processing power, without shared memory threads (which suck). Then over the weekend, I spoke at [...]]]></description>
			<content:encoded><![CDATA[<p>I took time away from the Mozilla all-hands last week to help out on-stage at the <a href="http://www.intel.com/idf/">Intel Developer Forum</a> with the introduction of <a href="http://blogs.intel.com/research/2011/09/pjs.php">RiverTrail</a>, Intel&#8217;s technology demonstrator for Parallel JS &#8212; JavaScript utilizing multicore (CPU) and ultimately graphics (GPU) parallel processing power, without shared memory <a href="/2007/02/threads-suck/">threads (which suck)</a>.</p>
<p>Then over the weekend, I spoke at <a href="http://capitoljs.com/schedule.html">CapitolJS</a>, talking about ES6 and Dart, and demo&#8217;ing RiverTrail to the JS faithful. As usual, I&#8217;ll narrate <a href="http://www.slideshare.net/BrendanEich/capitol-js">my slides</a>, but look out for something new at the end: a screencast showing the RiverTrail IDF demo.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.001.png" height="432" width="576"></p>
<p>I had a lot to cover in a half-hour (a good talk-time in my view &#8212; we&#8217;ll see how the video comes out, but I found it invigorating). CapitolJS had a higher-than-<a href="http://jsconf.us/">JSConf</a> level of newcomers to JS in attendance, so I ran through material that should be familiar to readers of this blog, presented here without much commentary:</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.002.png" height="432" width="576"></p>
<p>The meaning of my color-coding should be intuitively obvious <img src='http://brendaneich.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.003.png" height="432" width="576"></p>
<p>BTW, <a href="http://github.com/andreasgal/dom.js">dom.js</a>, with its <a href="/2010/11/proxy-inception/">Proxy</a> usage under the hood, is going great, with <a href="https://twitter.com/#!/__DavidFlanagan">David Flanagan</a> and <a href="https://twitter.com/#!/donovanpreston">Donovan Preston</a> among others hacking away on it, and (this is important) providing <a href="http://lists.w3.org/Archives/Public/public-script-coord/">feedback</a> to <a href="http://www.w3.org/TR/WebIDL/">WebIDL</a>&#8216;s editor, <a href="https://twitter.com/#!/heycam/">Cameron McCormack</a>.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.004.png" height="432" width="576"></p>
<p>Here I must add the usual caveat that &#8220;ES6&#8243; might be renumbered. Were I more prudent, I&#8217;d call it &#8220;ES.next&#8221;, but it&#8217;s highly likely to be the 6th edition, and you&#8217;re all sophisticated close readers of the spec and its colorful history, right?</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.005.png" height="432" width="576"></p>
<p>The SpiderMonkey bug tracking <a href="http://wiki.ecmascript.org/doku.php?id=harmony:binary_data">binary data</a> prototype implementation is <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=578700">bug 578700</a>.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.006.png" height="432" width="576"></p>
<p>The SpiderMonkey bug tracking <a href="http://wiki.ecmascript.org/doku.php?id=harmony:quasis">quasi-literal</a> prototype implementation is <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=688857">bug 688857</a>.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.007.png" height="432" width="576"></p>
<p>The <code>@</code> notation is actually &#8220;out&#8221; for ES6, per the July meeting (see <a href="https://mail.mozilla.org/pipermail/es-discuss/2011-August/016188.html">notes</a>). Thanks to <a href="http://wiki.ecmascript.org/doku.php?id=harmony:private_name_objects">private name objects</a> and <a href="http://wiki.ecmascript.org/lib/exe/fetch.php?id=harmony%3Aprivate_name_objects&#038;cache=cache&#038;media=harmony:private-name-alternatives.pdf">object literal extensions</a> (see middle column), private access syntax is factored out of classes. Just use <code>this[x]</code> or <code>p[x]</code>, or (in an object literal for the computed property name, which need not be a private name) <code>[x]: </code><i>value</i>.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.008.png" height="432" width="576"></p>
<p>As close to CoffeeScript as I can get them, given JS&#8217;s grammar and curly-brace (not indentation-based) block structure.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.009.png" height="432" width="576"></p>
<p>Ruby-esque, Smalltalk is the grandfather.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.010.png" height="432" width="576"></p>
<p>You know you want it.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.011.png" height="432" width="576"></p>
<p>I&#8217;ve been clear about preferring <a href="http://wiki.ecmascript.org/doku.php?id=strawman:block_lambda_revival">block-lambdas</a> over <a href="http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax">arrows</a> for their added semantic value and compelling syntax mimicking control statements. It&#8217;s good to hear <a href="https://twitter.com/#!/jashkenas">@jashkenas</a> agree in effect.</p>
<p><a href="https://twitter.com/#!/mikeal">@mikeal</a> is right that JS syntax is not a problem for some (perhaps many) users. For others, it&#8217;s a hardship. Adding block-lambdas helps that cohort, adds value for code generators (see Harmony Goals above), and on balance improves the language in my view. It won my straw show-of-hands poll at CapitolJS against all of arrows, vaguer alternatives, and doing nothing.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.012.png" height="432" width="576"></p>
<p>The epic <a href="http://news.ycombinator.com/item?id=2982256">Hacker News</a> thread on my last blog post in relation to Dart needs its own <a href="http://en.wikipedia.org/wiki/Baedeker">Baedeker</a>. For now I&#8217;ll just note that Dart and the politics evident in the memo are not making some of my standards pals who work for other browser vendors happy. Google may fancy itself the new Netscape, but it doesn&#8217;t have the market share to pull off proprietary power-move <i>de facto</i> standards.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.013.png" height="432" width="576"></p>
<p>The <a href="http://markmail.org/message/uro3jtoitlmq6x7t">leaked memo</a> makes some observations I agree with, some unbacked assertions about unfixable JS problems that TC39 work in progress may falsify this year, and a few implicit arguments that are just silly on their face.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.014.png" height="432" width="576"></p>
<p>Still, I think we should react to valid complaints about JS, whatever the source. The <code>number</code> type has well-known <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=5856">usability</a> and (in practice, in spite of aggressively optimizing JIT-compiling VMs) <a href="http://blog.mozilla.com/dmandelin/2011/06/16/know-your-engines-at-oreilly-velocity-2011/">performance</a> problems.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.015.png" height="432" width="576"></p>
<p>The last bullet shows pragmas for switching default numeric type and arithmetic evaluation regime. This would have to affect <code>Number</code> and <code>Math</code>, but lexically &#8212; no dynamic scope. Still a bit hairy, and not yet on the boards for Harmony. But perhaps it ought to be.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.016.png" height="432" width="576"></p>
<p>Links: [<a href="http://blog.mozilla.com/dmandelin/2011/06/16/know-your-engines-at-oreilly-velocity-2011/">it's true</a>], [<a href="https://wiki.mozilla.org/TypeInference">SpiderMonkey Type Inference</a>].</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.017.png" height="432" width="576"></p>
<p>Coordinated strawman prototyping in SpiderMonkey and V8 is a tall order. Perhaps we need a separate <a href="http://jswg.org/">jswg.org</a>, as whatwg.org is to the w3c, to run ahead? I&#8217;ve been told I should be BDFL of such an org. Would this work? Comments welcome.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.018.png" height="432" width="576"></p>
<p>Remember, <a href="http://en.wikipedia.org/wiki/GPU">ridiculously</a> <a href="http://en.wikipedia.org/wiki/Multi-core_processor">parallel</a> processing power is coming, if not already present, on your portable devices. It&#8217;s here on your laptops and desktops. The good news is that JS can exploit it without your having to deal with data races and deadlocks.</p>
<p><a href="http://github.com/RiverTrail/RiverTrail">RiverTrail</a> is a <a href="http://github.com/mozilla/narcissus">Narcissus</a>-based JS to <a href="http://en.wikipedia.org/wiki/OpenCL">OpenCL</a> compiler, packaged as a Firefox add-on. It demonstrates the utility of a new <code>ParallelArray</code> built-in, based on <a href="http://www.khronos.org/registry/typedarray/specs/latest/">typed arrays</a>. The JS-to-OpenCL compiler automatically multicore-short-vectorizes your JS for you.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.019.png" height="432" width="576"></p>
<p>As noted in the previous slide, because the <code>ParallelArray</code> methods compile to parallelized folds (see <a href="http://en.wikipedia.org/wiki/Guy_L._Steele,_Jr.">Guy Steele&#8217;s</a> excellent <a href="http://vimeo.com/6624203">ICFP 2009 keynote</a>), associative operations will be reordered, resulting in small non-deterministic floating point imprecision errors. This won&#8217;t matter for graphics code in general, and it&#8217;s an inevitable cost of business using parallel floating point hardware.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.020.png" height="432" width="576"></p>
<p>The code looks like typical JS, with no hairy callbacks, workers, or threads. It requires thinking in terms of immutable trees and reductions or other folds, but that is not a huge burden. As Guy&#8217;s talk makes plain, learning to program this way is the key to parallel speedups.</p>
<p>Here is my screencast of the demo. Alas, since RiverTrail currently targets the <a href="http://en.wikipedia.org/wiki/Intel_Core_i7">CPU</a> and its short vector unit (<a href="http://en.wikipedia.org/wiki/SSE4">SSE4</a>), and my screencast software uses the same parallel hardware, the frame rate is not what it should be. But not to worry, we&#8217;re working on GPU targeting too.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/QzOIydC2Has" allowfullscreen></iframe></p>
<p>At CapitolJS and without <a href="http://www.telestream.net/screen-flow/">ScreenFlow</a> running, I saw frame rates above 35 for the Parallel demo, compared to 3 or 2 for Sequential.</p>
<p>The point of a technology demonstrator is to show where real JS engines can go. Automatic parallelization of <code>ParallelArray</code>-based code can be done by next year&#8217;s JS engines, based on this year&#8217;s Firefox add-on. We&#8217;re very close to exploiting massively parallel hardware from JS, without having to write <a href="http://webcl.nokiaresearch.com/">WebCL</a> and risk terrible safety and DoS bugs.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.021.png" height="432" width="576"></p>
<p>To close, I sought inspiration from Wesley Snipes in <a href="http://www.imdb.com/title/tt0105104/">Passenger 57</a>. Ok, not his best movie, but I miss the &#8217;90s action movie era.</p>
<p><img src="/brendaneich_content/uploads/CapitolJS.022.png" height="432" width="576"></p>
<p>Seriously, the shortest path on the Web usually is the winning play. JS is demonstrably able to grow new capabilities with less effort than a &#8220;replacement&#8221; entails. Always bet on JS!</p>
<p>/be</p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2011/09/capitoljs-rivertrail/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>My TXJS talk (Twitter remix)</title>
		<link>http://brendaneich.com/2011/08/my-txjs-talk-twitter-remix/</link>
		<comments>http://brendaneich.com/2011/08/my-txjs-talk-twitter-remix/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 01:58:08 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=1446</guid>
		<description><![CDATA[TXJS 2011 A6 &#8211; Brendan Eich &#8211; Ecma TC39: The Good, The Bad, and The Ugly. [Main slides] [Paren-free] I spoke at TXJS, a really excellent regional JS conference, in June. Thanks to @SlexAxton, rmurphey, and everyone else involved. My talk was concerned with the good, bad, and ugly of Ecma TC39 (and I mean [...]]]></description>
			<content:encoded><![CDATA[<p><iframe src="http://player.vimeo.com/video/27911873?title=0&#038;byline=0&#038;portrait=0" width="600" height="360" frameborder="0"></iframe></p>
<p><a href="http://vimeo.com/27911873">TXJS 2011 A6 &#8211; Brendan Eich &#8211; Ecma TC39: The Good, The Bad, and The Ugly.</a></p>
<p>[<a href="http://www.slideshare.net/slideshow/embed_code/8281947">Main slides</a>] [<a href="http://www.slideshare.net/slideshow/embed_code/8281964">Paren-free</a>]</p>
<p>I spoke at <a href="http://2011.texasjavascript.com/">TXJS</a>, a really excellent regional JS conference, in June. Thanks to <a href="https://twitter.com/#!/slexaxton">@SlexAxton</a>, <a href="https://twitter.com/#!/rmurphey">rmurphey</a>, and everyone else involved. My talk was concerned with the good, bad, and ugly of Ecma TC39 (and I mean those words in the best possible way!), mixing philosophy with historical events from the last 14 years.</p>
<p>After describing the standards process and its history in Ecma, I presented the <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proposals">good stuff</a> that&#8217;s going into <a href="http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts">ES6</a> (I gave a remixed version of this part of the talk at an <a href="http://sftechtalks.com/irisheich.html">SFTechTalk</a> hosted by Twitter last month &#8212; thanks to <a href="https://twitter.com/#!/valueof">@valueof</a> and <a href="https://twitter.com/#!/chanian">@chanian</a> for hosting). As a bonus, I closed with a <a href="/2010/11/paren-free/">paren-free</a> update, whose punchline slide is included at the bottom.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.001.png" height="432" width="576"></p>
<p>I am not Tuco.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.002.png" height="432" width="576"></p>
<p>We don&#8217;t smoke, but the rest is pretty much right.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.003.png" height="432" width="576"></p>
<p>Here I praised Jan van den Beld, former S-G, Ecma &#8212; a <i>raconteur</i> and polymath, for his stewardship of Ecma.</p>
<p>Yes, Netscape picked ECMA (now Ecma, pay attention <img src='http://brendaneich.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) as standards body to which to submit JS mainly to give Microsoft grief, since ECMA had bravely standardized some part of the Windows API. But Jan and the entire TC39 TG1 group played fair on ES1, the first ECMA-262 Edition. Microsoft was so happy they standardized early <a href="http://www.ecma-international.org/publications/standards/Ecma-334.htm">C#</a> and <a href="http://www.ecma-international.org/publications/standards/Ecma-335.htm">CLI</a> metadata specs at Ecma.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.004.png" height="432" width="576"></p>
<p>Not Bruce Campbell, so not me. That means I&#8217;m the Bad.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.005.png" height="432" width="576"></p>
<p>Here is something that the Google <a href="http://markmail.org/message/uro3jtoitlmq6x7t">leak about Dart</a> (née Dash) telegraphs: many Googlers, especially V8 principals, do not like JS and don&#8217;t believe it can evolve &#8220;in time&#8221; (whatever that might mean &#8212; and Google of course influences JS&#8217;s evolution directly, so they can put a finger on the scale here).</p>
<p>They&#8217;re wrong, and I&#8217;m glad that at least some of the folks at Google working in TC39 actually believe in JS &#8212; specifically its ability to evolve soon enough and well enough to enable both more predictable performance and programming in the large.</p>
<p>There&#8217;s a better-is-better bias among Googlers, but the Web is a brutal, shortest-path, <a href="http://www.dreamsongs.com/WorseIsBetter.html">Worse-is-Better</a> evolving system.</p>
<p>I&#8217;ve spent the last 16 years betting on the Web. Evolving systems can face collapses, die-offs, exigent circumstances. I don&#8217;t see JS under imminent threat of death due to such factors, though. Ironic that Google would put a death mark on it.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.006.png" height="432" width="576"></p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.007.png" height="432" width="576"></p>
<p>Here I propose that <a href="http://crockford.com/">Crock</a> is Plato and I am Aristotle, and that while we need to &#8220;keep it real&#8221;, we must also hew to high ideals.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.008.png" height="432" width="576"></p>
<p>The ideas I cite here, represented by the <a href="http://en.wikipedia.org/wiki/Hermeneutic_circle">Hermenuetic Circle</a>, definitely apply to TC39&#8242;s understanding of the text of ECMA-262, as well as various canonical texts in Computer Science. The committee works best when it spirals in on a solid design, avoiding local and premature optimizations and pessimizations.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.009.png" height="432" width="576"></p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.010.png" height="432" width="576"></p>
<p>Every one of these &#8220;Bad Parts&#8221; has been on parade in TC39 in recent years, including 2011. I&#8217;ve been tempted by the second one, horse-trading, so I&#8217;m not innocent (no one is).</p>
<p>The &#8220;Scenario Solving&#8221; one is particularly subtle in that the Scenario proposed to be solved is quite often a very real developer problem. But a complex, ad-hoc solution to it, especially when rushed, too often is unsound. We would do better to take the <a href="http://schemers.org/Documents/Standards/R5RS/r5rs.pdf">Scheme</a> lesson to heart, and develop sound and valid orthogonal primitives. Higher-level libraries built on them can be standardized <i>post hoc</i>.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.011.png" height="432" width="576"></p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.012.png" height="432" width="576"></p>
<p>These meta-discussions are sometimes quite funny in light of the vendor whose representative is making them. I note that C# can now be written to <a href="http://www.weirdlover.com/2010/07/26/prototypal-c-making-c-look-and-work-like-javascript/">look like JS</a>. Why shouldn&#8217;t any particular extension to C# be <i>at least</i> considered (not rubber-stamped of course) for JS standardization?</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.013.png" height="432" width="576"></p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.014.png" height="432" width="576"></p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.015.png" height="432" width="576"></p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.016.png" height="432" width="576"></p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.017.png" height="432" width="576"></p>
<p>These slides provide a glimpse of <a href="http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts">ES6</a>, still under construction but already full of good stuff.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.018.png" height="432" width="576"></p>
<p>The <a href="http://wiki.ecmascript.org/doku.php?id=harmony:harmony">Harmony Goals</a> are not just lofty abstractions.</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.019.png" height="432" width="576"></p>
<p>I hope the way JS is developed and standardized, as much in the open as the existing standards process permits, and with developer feedback via <a href="https://mail.mozilla.org/listinfo/es-discuss">es-discuss</a>, <a href="https://twitter.com/#!/brendaneich">twitter</a>, and the various conference talks, helps. If not, we may as well <a href="https://twitter.com/#!/Gilad_Bracha/status/112181374332579840">wait</a> for some single-source solution to descend from the mountain. And then hold our breaths waiting for Firefox, IE and Safari to implement!</p>
<p><img src="/brendaneich_content/uploads/TXJS-Talk.020.png" height="432" width="576"></p>
<p><img src="/brendaneich_content/uploads/paren-free.009.png" height="432" width="576"></p>
<p>While <a href="/2010/11/paren-free/">paren-free</a> in all likelihood won&#8217;t make ES6, the <code>for-of</code> loop will, and comprehensions and generator expressions in ES6 will be paren-free. Yay!</p>
<p>/be</p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2011/08/my-txjs-talk-twitter-remix/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>New JavaScript Engine Module Owner</title>
		<link>http://brendaneich.com/2011/06/new-javascript-engine-module-owner/</link>
		<comments>http://brendaneich.com/2011/06/new-javascript-engine-module-owner/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 02:30:03 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=1400</guid>
		<description><![CDATA[As you may know, I wrote JavaScript in ten days. JS was born under the shadow of Java, and in spite of support by marca and Bill Joy, JS in 1995 was essentially a one-man show. I had a bit of help, even at the start, that I&#8217;d like to acknowledge again. Ken Smith, a [...]]]></description>
			<content:encoded><![CDATA[<p>As you may know, I wrote <a href="http://brendaneich.com/2008/04/popularity/">JavaScript in ten days</a>. JS was born under the shadow of Java, and in spite of support by <a href="http://blog.pmarca.com/">marca</a> and <a href="http://en.wikipedia.org/wiki/Bill_Joy">Bill Joy</a>, JS in 1995 was essentially a one-man show.</p>
<p>I had a bit of help, even at the start, that I&#8217;d like to acknowledge again. Ken Smith, a Netscape acquiree from Borland, ported <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/util/Date.html">JDK 1.0-era java.util.Date</a> (we both just <a href="http://movieclips.com/yXM8-breaking-away-movie-chasing-a-truck/">drafted</a> off of the Java truck, per management orders; we did not demur from the <a href="http://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and-stupid/#comment-1048">Y2K bugs</a> in that Java class). My thanks also to Netscape 2&#8242;s front-end hackers, <a href="https://twitter.com/#!/knobchouck">chouck</a>, <a href="http://totic.org/">atotic</a>, and <a href="https://twitter.com/#!/gorpheus">garrett</a> for their support. EDIT: can&#8217;t forget <a href="http://www.linkedin.com/in/smurray">spence</a> on the X front end!</p>
<p>That was 1995. Engine prototype took ten days in May. Bytecode compiler and interpreter from the start, because Netscape had a <a href="http://www.datacraft.com/livewire.html">server-side JS product</a> in the works. The rest of the year was browser integration, mainly what became known as &#8220;DOM level 0&#8243;. Only now standardized in <a href="http://developers.whatwg.org/">HTML 5</a> and <a href="http://www.w3.org/TR/2011/WD-domcore-20110531/">Anne&#8217;s wg</a>. Sentence fragments here show my PTSD from that sprint :-/.</p>
<p>In 1996 I finally received some needed assistance from <a href="http://www.linkedin.com/profile/view?id=28112&#038;authType=name&#038;authToken=fiRT&#038;goback=.con">RRJ</a>, who helped port David M. Gay and Guy Steele&#8217;s <a href="http://www.netlib.org/fp/dtoa.c">dtoa.c</a> and fix date/time bugs.</p>
<p>Also in summer 1996, <a href="http://nixweb.com/">nix</a> interned at Netscape while a grad student at CMU, and wrote the first <a href="http://apps.ycombinator.com/item?id=1894374">LiveConnect</a>. I am still grateful for his generous contributions in wide-ranging design discussions and code-level interactions.</p>
<p>At some point in late summer or early fall 1996, it became clear to me that JS was going to be standardized. Bill Gates was bitching about us changing JS all the time (some truth to it; but hello! Pot meet Kettle&#8230;). We had a standards guru, <a href="http://www.linkedin.com/pub/carl-cargill/10/495/404">Carl Cargill</a>, who knew <a href="http://www.ecma-international.org/memento/history.htm">Jan van den Beld</a>, then the Secretary-General of ECMA (now Ecma). Carl steered our standardization of JS to ECMA.</p>
<p>Joining ECMA and participating in the first JS standards meeting was an eye-opener. Microsoft sent a B-team, and Borland and a company called NOMBAS also attended. &#8220;Success has many fathers&#8221; was the theme. The NOMBAS founder greeted me by saying &#8220;oh, we&#8217;ve been doing JavaScript for *years*&#8221;. I did not see how that could be the case, unless JS meant any scripting language with C-based syntax. I had not heard of <a href="http://www.quora.com/How-did-ScriptEase-influence-the-design-of-JavaScript">NOMBAS</a> before then.</p>
<p>At that first meeting, I think I did well enough in meta-debate against the Microsoft team that they sent their A-team to the next meeting. This was all to the good, and Microsoft in full-blooded compete mode, but also with individual initiative beyond the call of corporate duty by <a href="http://www.linkedin.com/pub/shon-katzenberger/17/681/516">Shon Katzenberger</a>, materially helped create <a href="http://www.mozilla.org/js/language/E262.pdf">ES1</a>. Sun contributed <a href="http://en.wikipedia.org/wiki/Guy_L._Steele,_Jr.">Guy Steele</a>, who is composed of pure awesome. Guy even brought <a href="http://www.dreamsongs.com/RPG.html">RPG</a> for fun to a few meetings (Richard contributed ES1 Clause 4).</p>
<p>Meanwhile, in fall 1996, I was under some pressure from Netscape management to write a proto-spec for JS, but that was not something I could do while also maintaining the &#8220;Mocha&#8221; engine all by myself in both shipping and future Netscape releases, along with all of the DOM code.</p>
<p>This was a ton of work, and on top of it I had to pay off substantial technical debt that I had willingly taken on in the first year. So I actually stayed home for two weeks to rewrite Mocha as the codebase that <a href="http://blog.cdleary.com/2011/06/mapping-the-monkeysphere/#comment-222163115">became known as</a> <a href="https://developer.mozilla.org/en/spidermonkey">SpiderMonkey</a>, mainly to get it done (no other way), also to go on a bit of a strike against the Netscape management team that was still underinvesting in JS. This entailed garbage collection and tagged values instead of slower reference-counting and fat discriminated union values.</p>
<p>Also in fall 1996, chouck decided to join me as the second full-time JS team-mate. He and I did some work targeting the (ultimately ill-fated) Netscape 4 release. This work was ahead of its time. We put the JS engine in a separate thread from the &#8220;main thread&#8221; in Netscape (still in Mozilla). This allowed us to better overlap JS and HTML/CSS/image computations, years ahead of multicore. You could run an iloop in JS and the &#8220;slow script dialog&#8221; seamlessly floated above it, allowing you to stop the loop or permit it to continue.</p>
<p>After summer 1996 and the start of ECMA-262 standardization, Netscape finally invested more in JS. <a href="http://argostravels.blogspot.com/">Clayton Lewis</a> joined as manager, and hired <a href="http://www.norrisboyd.com/">Norris Boyd</a>, who ended up creating Rhino from SpiderMonkey&#8217;s DNA transcoded to Java. This was ostensibly because Netscape was investing in Java on the server, in particular in an AppServer that wanted JS scripting.</p>
<p>I met <a href="http://shaver.off.net/diary/">shaver</a> for the first time in October 1996 at Netscape&#8217;s NY-based <a href="https://groups.google.com/forum/#!topic/comp.lang.tcl/qFm-YEQEbHw">Developer Conference</a>, where he nimbly nerd-blocked some Netscape plugin API fanboys and saved me from having to digress from the main thing, which was increasingly JS.</p>
<p>Some time in 1997, shaver contributed &#8220;LiveConnect 2&#8243;, based on more mature Java reflection APIs not available to nix in 1996. Clayton hired shaver and the JS team grew large by end of 1997, when I decided to take a break from JavaScript (having delivered ES1 and ES2) and join the nascent mozilla.org.</p>
<p>I handed the keys to the JS kingdom to <a href="http://www.linkedin.com/pub/waldemar-horwat/1/25/333">Waldemar Horwat</a>, now of Google, in late 1997. Waldemar did much of the work on ES3, and threw his <a href="http://en.wikipedia.org/wiki/William_Lowell_Putnam_Mathematical_Competition">considerable intellect</a> into JS2/ES4 afterwards, but without overcoming the market power and stalling tactics of Microsoft.</p>
<p>True story: Waldemar&#8217;s Microsoft nemesis on TC39 back then, at the time a static language fan who hated JS, has come around and now endorses JS and dynamic languages.</p>
<p>Throughout all of this, I maintained module ownership of SpiderMonkey.</p>
<p>Fast-forward to 2008. After a great (at the time) Firefox 3 release where <a href="https://twitter.com/#!/shaver">@shaver</a> and I donned the aging super-hero suits one more time to compete successfully on interpreter performance against JavaScriptCore in WebKit, <a href="http://andreasgal.com/">Andreas Gal</a> joined us for the summer in which we hacked TraceMonkey, which we <a href="http://brendaneich.com/2008/08/tracemonkey-javascript-lightspeed/">launched</a> ahead of Chrome and V8.</p>
<p>A note on V8: I&#8217;d learned of it in 2006, when I believe it was just starting. At that point there was talk about open-sourcing it, and I welcomed the idea, encouraging any of: hosting on code.google.com, hosting without any pressure to integrate into Firefox on mozilla.org (just like Rhino), or hosting with an integration plan to replace SpiderMonkey in Firefox. I had to disclose that another company was about to release their derived-from-JS <a href="http://www.mozilla.org/projects/tamarin/">engine</a> to Mozilla, but my words included &#8220;the more the merrier&#8221;. It was early days as far as JS JITs were concerned.</p>
<p>V8 never open-sourced in 2006, and stealthed its way to release in September 2008. This may have been a prudent move by Google to avoid exciting Microsoft. Clearly, in 1995, the &#8220;Netscape + Java kills Windows&#8221; talk from Netscape antagonized Microsoft. I have it on good authority that a Microsoft board member wrote marca at the end of 1995 warning &#8220;you&#8217;ve waved the cape in the bull&#8217;s face &#8212; prepare to get the horns!&#8221; One could argue that Chrome in 2008 was the new red cape in the bull&#8217;s face, which begot IE9 and Chakra.</p>
<p>Whatever Google&#8217;s reasoning, keeping V8 closed-source for over two years hurt JS in this sense: it meant Apple and Mozilla had to climb the JIT learning curves on their own (at first; then finally with the benefit of being able to inspect V8 sources). Sure, the Anamorphic work on Self and Smalltalk was somewhat documented, and I had learned it in the &#8217;90s, in part with a stint on loan from Netscape to Sun when they were doing due dliigence in preparation for acquiring Anamorphic. But the opportunity to build on a common engine codebase was lost to path dependence.</p>
<p>On the upside, different competing open source engines have demonstrably explored a larger design space than one engine codebase could under consolidated management.</p>
<p>In any event, the roads not taken in JS&#8217;s past still give me pause, because similar roads lie ahead. But the past is done, and once we had launched TraceMonkey, and Apple had launched SquirrelFish Extreme, the world had multiple proofs along with the V8 release that JS was no longer consigned to be &#8220;slow&#8221; or &#8220;a toy&#8221;, as one referee dismissed it in rejecting a PLDI submission from Andreas in 2006.</p>
<p>You know the rest: JS performance has grown <a href="http://blog.mozilla.com/dmandelin/2011/06/16/know-your-engines-at-oreilly-velocity-2011/">an order of magnitude</a> over the last several years. Indeed, JS still has upside undreamed of in the Java world where 1% performance win is remarkable. And, we are still at an early stage in studying web workloads, in order to synthesize credible benchmarks. On top of all this, the web is still evolving rapidly, so there are no stable workloads as far as I can tell.</p>
<p>Around the time TraceMonkey launched, Mozilla was lucky enough to hire <a href="http://blog.mozilla.com/dmandelin/">Dave Mandelin</a>, fresh from PhD work at UCB under <a href="http://www.cs.berkeley.edu/~bodik/">Ras Bodik</a>.</p>
<p>The distributed, open source Mozilla JS team delivered <a href="http://arewefastyet.com/">the goods</a> in Firefox 4, and credit goes to all the contributors. I single Dave out here because of his technical and personal leadership skills. Dave  is even-tempered, super-smart, and a true empirical/skeptical  scientist in the spirit of my hero, <a href="http://en.wikipedia.org/wiki/Richard_Feynman">Richard  Feynman</a>.</p>
<p>So it is with gratitude and more than a bit of relief, after a very long 16 years in full, 13 years open source, that I&#8217;m announcing the transfer of <a href="https://wiki.mozilla.org/Modules/Core#JavaScript">SpiderMonkey&#8217;s module ownership</a> to <a href="https://twitter.com/#!/dmandelin">@dmandelin</a>.</p>
<p><a href="http://www.youtube.com/watch?v=SAqq11HYMsk">Hail to the king, baby!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2011/06/new-javascript-engine-module-owner/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Mozilla&#8217;s NodeConf Presentation</title>
		<link>http://brendaneich.com/2011/05/mozillas-nodeconf-presentation/</link>
		<comments>http://brendaneich.com/2011/05/mozillas-nodeconf-presentation/#comments</comments>
		<pubDate>Thu, 05 May 2011 23:29:32 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[javascript ecmascript harmony spidermonkey spidernode v8 v8monkey nodejs nodeconf]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=1248</guid>
		<description><![CDATA[NodeConf is a blast, and Mozilla had a 30 minute slot. Here&#8217;s the slideshare.net link. SpiderNode and V8Monkey are on github, of course. Paul O&#8217;Shannessy already blogged a few weeks ago. To avoid confusion, here&#8217;s the cheat-sheet: V8Monkey is SpiderMonkey with V8&#8242;s API around it. We are not done emulating the full V8 API. Because [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nodeconf.com/">NodeConf</a> is a blast, and Mozilla had a <a href="http://nodeconf.com/schedule.html">30 minute slot</a>. Here&#8217;s the <a href="http://www.slideshare.net/BrendanEich/mozillas-nodeconf-talk">slideshare.net link</a>.</p>
<p><a href="/brendaneich_content/uploads/Node.001.png"><img src="/brendaneich_content/uploads/Node.001.png" height="432" width="576"></a></p>
<p><a href="https://github.com/zpao/spidernode">SpiderNode</a> and <a href="https://github.com/zpao/v8monkey">V8Monkey</a> are on <a href="https://github.com/">github</a>, of course. <a href="https://twitter.com/#!/zpao">Paul O&#8217;Shannessy</a> already <a href="http://blog.zpao.com/post/4620873765">blogged</a> a few weeks ago.</p>
<p><a href="/brendaneich_content/uploads/Node.002.png"><img src="/brendaneich_content/uploads/Node.002.png" height="432" width="576"></a></p>
<p>To avoid confusion, here&#8217;s the cheat-sheet:</p>
<ul>
<li>V8Monkey is <a href="https://developer.mozilla.org/spidermonkey">SpiderMonkey</a> with V8&#8242;s API around it. We are not done emulating the full V8 API.
<li>Because we haven&#8217;t managed to perfectly emulate the full V8 API, the few language-level extensions (e.g., <a href="http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi"><code>Error.captureStackTrace</code></a>), and the V8 build system, SpiderNode is a clone of <a href="https://github.com/joyent/node">Node</a> with V8Monkey integrated and (in a few cases we want to get rid of) hacked in place of V8.
</ul>
<p><a href="/brendaneich_content/uploads/Node.003.png"><img src="/brendaneich_content/uploads/Node.003.png" height="432" width="576"></a></p>
<p>This slide should speak for itself.</p>
<p>We are not out to make a maintained, competing fork of Node, just a friendly downstream that should go away as soon as possible. We aren&#8217;t selling anything to Node users.</p>
<p>We <i>are</i> trying to improve SpiderMonkey&#8217;s API, test Harmony JS language features in the Node setting, and have fun learning about the new JS server side.</p>
<p><a href="/brendaneich_content/uploads/Node.004.png"><img src="/brendaneich_content/uploads/Node.004.png" height="432" width="576"></a></p>
<p><a href="/brendaneich_content/uploads/Node.005.png"><img src="/brendaneich_content/uploads/Node.005.png" height="432" width="576"></a></p>
<p><a href="/brendaneich_content/uploads/Node.006.png"><img src="/brendaneich_content/uploads/Node.006.png" height="432" width="576"></a></p>
<p><a href="/brendaneich_content/uploads/Node.007.png"><img src="/brendaneich_content/uploads/Node.007.png" height="432" width="576"></a></p>
<p>These four slides are straight from my <a href="http://brendaneich.com/2011/05/my-jsconf-us-presentation/">JSConf.us 2011 talk</a>. I went fast since a lot of NodeConf attendees were at JSConf, but a good number of hands did not go up when I asked who attended both conferences.</p>
<p><a href="/brendaneich_content/uploads/Node.008.png"><img src="/brendaneich_content/uploads/Node.008.png" height="432" width="576"></a></p>
<p><a href="/brendaneich_content/uploads/Node.009.png"><img src="/brendaneich_content/uploads/Node.009.png" height="432" width="576"></a></p>
<p><a href="http://wiki.ecmascript.org/doku.php?id=harmony:generators"><code>yield</code></a> conquers the <a href="http://www.slideshare.net/sh1mmer/how-to-stop-writing-spaghetti-code">nested function spaghetti monster</a>.</p>
<p>Generators are winning, and they are worth playing with and investigating in SpiderNode and of course Firefox and other SpiderMonkey embeddings (also in Rhino). They are not the last word on the &#8220;anti-function-nesting&#8221; topic, for sure. I&#8217;m pretty sure there is no &#8220;last word&#8221;.</p>
<p>Thanks to <a href="https://twitter.com/#!/robarnold">Rob Arnold</a> for this demo and the next one, and of course to <a href="https://twitter.com/#!/@littlecalculist">Dave Herman</a> for <a href="https://github.com/dherman/taskjs">TaskJS</a>. Thanks too to <a href="https://twitter.com/#!/mehdisdwilsh">Shawn Wilsher</a> for the <a href="https://twitter.com/#!/mehdisdwilsh/status/66227670593179648">encouragement at the last minute <img src='http://brendaneich.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </a>.</p>
<p><a href="/brendaneich_content/uploads/Node.010.png"><img src="/brendaneich_content/uploads/Node.010.png" height="432" width="576"></a></p>
<p>This is an even shorter demo. I switched to a terminal window, fired up <code>$ ./node helloworld.js</code>, loaded <code>http://127.0.0.1:10337/</code> into a fresh Firefox window, and pressed reload repeatedly to show the counter incrementing.</p>
<p>Node really did break the mold when it comes to ease of writing server code that you can get running super-fast, using JS and lots of the client-side knowledge you may already have.</p>
<p><a href="/brendaneich_content/uploads/Node.011.png"><img src="/brendaneich_content/uploads/Node.011.png" height="432" width="576"></a></p>
<p>One more time: thanks to <a href="https://twitter.com/#!/robarnold">@robarnold</a>, <a href="https://twitter.com/#!/sdwilsh">@sdwilsh</a>, <a href="https://twitter.com/#!/zpao">@zpao</a>, the awesome <a href="https://twitter.com/#!/john_h_ford">@john_h_ford</a> who did our build automation, and of course my partner in crime for much mad science at Mozilla, <a href="https://twitter.com/#!/andreasgal">@andreasgal</a>.</p>
<p>Join us on IRC and the mailing list, we have a lot of work still to do, and we&#8217;re having a ton of fun.</p>
<p>/be</p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2011/05/mozillas-nodeconf-presentation/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>My JSConf.US Presentation</title>
		<link>http://brendaneich.com/2011/05/my-jsconf-us-presentation/</link>
		<comments>http://brendaneich.com/2011/05/my-jsconf-us-presentation/#comments</comments>
		<pubDate>Thu, 05 May 2011 04:44:14 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[javascript ecmascript harmony coffeescript]]></category>
		<category><![CDATA[transpiler]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=1246</guid>
		<description><![CDATA[@jashkenas was kind enough to let me join him for his JSConf.us session. Here is the slideshare link. I&#8217;ll comment on the individual slides below. Jeremy&#8217;s talk was entitled &#8220;CoffeeScript as a JS/next&#8221;, and I was interested in giving an update on Ecma TC39 Harmony progress, so when Jeremy and I met and caught up [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://twitter.com/#!/jashkenas">@jashkenas</a> was kind enough to let me join him for his <a href="http://2011.jsconf.us/#/proposal/9b24b4cbddec671383481fe16204b9d0">JSConf.us session</a>. Here is the <a href="http://www.slideshare.net/BrendanEich/esnext">slideshare link</a>. I&#8217;ll comment on the individual slides below.</p>
<p><a href="/brendaneich_content/uploads/ES.001.png"><img src="/brendaneich_content/uploads/ES.001.png" height="432" width="576"></a></p>
<p>Jeremy&#8217;s talk was entitled &#8220;<a href="http://jashkenas.github.com/coffee-script/">CoffeeScript</a> as a JS/next&#8221;, and I was interested in giving an update on Ecma TC39 <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proposals">Harmony</a> progress, so when Jeremy and I met and caught up during the first day of JSConf, we quickly agreed on a joint session with about 15 minutes in the first half for my stuff.</p>
<p><a href="/brendaneich_content/uploads/ES.002.png"><img src="/brendaneich_content/uploads/ES.002.png" height="432" width="576"></a></p>
<p> JS developers sometimes seem afraid of the future, specifically of what browser vendors and Ecma TC39 might do to them! Here I used some inspiring quotes and a practical, three-step process outline to encourage everyone at JSConf to have courage and make their direct wishes known, as best they can. By acting (using CoffeeScript, for example) as well as writing (es-discuss at mozilla.org).</p>
<p>Browser competition is hot, browser vendors crave developers as fans and supporters. This should give JS hackers great power, if they can speak coherently, as individuals and as a group. But it&#8217;s important for developers to speak clearly, since TC39 members often listen to their own peers on the committee and in their respective companies more than to the JS community writ large.</p>
<p>Of course &#8220;the community&#8221; does not speak with one voice. Communities do evolve leaders, and leaders are often necessarily articulate. Also, effective communities produce artifacts such as PrototypeJS and jQuery, which speak in their own ways.</p>
<p>Why does the community matter? One good reason is this: communities facing harsh survival tests (as JS&#8217;s has) reward merit better than committees operating under competitive and time pressures.</p>
<p><a href="https://twitter.com/#!/andrewdupont">@andrewdupont</a> observed, in his barn-burner of a <a href="http://2011.jsconf.us/#/proposal/9b24b4cbddec671383481fe1620bdb97">talk</a> near the end of JSConf day one, how recent JS standards started as community-project library methods. Often enough, these <i>de facto</i> standards also started out as rough and real, i.e., far from perfect &#8212; just as JS did. They had to be user-tested and iterated upon until winning.</p>
<p>I reiterated this point in my talk. TC39 should avoid inventing where it can <a href="http://lists.w3.org/Archives/Public/public-html/2007Aug/0435.html">pave the cowpaths</a>.</p>
<p><a href="/brendaneich_content/uploads/ES.003.png"><img src="/brendaneich_content/uploads/ES.003.png" height="432" width="576"></a></p>
<p>The <a href="http://wiki.ecmascript.org/doku.php?id=harmony:harmony">Harmony goals</a> (slightly reworded here to fit on the slide, and for clarity) indeed talk about codifying <i>de facto</i> standards.</p>
<p>The &#8220;complex applications&#8221; and &#8220;libraries&#8221; bits suggest programming in the large, implying <a href="http://wiki.ecmascript.org/doku.php?id=harmony:modules">modules</a> and other Harmony proposals. The &#8220;code generators targeting the new edition&#8221; verbiage directly invokes CoffeeScript and the many other <a href="https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS">JS code-generators</a> out there today.</p>
<p>An important point about the Harmony process: you don&#8217;t have to wait three years for a finished standard before browsers start supporting prototype implementations of solid proposals. We aim to do how implementors have done HTML5 and the Web API standards &#8212; continuous early implementation and rolling standardization. Thus, Proxies in FF4, WeakMaps in Nightly (FF6) releases, etc.</p>
<p><a href="/brendaneich_content/uploads/ES.004.png"><img src="/brendaneich_content/uploads/ES.004.png" height="432" width="576"></a></p>
<p>This slide (which builds bullet by bullet in Keynote) is as concise a summary as I could make of the bulk of what is already very likely in the next ECMA-262 Edition, according to the <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proposals">Harmony Proposals</a> wiki page.</p>
<p>We have invested over the years in most of these proposals, not only on TC39 but in SpiderMonkey (with Norris Boyd, Steve Yegge, et al. matching in Rhino), in order to test implementability and usability. Firefox and other Mozilla XUL apps and add-ons make great use of <code>let</code>, generators, and more. We will keep adjusting our prototype implementations to match the emerging ES.next spec.</p>
<p>Now it looks like other browsers will start to implement Harmony proposals. This effort complements the adoption of <i>de facto</i> standard library functions. Some problems can&#8217;t be solved in the current language by writing library code. We need language evolution at both syntactic (user interface) and semantic (deep meaning) layers.</p>
<p><a href="/brendaneich_content/uploads/ES.005.png"><img src="/brendaneich_content/uploads/ES.005.png" height="432" width="576"></a></p>
<p><a href="http://2011.jsconf.us/#/proposal/7edca1476b18fe06e50883702e26eafa">David Flanagan&#8217;s talk</a>, which was first up on JSConf day one, covered typed arrays and array buffers a bit. During the Q&#038;A I mentioned the Harmony <a href="http://wiki.ecmascript.org/doku.php?id=harmony:binary_data&#038;s=binary+data">binary data</a> proposal from <a href="https://twitter.com/#!/littlecalculist">@littlecalculist</a>.</p>
<p>The binary data proposal embraces and extends the fine work of WebGL <a href="http://www.khronos.org/registry/typedarray/specs/latest/">typed arrays</a>. Sometimes someone paves the cowpath into an expressway, which grows into a superhighway. JS has a lot of bits to move these days.</p>
<p><a href="/brendaneich_content/uploads/ES.006.png"><img src="/brendaneich_content/uploads/ES.006.png" height="432" width="576"></a></p>
<p>I&#8217;ve been talking about better function syntax for a while. <code>function</code> is too long (I wish I&#8217;d used <code>fn</code> in 1995 and preempted this issue).</p>
<p>TC39 has had several proposals or variations. Meanwhile, CoffeeScript has emerged and taken off. In <a href="http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax">arrow function syntax</a> I&#8217;ve synthesized all the winning ideas, without goring anyone&#8217;s ox. This slide conveys the main points of the proposal.</p>
<p>The <code>#</code> syntax from <a href="http://brendaneich.com/2011/01/harmony-of-my-dreams/">Harmony of My Dreams</a> evolves in this proposal to be an orthogonal prefix, for freezing and joining (fusing identity up to the nearest relevant closure). See <a href="http://wiki.ecmascript.org/doku.php?id=strawman:records">records</a> and <a href="http://wiki.ecmascript.org/doku.php?id=strawman:tuples">tuples</a> for analogous hash meaning.</p>
<p><a href="/brendaneich_content/uploads/ES.007.png"><img src="/brendaneich_content/uploads/ES.007.png" height="432" width="576"></a></p>
<p>Here I go out on a limb in listing some strawman proposals not yet in Harmony. Some of these will make ES.next, some probably won&#8217;t (there will be an ES.next.next).</p>
<p>At this point in my talk, I advocated strongly for standardizing <a href="http://jashkenas.github.com/coffee-script/#classes">prototypal inheritance</a> <i>a la</i> CoffeeScript&#8217;s <code>class</code>, <code>super</code>, and <code>@</code> syntactic sugar.</p>
<p>TC39 is tempted to &#8220;do more&#8221;, which means invent (not by committee but by champions, single members or sub-groups working on a particular area). I believe we will not achieve consensus soon, and possibly go wrong, if we overreach.</p>
<p>We could renounce classes in order to remain future-proof, but JS developers are <a href="http://www.aminutewithbrendan.com/pages/20110216">crying out</a> for sweet and (more important) foolproof syntax to make prototype-based single-inheritance class-like abstractions. We should pave this cowpath now.</p>
<p>(Some at the conference tweeted against &#8220;classes&#8221; thinking this was another turn-JS-into-Java thing, but counter-tweeting made it clear that it&#8217;s purely prototypal. What&#8217;s in a name? It is hard to beat &#8220;class&#8221;, IMHO.)</p>
<p>Oh, and <a href="http://brendaneich.com/2010/11/paren-free/">paren-free</a> still wins. Where it is not simply a relaxation of JS&#8217;s over-bracketed C-based grammar, it gives <code>for-in</code> in loops, comprehensions, and generator expressions not only lighter syntax (and only paren-free syntax!) &#8212; it gives better semantics.</p>
<p>Generally, paren-free <code>for-in</code> provides the iteration protocol hook for custom iterators, definitely including generators (the easiest way to write an iterator).</p>
<p>Specifically, paren-free <code>for-in</code> reforms array iteration to be over <i>values</i>, not keys. This is pure win (ignoring migration, see next paragraph), as far as I can tell.</p>
<p>Forbidding parenthesized <code>for-in</code> heads makes a migration &#8220;early error&#8221;, a tax for a common good: lighter syntax with much better semantics.</p>
<p><a href="/brendaneich_content/uploads/ES.008.png"><img src="/brendaneich_content/uploads/ES.008.png" height="432" width="576"></a></p>
<p>JS developers and implementors on TC39 must learn from one another and &#8220;meet in the middle&#8221;. The Harmony goals are good. But developers may do only what can be done in library code, or reach for CoffeeScript or another language on top of JS. And TC39 may over-invent.</p>
<p>The better way is a dialog between JS developers, especially natural leaders among them such as @jashkenas, and TC39 members.</p>
<p>This won&#8217;t involve &#8220;scientific polling&#8221;. There&#8217;s no substitute for nice judgment and (ultimately) sound language design theory and practice. But the experts must also learn from the users, who&#8217;ve moved mountains on their own over the last ten years. And users, meaning JS developers, should step up to this dialog and away from fear and passivity.</p>
<p><a href="/brendaneich_content/uploads/ES.009.png"><img src="/brendaneich_content/uploads/ES.009.png" height="432" width="576"></a></p>
<p>After our talk, with some fun stage misdirection, <a href="https://twitter.com/#!/slightlylate">Alex Russell</a> and Peter Hallam of Google introduced <a href="http://traceur-compiler.googlecode.com/">Traceur</a>, Google&#8217;s Harmony-ish transpiler. This is a good development on the whole. I&#8217;m happy to see it as a way to test proposals. However, I need to register some misgivings that go beyond &#8220;style point deductions&#8221;:</p>
<ul>
<li><a href="http://traceur-compiler.googlecode.com/svn/trunk/presentation/index.html">The slides</a> are Chrome-only. Come on, it&#8217;s not 1997. I&#8217;m using slideshare.net and HTML/PNG. There&#8217;s no excuse.
<li><a href="http://code.google.com/p/traceur-compiler/wiki/LanguageFeatures#Iterators_and_For_Each">Some</a> of the extensions are neither Harmony nor Strawman. (In particular <code>for (i : o)</code> was rejected. So was <code>__iterator__</code>.) I hope this can be updated, but if Traceur turns out to support (over the long run, ignoring short-term committee jitter) other than what has been pitched and vetted by TC39, that would be several kinds of wrong.
<li><a href="http://functionsource.com/post/traceur-googles-js-next-to-js-transpiler">Dion&#8217;s post</a> was up last night [UPDATE: <i>not</i> pre-arranged, Dion is just very fast even when he's not actually at JSConf. Sorry, D], yet it says &#8220;JS.next&#8221; without qualification. My posts, and other TC39ers as far as I know, have been careful to say &#8220;experimental&#8221;, &#8220;proposed&#8221;, &#8220;possible&#8221;, &#8220;dark horse&#8221;, etc. I personally try to assess odds of inclusion in ES.next based on the Harmony/Strawman process. No such nuance from Dion.
<li><a href="https://github.com/mozilla/narcissus/">Narcissus on github</a> is where Mozilla and several academic partners have been working on ES.next prototypes. We&#8217;re not as well-staffed as Google, but we&#8217;ve done this work in the open and I&#8217;ve talked about it since last year. Meanwhile, Traceur was done as &#8220;delayed open source&#8221;, with the wow-effect JSConf unveiling.
<li>Ok, to each his own. But the after-show cajoling by Alex to me, along the lines of &#8220;come work on our transpiler with us&#8221;, left a bad taste. I say: Open-source early, tell your TC39 colleagues your plans and intentions, invite others to join you. Don&#8217;t seed the googlecode project with all-Google-employee committers, work for months in relative secrecy, and <i>then</i> go open.
</ul>
<p>This reminds me of how V8 was developed (I have a few saved emails from 2006&#8230; V8 released as open source with Chrome in 2008).</p>
<p>Again, it&#8217;s Google&#8217;s prerogative to do whatever it wants with its staff and code. But this pattern of secret-first/open-later development is on a slippery slope toward <a href="http://www.readwriteweb.com/archives/how_to_spot_openwashing.php">openwashing</a>. That aside, with Traceur it seems &#8220;forkish&#8221; in TC39 social-cohesion terms.</p>
<p>Another point: a transpiler (syntax only or mostly) or true compiler/runtime targeting JS (new semantics too) is ultimately not enough. Harmony proposals need to be implemented in several engines, ideally including V8, before a new standard edition is ratified. No word on this at JSConf, but I hear good things from others at Google, so I&#8217;ll leave this one on a positive note.</p>
<p>Really, I&#8217;m not out to break TC39 and Harmony over this. Indeed we haven&#8217;t heard anything from Microsoft about what they&#8217;re hoping for in Harmony; we have not seen anything like an open source transpiler. So good for Google. But some things about how this came out don&#8217;t sit right, enough so that I&#8217;m writing publicly.</p>
<p><a href="/brendaneich_content/uploads/ES.010.png"><img src="/brendaneich_content/uploads/ES.010.png" height="432" width="576"></a></p>
<p>Jeremy is a star, and I want to thank him again for letting me share his slot. He made a number of excellent points, some intentionally &#8220;dialectically sharp&#8221;, all encouraging JS developers to use and even implement &#8220;better languages&#8221; built on top of JS.</p>
<p>The sharpest point in my mind was &#8220;JavaScript is too important to be left to the experts.&#8221; This is obviously true for several definitions of &#8220;experts&#8221;, but expertise matters too or we wouldn&#8217;t have <a href="http://zaach.github.com/jison/">Jison</a>, the parser-generator used by CoffeeScript, based on Bison and Yacc before it.</p>
<p>Jeremy was dialectically sharp to encourage developers to throw stuff up and see what sticks. Seeing what sticks with a programming language in part depends on user-testing, usability, human factors that are not reduced to science &#8212; that is, part of language design is art. He even encouraged people to &#8220;cheat when you get stuck&#8221;, words I try to live by (after the example of <a href="http://en.wikipedia.org/wiki/Kobayashi_Maru">Cadet Kirk</a>).</p>
<p>Now, not everyone is a <a href="https://twitter.com/#!/WilliamShatner">@WilliamShatner</a>, or a <a href="https://twitter.com/#!/jashkenas">@jashkenas</a>. Many will get stuck, cheat, fail, and cry in despair. Not to be discouraging!</p>
<p>Expertise, even formal methods and people who know them, can help. <a href="https://github.com/zaach/">Zaach</a>&#8216;s Jison is one example. TC39&#8242;s generally pragmatic collection of experts, including Dave Herman, Allen Wirfs-Brock, Mark Miller, Sam Tobin-Hochstadt and others, also constitute a valuable resource for the community.</p>
<p>What Jeremy and I tried to advocate, which I believe is happening before our eyes, is a connecting of the circle, from JS as I created it, though its fearless communities and their leaders, back to browser vendors and experts on TC39 &#8212; and around again.</p>
<p>We are not just advocating a language on top of JS that you use to <i>avoid</i> JS (GWT, Haxe, Objective-J, etc.). We are advocating that you all help build a better JS on JS, which then becomes standardized as JS.next.</p>
<p>This is important work. I haven&#8217;t seen anything like it at this scale, with multiple interoperating implementations. It happens with single-open-source-as-spec languages (Perl, Python, Ruby). With transpilers, better libraries, and <i>de facto</i>, prompt (but not premature) standardization, it can happen with JS, too.</p>
<p>/be</p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2011/05/my-jsconf-us-presentation/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Harmony Of My Dreams</title>
		<link>http://brendaneich.com/2011/01/harmony-of-my-dreams/</link>
		<comments>http://brendaneich.com/2011/01/harmony-of-my-dreams/#comments</comments>
		<pubDate>Wed, 19 Jan 2011 01:02:43 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=554</guid>
		<description><![CDATA[Continuing in the vein of paren-free, I&#8217;d like to present a refreshed vision of JavaScript Harmony. This impressionist exercise is of course not canonical (not yet), but it&#8217;s not some random, creepy fanfic either. Something like this could actually happen, likelier and better if done with your help (more on how at the end). I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<style>
pre.coolright, pre.hotleft {
    margin-top: 0;
    margin-bottom: 20px;
}
p {
    clear: both !important;
}
</style>
<p>Continuing in the vein of <a href="/2010/11/paren-free/">paren-free</a>, I&#8217;d like to present a refreshed vision of <a href="https://mail.mozilla.org/pipermail/es-discuss/2008-August/003400.html">JavaScript Harmony</a>. This impressionist exercise is of course not canonical (not yet), but it&#8217;s not some random, creepy <a href="http://www.answers.com/main/ntquery?gwp=13&#038;s=fanfic">fanfic</a> either. Something like this could actually happen, likelier and better if done with your help (more on how at the end).</p>
<p>
I&#8217;m blurring the boundaries between Ecma TC39&#8242;s current consensus-Harmony, straw proposals for Harmony that some on TC39 favor, and my ideas. On purpose, because I think JS needs some new <a href="http://www.dreamsongs.com/Files/DesignedAsDesignerExpanded.pdf">conceptual integrity</a>. It does not need play-it-safe design-by-committee, either of the &#8220;let&#8217;s union all proposals&#8221; kind (which won&#8217;t fly on TC39), or a blind &#8220;let&#8217;s intersect proposals and if the empty set remains, so be it&#8221; approach (which also won&#8217;t fly, but it&#8217;s the likelier bad outcome).</p>
<p>
Anyway, it&#8217;s my blog, and my current dream. I hope you like it. Talk and dream back at me, and with any luck we&#8217;ll build a better Harmony-in-reality.</p>
<h2>little languages</h2>
<p>Calling JavaScript a little language is polite but false at this late date: <a href="http://wiki.ecmascript.org/lib/exe/fetch.php?id=start&#038;cache=cache&#038;media=resources:tc39-2010-062-rev5.doc">ES5.1</a> weighs in at over 100,000 words, with hundreds of nonterminals in the lexical and syntactic grammars.</p>
<p>
I would say that the same goes for <a href="http://jashkenas.github.com/coffee-script/">CoffeeScript</a>, although I get the point in its use of the phrase &#8220;little language&#8221;: concise expression-language sugar for the lever-arm, using JS-in-full as implemented in all browsers as the fulcrum, for maximum productivity leverage. CoffeeScript is well done and more convenient to use than JS, provided you buy into the Python-esque significant space and the costs of  generating JS from another source language. But semantically it&#8217;s still JS.</p>
<p>
Could JS evolve to be a better &#8220;little language&#8221; in both surface and substance? Implementors and users will impose some fuzzy but obvious and (past the fuzz) hard limits. JS can&#8217;t evolve directly into something too different. For instance, I believe JS implementors on TC39 would reject significant space instead of curly braces, or a mandatory bottom-up parser with disambiguation magic.</p>
<p>
Meanwhile, <a href="http://remysharp.com/2010/10/08/what-is-a-polyfill/">polyfills</a> such as CoffeeScript (when not run as a server-side code generator) may become more widely used, pushing JS in different directions. Still, it will be hard for polyfills to beat native code implementation, &lt;script&gt; tag prefetching, and the other built-into-every-browser advantages of pure JS.</p>
<p>
Whatever happens with polyfills, JS&#8217;s fitful progress over its life so far suggests that it can evolve further, and significantly. Such evolution requires growth in the short run, to solve the obvious web-imposed problem of backward compatibility.</p>
<h2>growing a language</h2>
<p>Maturing languages grow even without web-wide compatibility constraints, and JS is no exception. We should continue to <a href="http://www.google.com/url?sa=t&#038;source=web&#038;cd=1&#038;ved=0CBMQtwIwAA&#038;url=http%3A%2F%2Fvideo.google.com%2Fvideoplay%3Fdocid%3D-8860158196198824415&#038;rct=j&#038;q=growing%20a%20language%20guy%20steele&#038;ei=1AY0TeW5DI3SsAOZs_C2BQ&#038;usg=AFQjCNGQFOs3B18-QhIFHVEXEV54gPQFGw&#038;sig2=i4-HY3NLHTjgX9zma6yekA&#038;cad=rja">grow the language</a>, keeping support for old forms while adding new forms to help users themselves grow the language.</p>
<p>
That last link is to a video of Guy Steele&#8217;s famous talk. Here&#8217;s a cleaned-up <a href="http://labs.oracle.com/features/tenyears/volcd/papers/14Steele.pdf">transcript</a>. One quote:</p>
<blockquote><p>
If we add hundreds of new things to the Java programming language, we will have<br />
a huge language, but it will take a long time to get there. But if we add just a few<br />
things—generic types, overloaded operators, and user defined types of light weight, for<br />
use as numbers and small vectors and such—that are designed to let users make and add<br />
things for their own use, I think we can go a long way, and much faster. We need to put<br />
tools for language growth in the hands of the users.
</p></blockquote>
<p>Look past the Java specifics. This applies deeply to JS as well. Empowering users to grow the language is why <a href="#modules">modules</a>, <a href="/2010/11/proxy-inception/">proxies</a>, <a href="http://wiki.ecmascript.org/doku.php?id=strawman:binary_data">binary data</a>, and even an operators/literals/value-types <a href="http://wiki.ecmascript.org/doku.php?id=strawman:value_proxies">dark horse</a>, are high priorities for Harmony in my view. Which is not to say we shouldn&#8217;t add anything else. Because:</p>
<blockquote><p>
I hope that we can, in this way or some other way, design a programming language<br />
where we don’t seem to spend most of our time talking and writing in words of just one<br />
syllable.
</p></blockquote>
<p>You can do anything with <code>function</code> in JS, but you shouldn&#8217;t have to &#8212; it over-taxes JS programmers and VM implementors to learn and optimize all the idiomatic patterns. Too much like writing with only one-syllable words.</p>
<h2>grow to shrink</h2>
<p>If we do this right, Harmony&#8217;s <a href="http://www.sics.se/~seif/Publications/fdp.pdf">kernel semantics</a> do not grow inordinately in complexity. Then users merely have to choose to use the simpler new syntax over the old, and for those users (and possibly for everyone, many years hence &#8212; sooner, if you use a translator to &#8220;lower&#8221; Harmony to JS-as-it-is), JS is in fact more usable and smaller in its critical dimensions.</p>
<p>
Beyond users choosing to code in a subset, we could potentially shrink &#8212; or not grow, or grow less &#8212; the opt-in Harmony language by excluding misfeatures of &#8220;classic JS&#8221;. This was one of the ideas developed in <a href="/2010/11/paren-free/">paren-free</a> and some followup comments: no messy, underspecified, not-quite-interoperable <code>for (i in o)</code> loop, only <code>for i in o</code> loops, comprehensions, and generator expressions, to take one example. ES5 strict mode already removes <code>with</code>. Harmony already proposes to remove the global object as top-most scope, to pick a non-syntactic example.</p>
<p>
(Opt-in is required for Harmony because of new syntax. Yet developer brain-print conservation, existing code migration, shared-object-heap interoperation, and browser engine code re-use, all favor keeping Harmony &#8220;close&#8221; to JS-as-it-is. How close is the question. I&#8217;m in favor of pushing this envelope given the inertia of the standards setting and the conservatism of committees. Bear with me if you disagree.)</p>
<p>
On the web, the only way to shrink is to grow first. As I put it at <a href="/2010/07/a-brief-history-of-javascript/">jsconf.us</a> last year, provide better carrots to lead the horses away from the rotting vegetables, which can be cleaned up later.</p>
<h2>finding harmony</h2>
<p>Some of what&#8217;s below is <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proposals">already harmonious</a> according to TC39. Some is new, some is not yet proposed. The idea is to give an overview of Harmony that covers all of the high points and adds some new spice, instead of referring true believers to the sprawling <a href="http://wiki.ecmascript.org/doku.php?id=harmony:harmony">wiki</a> and then hoping they can figure things out from <a href="http://wiki.ecmascript.org/doku.php?do=recent&#038;id=">recent changes</a> and the <a href="https://mail.mozilla.org/listinfo/es-discuss/">discussion list</a>.</p>
<p>
Unlike the CoffeeScript docs, I&#8217;ll show JS as it is implemented today on the left, and Harmony-of-my-dreams code on the right. This emphasizes how we&#8217;re working to fill gaps in the language&#8217;s semantics, not simply add sugar that lowers from new syntax to old. There&#8217;s nothing wrong with <a href="http://en.wikipedia.org/wiki/Desugaring">desugaring</a>, and I believe CoffeeScript and other front ends for JS have a bright future, but TC39 is charged with evolving the core language, especially in ways that can&#8217;t be done efficiently or at all in today&#8217;s JS.</p>
<p>
With this context in mind, let&#8217;s dive in.</p>
<h2>binding and scope</h2>
<p>Block scoped <code>let</code> and <code>const</code>, not weird old hoisted (to top of function or script) <code>var</code>. Lexical scope all the way up, no global object on the scope chain. <a href="http://en.wikipedia.org/wiki/Free_variable">Free variables</a> are <a href="http://ecma262-5.com/ELS5_Section_16.htm">early errors</a>.</p>
<pre class="hotleft">
var still_hoisted = "alas"
var PRETEND_CONST = 3.14
function later(f, t, type) {
  setTimeout(f, t, typo) // oops...
}
</pre>
<pre class="coolright">
let block_scoped = "yay!"
const REALLY = "srsly"
function later(f, t, type) {
  setTimeout(f, t, typo) // EARLY ERROR
}
</pre>
<p>Removing the global <code>window</code> object from the scope chain doesn&#8217;t mean it won&#8217;t be available, though; see <a href="#modules"/>modules</a> below.</p>
<h2>functions</h2>
<p>[Presented in the spirit of the <a href="http://www-archive.mozilla.org/apology.html">Mozilla Apologator</a>:] I&#8217;m sorry for picking so long a keyword. Beyond the length of <code>function</code>, and for all the many wins of closures, the objects that result from evaluating function declarations and expressions have some very shaggy hair. Time for a trim, starting with syntax proposed by <a href="http://twitter.com/#!/ErikArvidsson">@Arv</a> and <a href="http://infrequently.org/">@Alex</a>, extended to work with binding keywords:</p>
<pre class="hotleft">
function add(a, b) { return a + b }
(function(x) { return x * x })
</pre>
<pre class="coolright">
const #add(a, b) { a + b }
#(x) { x * x }
</pre>
<p>The <code>#</code> character is one of few ASCII punctuators available. My straw polls on better characters to use has not led to a clear winner, and this one is proposed for Harmony. CoffeeScript&#8217;s <code>-&gt;</code> and <code>=&gt;</code> seem to require bottom-up parsing, so they&#8217;re not going to fly among implementors.</p>
<p>
Beyond syntax, notice how the braced body can end in an expression statement that evaluates to the implicit return value. And here&#8217;s another difference from functions: <code>#</code>-functions are immutable and <a href="http://wiki.ecmascript.org/doku.php?id=strawman:const_functions#joining">joined</a>.</p>
<p>
What to call these <code>#</code> functions? Ruby has given up <a href="http://blog.peepcode.com/tutorials/2011/rip-ruby-hash-rocket-syntax">hash rockets</a>. Can JS coin a new hash-phrase: hash-funcs? Suggestions welcome.</p>
<p>
We should not call these things <a href="http://wiki.ecmascript.org/doku.php?id=strawman:lambdas">lambdas</a>, as that drags in untenable <a href="http://gafter.blogspot.com/2006/08/tennents-correspondence-principle-and.html">Tennent&#8217;s Correspondence Principle</a> strangeness, such as <code>return</code> from a lambda returning from its enclosing function (if still active; otherwise you would get a <a href="https://mail.mozilla.org/pipermail/es-discuss/2008-December/008390.html">runtime error</a>).</p>
<h2>tail position</h2>
<p>The implicit return value does more than save six characters plus one space (relieving you of having to type <cod>return </code>), it also makes the last expression statement be in <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proper_tail_calls">tail position</a>. This contrasts with a JS function, which has an implicit <code>return undefined;</code> at the end of its body.</p>
<pre class="hotleft">
function cps(x) { not_tail(x) }
function cps_harder(x) {
  work(x)
  return tail(x)
}
</pre>
<pre class="coolright">
&nbsp;
const #cps_smarter(x) {
  work(x)
  tail()
}
</pre>
<p>At his <a href="http://jsconf.eu/2010/speaker/loopage_by_douglas_crockford.html">JSConf.eu talk</a> last fall, <a href="http://crockford.com/">@Crock</a> promoted the idea of <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proper_tail_calls">proper tail calls</a>, something we have wrestled with in TC39 since ES4 days. Tail calls are a feature of Scheme, providing an asymptotic space guarantee (in plain English, you can tail-call without growing the call stack inevitably to entrain the space for all args and vars active along the dynamic call chain).</p>
<p>
I agree with Doug that tail calls would be a win, especially with <a href="http://nodejs.org/">evented code</a>. The <code>#</code> function syntax allows us to give tail calls a boost and save you seven (14 total: <code>function</code> + <code>return_</code> - <code>#</code>) keystrokes.</p>
<p>
Some have objected that this creates an unintended <a href="https://mail.mozilla.org/pipermail/es5-discuss/2009-June/002822.html">completion value</a> leak-hazard, but (a) we can improve the Harmony definition of completion value in <code>#</code>-functions, (b) the <code>void</code> operator I added <a href="http://www.quora.com/Why-do-most-web-browsers-allow-the-execution-of-JavaScript-code-from-the-address-bar">for <code>javascript:</code> URLs</a>  back in '95 stands ready, and (c) when in doubt, use <code>function</code> syntax or write an explicit <code>return</code>.</p>
<h2>no arguments</h2>
<p>The <code>arguments</code> object is another <a href="http://www.aminutewithbrendan.com/pages/20101115">clump of hair</a> to trim from functions in adding hash-funcs. With Harmony, we have <a href="#rest_parameters">rest parameters</a>, so we don't need no steenking <code>arguments</code>!</p>
<pre class="hotleft">
(function () {
  return typeof arguments
})() == "undefined"
</pre>
<pre class="coolright">
#() {
  typeof arguments
}() == "undefined"
</pre>
<p>This haircut makes life simpler for web developers; it means even more to JS implementors.</p>
<h2>lexical this</h2>
<p>Another Tennent's Correspondence Principle casualty: <code>this</code> default binding. When you call <code>o.m()</code> in JS, unless <code>m</code> is a <a href="http://whereswalden.com/2010/09/07/now-in-spidermonkey-and-firefox-es5s-function-prototype-bind/">bound method</a>, <code>this</code> must bind to <code>o</code>. But for all functions in <a href="http://kangax.github.com/es5-compat-table/">ES5 strict mode</a>, and therefore in Harmony (based on ES5 strict), <code>this</code> is bound to <code>undefined</code> when the function is called by its lexical name (<code>f</code>, not <code>o.m</code> for <code>o.m=f</code>).</p>
<p>
Binding <code>this</code> to <code>undefined</code> censors the global object, a <a href="http://www.eecs.berkeley.edu/~jww/papers/2009/barth-weinberger-song.pdf">capability leak</a>. Apart from that fix, though, passing <code>undefined</code> as <code>this</code> is nearly useless.</p>
<p>
Why not bind <code>this</code> to the same value as in the code enclosing the hash-func? Doing so will greatly reduce the need for <code>var self=this</code> or <code>Function.prototype.bind</code>, especially with the <a href="https://developer.mozilla.org/en/new_in_javascript_1.6#Array_extras">Array extras</a>.</p>
<pre class="hotleft">
function writeNodes() {
  var self = this
  this.nodes.forEach(function(node) {
    self.write(node);
  }
}
</pre>
<pre class="coolright">
function writeNodes() {
&nbsp;
  this.nodes.forEach(#(node) {
    this.write(node);
  }
}
</pre>
<p>It's great that ES5 added <code>bind</code> as a standard method, but why should you have to call it all over the place? If Harmony does not address this issue, I will count that a failure.</p>
<h2>records</h2>
<p>A hot-button issue with ES5: <code>Object.freeze</code>. Whose side are you on, Batman's or Mr. Freeze's? Simplistic to say the least, since even in one's own small-world codebase, making some things immutable protects against mistakes. Never mind single- and multi-threaded data sharing and other upside.</p>
<p>
However, calling an <code>Object</code> method around every object initialiser you want frozen is a drag, and even then, the JS engine has to stand on its head and spin around to figure out that all the many evaluations of such an expression could be shared (but for the violation of object identity, detectable via <code>===</code> and <code>!==</code>, that sharing would create; but that could be optimized too, at some further expense).</p>
<p>
With <code>#</code> we can do better:</p>
<pre class="hotleft">
var point = {x: 10, y: 20}
point.equals({x: 10, y: 20})
</pre>
<pre class="coolright">
const point = #{x: 10, y: 20}
point === #{x: 10, y: 20}
</pre>
<p>Not only does the <code>#</code> <a href="http://en.wikipedia.org/wiki/Sigil_%28computer_programming%29">sigil</a> allow us to create records that are <a href="http://en.wikipedia.org/wiki/Hash_cons">hash-cons</a>'ed so there is only one object identity per nearest containing relevant closure; we also get <code>==</code> and <code>!=</code> (and the triple-equals forms) for free. Object content-based equality.</p>
<h2>tuples</h2>
<p>You may have noticed a trend here. Gaps in the JS language in usability, semantic unity of purpose, and reliability or invariance, can be made up for by adding "hash forms" that are shorter or still short enough, better for optimization, and free from mutation hazards and other historic hair. The same goes for <code>Arrays</code>, via <a href="http://en.wikipedia.org/wiki/Tuple">tuples</a>:</p>
<pre class="hotleft">
var tuple = [1, 2, 3]
tuple[tuple.length-1] === 3
Array.prototype.compare = /*...*/
tuple.slice(0, 2).compare([1, 2]) == 0
tuple.compare([1, 2, 4]) &lt; 0
</pre>
<pre class="coolright">
const tuple = #[1, 2, 3]
tuple[-1] === 3
&nbsp;
tuple[0:2] === #[1, 2]
tuple &lt; #[1, 2, 4]
</pre>
<p>Not only are the equality operators (strict and loose) based on contents and not object identity (which is not material due to the implicit freezing of these array-like objects), tuples support relational operators (<code>&lt; &lt;= &gt; &gt;=</code>), again based on contents not identity.</p>
<p>
Relationals could work on records too, using <a href="http://wiki.ecmascript.org/doku.php?id=strawman:enumeration">enumeration order</a> (assuming we standardize that order sanely).</p>
<p>
Negative indexing, something <a href="https://mail.mozilla.org/pipermail/es-discuss/2010-November/012126.html">unlikely</a> to be grafted onto <code>Array</code> in Harmony (see "shared-object-heap interoperation" point above), is more than a minor convenience in my book. It's also something Harmony <code>Proxy</code> handlers can implement. So tuples should support negative indexing even if arrays do not. And it ought to be cheap to create a tuple from an <code>Array</code> instance.</p>
<p>
If negative indexing works, can slices and ranges be far behind? I'll leave those for another post.</p>
<p>
<code>Array.prototype</code> is full of generic methods, most of which do not mutate <code>this</code>. It's tempting to want tuples to delegate to <code>Array.prototype</code>, with optimizations possible (as fast engines do today for dense-enough arrays). I'll throw this idea out and confess I haven't thought through every corner of it.</p>
<p>
One known bug in the <code>Array.prototype</code> methods that construct a new array object, e.g. <code>slice</code>: they always make an <code>Array</code> instance, instead of calling <code>new this.constructor</code>. I agree with <a href="http://infrequently.org/">@Alex</a> that we ought to fix this bug in Harmony.</p>
<h2>statements</h2>
<p>Here I recap <a href="/2010/11/paren-free/">paren-free</a>, which I have prototyped in <a href="https://github.com/mozilla/narcissus/">Narcissus</a> (invoked via <code>njs --paren-free</code>), but with an obvious and convenient extension:</p>
<pre class="hotleft">
if (x > y) alert("brace-free")
if (x > z) return "paren-full"
if (x > y) f() else if (x > z) g()
</pre>
<pre class="coolright">
if x > y { alert("paren-free") }
if x > z return "brace-free"
if x > y { f() } else if x > z { g() }
</pre>
<p>We do not want <code>else</code> clauses to be braced no matter what. In particular, an <code>if</code> statement as the <code>else</code> clause should not be braced, to avoid rightward indentation drift. Therefore any statement that starts with a keyword need not be braced. This is a boon for short <code>break</code>, <code>continue</code>, <code>return</code>, and <code>throw</code> statements often controlled by <code>if</code> heads that guard uncommon conditions.</p>
<h2><a name="modules">modules</a></h2>
<p>The <a href="http://wiki.ecmascript.org/doku.php?id=strawman:simple_modules">simple modules</a> proposal, along with its <a href="http://wiki.ecmascript.org/doku.php?id=strawman:module_loaders">module loaders</a> adjunct, is the likely Harmony module system solution. Note that there is no left-hand side example written in current JS below -- you'd need a preprocessor, not part of the language.</p>
<pre class="hotleft">
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
</pre>
<pre class="coolright">
module M {
  module N = "http://N.com/N.js"
  export const K = N.K
  export #add(x, y) { x + y }
}
</pre>
<p>Modules are being prototyped in <a href="https://github.com/mozilla/narcissus/">Narcissus</a> by <a href="http://blog.mozilla.com/dherman/">@little_calculist</a> right now. More on this at the end.</p>
<h2>iteration</h2>
<p>The impetus for <a href="/2010/11/paren-free/">paren-free</a> was the poor old <code>for-in</code> loop. I propose we break it utterly by requiring an unparenthesized head sporting implicit <code>let</code> binding, and the "always use the one true iteration protocol" semantics. Also, generators based on JS1.7, based on Python. All of this is pretty much as in Python, but built on proxies.</p>
<pre class="hotleft">
&nbsp;
&nbsp;
for (var k in o) append(o[k])
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
</pre>
<pre class="coolright">
module Iter = "@std:Iteration"
import Iter.{keys,values,items,range}
for k in keys(o) { append(o[k]) }
for v in values(o) { append(v) }
for [k,v] in items(o) { append(k, v) }
for x in o { append(x) }
#sqgen(n) { for i in range(n) yield i*i }
return [i * i for i in range(n)]
return (i * i for i in range(n))
</pre>
<p>Migrating <code>for-in</code> loops into Harmony will require saying what you mean.</p>
<p>
That <code>"@std:Iteration"</code>module resource locator is something I made up. It's an "anti-URL" since it starts with <code>@</code>. The idea is to be able to name built-in modules without having to write URLs, and without colliding with any possible URL. You could imagine <code>"@dom"</code> too.</p>
<h2><a name="rest_parameters">rest parameters</a></h2>
<p>Instead of the bad-smelling <code>arguments</code> object, Harmony boasts <a href="http://wiki.ecmascript.org/doku.php?id=harmony:parameter_default_values">parameter default values</a> (not shown here) and <a href="http://wiki.ecmascript.org/doku.php?id=harmony:rest_parameters">rest parameters</a>.</p>
<pre class="hotleft">
function printf(format) {
  var args = Array.prototype.slice
                  .call(arguments,1)
&nbsp;
  /* use args as a real array here */
}
</pre>
<pre class="coolright">
function printf(format, ...args) {
  /* use args as a real array here */
}
&nbsp;
&nbsp;
&nbsp;
</pre>
<p>With hash-funcs, default parameter values and rest parameters are all you get -- no more <code>arguments</code>.</p>
<p>
Should tuples become harmonious, the question arises: how does a rest parameter reflect, as an array or as a tuple? The answer may depend on how important it is to <code>splice</code>, <code>reverse</code>, or <code>sort</code> a rest parameter. VM implementors would love the frozen tuple answer. Most JS hackers who cared would, I suspect, favor array over tuple here.</p>
<h2>spread</h2>
<p>A companion to rest parameters, the spread syntax allows one to expand an array's elements as positional parameters or <a href="http://bclary.com/2004/11/07/#a-11.1.4">array initialiser</a> elements. Finally you can write a generic constructor-invoking helper without using <code>switch</code> and <code>eval</code>:</p>
<pre class="hotleft">
function construct(f, a) {
  switch (a.length) {
    case 0: return new f
    case 1: return new f(a[0])
    case 2: return new f(a[0], a[1])
    default:
      var s = "new f("
      for (var i = 0; i < a.length; i++)
       s += "a[" + i + "],"
     s = s.slice(0, -1) + ")"
     return eval(s)
  }
}
</pre>
<pre class="coolright">
function construct(f, a) {
  return new f(...a)
}
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
</pre>
<p>Even without the 0, 1, and 2 special cases, this significant savings in lines screams "semantic gap being filled!"</p>
<p>
UPDATE: <a href="http://erights.org/">@markm</a> emailed to remind me that ES5 fills the gap part-way, at the price of a bound function:</p>
<pre class="hotleft">
function construct(f, a) {
  var ctor = Function.prototype.bind
             .apply(f, [null].concat(a))
  return new ctor();
}
</pre>
<pre class="coolright">
function construct(f, a) {
  return new f(...a)
}
&nbsp;
&nbsp;
</pre>
<p>ES5 helps, but I think it is time to prototype Harmony's <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=574130">spread</a> for Firefox.next.</p>
<h2>destructuring</h2>
<p>Often in JS you'll find yourself unpacking the properties of an object into same-named variables. Destructuring binding and assignment (prototyped since 2006 in JS1.7 in Firefox) fill this gap:</p>
<pre class="hotleft">
var first = sequence[0],
    second = sequence[1]
var name = person.name,
    address = person.address
    // no easy misc solution
&nbsp;
</pre>
<pre class="coolright">
let [first, second] = sequence
&nbsp;
const {name, address, ...misc} = person
&nbsp;
&nbsp;
</pre>
<p>The destructuring patterns mimic object and array initialisers, and raise the possibility of <a href="http://www.haskell.org/tutorial/patterns.html">refutable matching</a> in JS.</p>
<h2>library missing links</h2>
<p><a href="http://wiki.ecmascript.org/doku.php?id=strawman:array_create"><code>Array.create</code></a>, <a href="http://wiki.ecmascript.org/doku.php?id=strawman:name_property_of_functions"><code>Function.create</code></a> (like <code>Function</code> but with a leading <code>name</code> parameter), <a href="http://wiki.ecmascript.org/doku.php?id=strawman:binary_data">binary data</a>, <a href="/2010/11/proxy-inception/">proxies</a>, and <a href="http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps">weak maps</a>.</p>
<pre class="coolright" style="width: 610px">
Array.create(proto, [1, 2, 3]) // see also Array.createConstructor

Function.create(name, ...params, body);

const Point2D = new StructType({ x: uint32, y: uint32 });
const Color = new StructType({ r: uint8, g: uint8, b: uint8 });
const Pixel = new StructType({ point: Point2D, color: Color });
const Triangle = new ArrayType(Pixel, 3);

Proxy.create(handler, proto)
Proxy.createFunction(handler, call, construct)

const map = WeakMap()
map.set(obj, value)
</pre>
<p>These are just the big dogs in the Harmony standard library kennel, but worth some attention.</p>
<p>
In particular, proxies really want weak maps. Weak maps are something JS has needed for ages in general. Have you ever kept objects in an array and searched by object identity, or else mutated objects to assign hashcodes to them? No more.</p>
<p>
Binary data looks insanely useful, and we hope it will supplant WebGL typed arrays in due course.</p>
<h2>closing</h2>
<p>This is a long post. If you made it this far and take away anything, I hope it is Guy's "Growing a Language" meta-point. JS will be around for a very long time, and it has a chance to evolve until its users can replace TC39 as stewards of its growth. The promised land would be <a href="http://www.cs.indiana.edu/~dyb/pubs/LaSC-5-4-pp295-326.pdf">macros</a>, for syntactic abstraction and extensibility. I am not holding my breath, but even without macros, the Harmony-of-my-dreams sketched here would be enough for me.</p>
<p>
We aim to do more than dream. <a href="https://github.com/mozilla/narcissus/">Narcissus</a> is coming along nicely since it moved to github and got a shot in the arm from our excellent Mozilla Research interns last summer. We are prototyping Harmony in Narcissus (invoked via <code>njs -H</code>), so you can run it as an alternate &lt;script&gt; engine via the <a href="https://mozillalabs.com/zaphod/">Zaphod</a> Firefox add-on.</p>
<p>
<a href="http://andreasgal.wordpress.com/">@andreasgal</a> has a JS code generator for Narcissus in the works, which promises huge speedups compared to the old metacircular interpreter I wrote for fun in 2004. With good performance, we can actually do some usability studies of Harmony proposals, and avoid Harmony-of-our-nightmares: untested, hard-to-use committee designs.</p>
<p>
A code-generating Narcissus has other advantages than performance. Migrating code into Harmony, what with the removal of the global object as top scope (never mind the other changes I'm proposing -- here's another one: <a href="http://wiki.ecmascript.org/doku.php?id=strawman:object_isobject">let's fix typeof</a>), needs automated checking and even code rewriting. <a href="http://doctorjs.org/">DoctorJS</a> uses a static analysis built on top of Narcissus, which could be used to find flaws, not just migration changes. Self-hosted parsing, JS-to-JS code generation, and <a href="/2010/08/static-analysis-ftw/">powerful static analysis</a> come together to make a pretty handy Harmonizer tool. So we're going to build that, too.</p>
<p>
More on Narcissus and Zaphod as they develop. When the time is right, we will need users -- lots of them. As always, your comments are welcome.</p>
<p>
/be</p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2011/01/harmony-of-my-dreams/feed/</wfw:commentRss>
		<slash:comments>79</slash:comments>
		</item>
		<item>
		<title>Paren-Free</title>
		<link>http://brendaneich.com/2010/11/paren-free/</link>
		<comments>http://brendaneich.com/2010/11/paren-free/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 08:36:33 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=428</guid>
		<description><![CDATA[The tl;dr version &#60;Krusty&#62;So, you kids want CoffeeScript, do you?&#60;/Krusty&#62; &#60;script type="harmony"&#62; // placeholder MIME type if year &#62; 2010 { syntax++ } for i in iter { // i is a fresh let binding! frob(i) } while lo &#60;= hi { let mid = (lo + hi) / 2 // binary search blah blah [...]]]></description>
			<content:encoded><![CDATA[<h2>The <b>tl;dr</b> version</h2>
<p><img src="/brendaneich_content/uploads/krustygetskancelled7.png"></p>
<p>&lt;<a href="http://en.wikipedia.org/wiki/Krusty_Gets_Kancelled">Krusty</a>&gt;So, you kids want <a href="http://jashkenas.github.com/coffee-script/">CoffeeScript</a>, do you?&lt;<a href="http://deadhomersociety.wordpress.com/tag/krusty-gets-kancelled/">/Krusty</a>&gt;</p>
<pre>
&lt;script type="harmony"&gt;   // placeholder MIME type

if year &gt; 2010 {
    syntax++
}

for i in iter {           // i is a fresh let binding!
    frob(i)
}

while lo &lt;= hi {
    let mid = (lo + hi) / 2
    // binary search blah blah blah
}

... return [i * i for i in range(n)]   // array comprehension

&lt;/script&gt;
</pre>
<p>No parentheses around control structure &#8220;heads&#8221;. If <a href="http://golang.org/">Go</a> can do it, so can JS. And yes, I&#8217;m using automatic semi-colon insertion (JSLint can suck it).</p>
<p>There are open issues (are braces required around bodies?) but this is the <a href="http://twitter.com/#!/BrendanEich">twitter</a>-friendly section. More below, after some twitter-unfriendly motivation.</p>
<h2>Background</h2>
<p>We had a <a href="http://www.ecma-international.org/memento/TC39.htm">TC39</a> meeting last week, graciously hosted at <a href="http://www.apple.com/">Apple</a> with <a href="http://twitter.com/#!/ohunt">Ollie</a> representing. Amid the many productive activities, <a href="http://blog.mozilla.com/dherman/">Dave</a> presented <a href="http://wiki.ecmascript.org/doku.php?id=strawman:iterators">iterators</a> as an extension to <a href="/2010/11/proxy-inception/">proxies</a>.</p>
<p>The good news is that the committee agreed that some kind of <a href="http://en.wikipedia.org/wiki/Metaprogramming">meta-programmable</a> <a href="http://en.wikipedia.org/wiki/Iteration">iteration</a> should be in the language.</p>
<h3>Enumeration</h3>
<p>Proxies had already moved to <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proposals">Harmony Proposal</a> status earlier this year, but with an open issue: how to trap <code>for (i in o)</code> where <code>o</code> is a proxy with a huge (or even an infinite &#8212; rather, a lazily created and indefinite) number of properties.</p>
<pre>
js> var handler = {
    enumerate: function () { return ["a", "b", "c"]; }
};
js> var proxy = Proxy.create(handler);
js> for (var i in proxy)
    print(i);
a
b
c
</pre>
<p>The proxy handler&#8217;s fundamental <code>enumerate</code> trap eagerly returns an array of all property names &#8220;in&#8221; the proxy, coerced to string type if need be. Each string is required to be unique in the returned array. But for a large or lazy object, where the trapping loop may break early, eagerness hurts. Scale up and eagerness (never mind the uniqueness requirement) is fatal. TC39 agreed that a lazy-iteration derived (optional) trap was wanted.</p>
<pre>
js> var handler = {
    iterate: function () { for (var i = 0; i < 1e9; i++) yield i; }
};
js> var proxy = Proxy.create(handler);
js> for (var i in proxy) {
    if (i == 3) break;
    print(i);
}
0
1
2
</pre>
<p>The <a href="http://wiki.ecmascript.org/doku.php?id=strawman:iterators">iterators strawman</a> addressed this use-case by proposing that <code>for-in</code> would trap to <code>iterate</code> if present on the handler for the proxy referenced by <code>o</code>, in preference to trapping to <code>enumerate</code>.</p>
<pre>
js> var handler = {
    enumerate: function () { return ["a", "b", "c"]; },
    iterate: function () { for (var i = 0; i < 1e9; i++) yield i; }
};
js> var proxy = Proxy.create(handler);
js> for (var i in proxy) {
    if (i == 3) break;
    print(i);
}
0
1
2
</pre>
<p>To avoid switching from enumeration to iteration under a single <code>for-in</code> loop, once the loop has started enumerating a non-proxy, if a proxy is encountered on that object&#8217;s prototype chain, the prototype proxy&#8217;s <code>enumerate</code> trap will be used, not its <code>iterate</code> trap.</p>
<pre>
js> var handler = {
    has: function (name) { return /^[abc]$/.test(name); },
    enumerate: function () { return ["a", "b", "c"]; },
    iterate: function () { for (var i = 0; i < 1e9; i++) yield i; }
};
js> var proxy = Proxy.create(handler);
js> var obj = Object.create(proxy);
js> for (var i in obj) {
    print(i);
}
a
b
c
</pre>
<p>Enumeration walks the prototype chain, and this is why a proxy might want both <code>enumerate</code> and <code>iterate</code>.</p>
<h3>Iteration</h3>
<p>What all this means: you can implement Pythonic iterators with proxies, and return a sequence of arbitrary values to a <code>for-in</code> loop that&#8217;s given the proxy directly (not on a prototype chain of a non-proxy object, as noted above). A large/lazy proxy would trap <code>iterate</code> instead of <code>enumerate</code> and return string keys, but other iterator-proxies could return Fibonacci numbers, integer ranges, or whatever the proxy implementor and consumer want. This was an intended part of the package deal.</p>
<pre>
js> function fib(n) {
    var i = 0;
    var a = 0, b = 1;
    return {
        next: function () {
            if (++i > n)
                throw StopIteration;
            [a, b] = [b, a + b];
            return a;
        }
    };
}
js> var handler = {iterate: function () { return fib(10); } };
js> var proxy = Proxy.create(handler);
js> for (var i in proxy)
    print(i);
1
1
2
3
5
8
13
21
34
55
</pre>
<p>(<a href="https://developer.mozilla.org/en/New_in_Javascript_1.7">JS1.7</a> and above, implemented in both SpiderMonkey and Rhino, prefigured this proposal by supporting an unstratified iteration protocol based on Python 2.5. This JS1.7 <code>Iterator</code> extension is fairly popular in spite of some design flaws, and from the exercise of implementing and shipping it we&#8217;ve recognized those flaws and fixed them via proxies combined with the iterators strawman.)</p>
<p>The bad news is that the committee did something committees often do: try to compromise between divergent beliefs or subjective value theories.</p>
<p>In this case the compromise was based on the belief that <code>for-in</code> should not become the wanted meta-programmable iteration syntax. The argument is that <code>for-in</code> must always visit string-typed keys of the object, or at least whatever strings the accepted proxy <code>enumerate</code> trap returns in an array. If a Harmony proxy could somehow be enumerated by pre-Harmony <code>for-in</code>-based code, non-string values in the iteration might break the old code.</p>
<p>(The counter-argument is that once you let the proxy handler trap <code>enumerate</code>, a lot can change behind the back of old <code>for-in</code>-based code; also, enumeration is an underspecified mess. But these points do not completely overcome the objection about potential breakage in old code.)</p>
<h3>Fear of Change</h3>
<p>To fend off such breakage, we could make <code>for-in</code> meta-programmable only in Harmony code &#8212; any loop loaded under a pre-Harmony script tag type would not iterate a proxy.</p>
<p>This opt-in protection probably does not resolve the real issue, which is whether syntax can have its semantics changed much (or at all) in a mature language such as JS, which is being evolved via mostly-compatible standard versions in multi-year cycles.</p>
<p>I acknowledged during the meeting that we would not make progress without trying to agree on new syntax. This was too optimistic but I wanted to discover more about the divergent beliefs that made extending <code>for-in</code> via proxies a showstopper.</p>
<p>A quick whip-round the room with an empty cup managed to net us loose change from latter-day Java and C++:</p>
<pre>
for (var i : x)   // or let i, or just i for any lvalue i
     ...
</pre>
<p>as our meta-programmable &#8220;new syntax&#8221;. Bletch!</p>
<p>Not to worry. For-colon is probably not going to fly for some reasons I raised on <a href="https://mail.mozilla.org/pipermail/es-discuss/2010-November/012189.html">es-discuss</a>, but it also should die a deserved death as a classic bad compromise forged in the heat of a committee meeting.</p>
<p>The difficulty before us is precisely this how-much-to-change question.</p>
<p>ES5 strict mode already changes runtime semantics for existing syntax (<code>eval</code> of <code>var</code> no longer pollutes the caller&#8217;s scope; <code>arguments</code> does not alias formal parameters;  a few others), for the better. Unfortunately, developers porting to <code>"use strict"</code> must test carefully, since these are meaning shifts, not new early errors.</p>
<p>My point is that syntactic and semantic change has happened over the last 15 years of JS, it is happening now with ES5 strict, and it will happen again.</p>
<h3>Change is Coming</h3>
<p>We believe that future JS, the Harmony language, must include at least one incompatible change to runtime semantics: no more global object at the top of the scope chain. Instead, programmers would have lexical scope all the way up, with the <a href="http://wiki.ecmascript.org/doku.php?id=strawman:simple_modules">module system</a> for populating the top scope. By default, the standard library we all know would be imported; also by default in browsers, the DOM would be there.</p>
<p>Can the world handle another incompatible change to the semantics of existing syntax, namely the <code>for-in</code> loop?</p>
<p>There are many trade-offs.</p>
<p>On the one hand, adding new syntax ensures no existing code will ever by confused, even if migrated into Harmony-type script. On the other, adding syntax hurts users and implementors in ways that combine to increase the complexity of the language non-linearly. The chances for failure to standardize and mistakes during standardization go up too.</p>
<p>What&#8217;s more, it will be a long time before anyone can use the new syntax on the web, whereas <code>for-in</code> and proxies implementing well-behaved iterators could be used much sooner, with fallback <code>if (!window.Proxy)</code>.</p>
<p>Utlimately, it&#8217;s a crap shoot:</p>
<ul>
<li>Play it safe, enlarge the language, freeze (and finally standardize, ahem) the semantics of the old syntax, and try to move users to the new syntax? or
<li>Conserve syntax, enable developers to reform the <code>for-in</code> loop from its enumeration-not-iteration state?
</ul>
<p>All this is prolog. Perhaps the &#8220;play it safe&#8221; position is right. And more important, what if new syntax could be strictly more usable <i>and</i> have better semantics?</p>
<h2>New Clothes and Body</h2>
<p>Here&#8217;s my pitch: committees do not design well, period. Given a solid design, a committee with fundamental disagreements can stall or eviscerate that design out of conservatism or just nay-saying, until the proposal is hardly worth the trouble. At best, the language grows larger more quickly, with conservative add-ons instead of holistic rethinkings.</p>
<p>I&#8217;m to blame for some of this, since I&#8217;ve been playing the standards game with JS. Why not? It seems to be working, and the alternatives (<a href="http://wiki.mozilla.org/Tamarin:ScreamingMonkey">ScreamingMonkey</a>, <a href="http://www.aminutewithbrendan.com/pages/20101122">another language getting into all browsers</a>) are nowhere. But I observe that even for Harmony, and notably for ES5, much of the innovation came before the committee got together (getters, setters, <code>let</code>, destructuring). Other good parts of ES5 and emerging standards came from strong individual or paired designers (<a href="http://twitter.com/#!/awbjs">@awbjs</a>, <a href="http://erights.org/">@markm</a>, <a href="http://twitter.com/#!/tomvc">@tomvc</a>).</p>
<p>And don&#8217;t get me wrong: sometimes saying &#8220;no&#8221; is the right thing. But in a committee tending a mature but still living programming language, it&#8217;s too easy to say &#8220;no&#8221; without any &#8220;but here&#8217;s a better way&#8221; follow-through. To be perfectly clear, TC39 members generally do provide such follow-through. But we are still a committee.</p>
<p>I want to break out of this inherently clog-prone condition.</p>
<p>So, given the concern about changing the meaning of <code>for-in</code>, and the rise of wrist-friendly &#8220;unsyntax&#8221; (Ruby, Python, CoffeeScript) over the shifted-keystroke-burdened C-family syntax represented by JS, why not make opting into Harmony enable new syntax with the desired meta-programmable semantics?</p>
<h3>Paren-Free Heads</h3>
<p>It would be a mistake to change syntax (and semantics) utterly. VM implementors and web developers having to straddle both syntaxes would rightly balk. There will be commerce between Harmony and pre-Harmony scripts, via the DOM and the shared JS object heap. But can we <i>relax</i> syntactic rules a bit, and lose two painfully-shifted, off-QWERTY-home-row characters, naming <code>()</code> in control structure heads?</p>
<pre>
for i in iter {
    // i is a value of any type;
}
</pre>
<p>Here&#8217;s your new syntax with new semantics!</p>
<p>We can simplify the iterator strawman too. If you want to iterate and not enumerate, use the new syntax. If you want to iterate keys (both &#8220;own&#8221; and any enumerable unshadowed property names on prototypes), use a helper function:</p>
<pre>
for i in keys(o) {
    // i is a string-typed key
}
</pre>
<p>The old-style <code>for (var i in o)...</code> loop only traps to <code>enumerate</code>. Large/lazy proxies? Use the new <code>for k in keys(o) {...}</code> form.</p>
<p>Are the braces required? C has parenthesized head expressions and unbraced single-statement bodies. Without parens, a C statement such as</p>
<pre>
if x
    (*pf)(y);
</pre>
<p>would be ambiguous (don&#8217;t try significant newlines on me &#8212; I&#8217;ve learned my lesson :-/). You need to mandate either parens around the head, or braces around the body (or both, but that seems like overkill).</p>
<p>So C requires parens around head expressions. But many style guides recommend always bracing, to ward off <a href="http://en.wikipedia.org/wiki/Dangling_else">dangling else</a>. Go codifies this fully, requiring braces but relieving programmers from having to parenthesize the head expression.</p>
<p>I swore I&#8217;d never blog at length about syntax, but here I am. Syntax matters, it&#8217;s programming language UI. Therefore it needs to be improved over time. JS is overdue for an upgrade. So my modest proposal here is: lose the head parens, require braces always.</p>
<p>You could argue for optional braces if there&#8217;s no particular ambiguity, e.g.</p>
<pre>
if foo
    bar();
</pre>
<p>But that will be a hard spec to write, a confusing spec to read, and educators and gurus will teach &#8220;always brace&#8221; anyway. Better to require braces.</p>
<p>Pythonic significant whitespace is too great a change, and bad for minified/crunched/mangled web scripts anyway. JS is a curly-brace language and it always will be.</p>
<h3>Implicit Fresh Bindings</h3>
<p>Another win: the position between <code>for</code> and <code>in</code> is implicitly a <code>let</code> binding context. You can <a href="http://wiki.ecmascript.org/doku.php?id=harmony:destructuring">destructure</a> there too, but whatever names you bind, they&#8217;ll be fresh for each iteration of the loop.</p>
<p>This allows us to solve an old and annoying closure misfeature of JS:</p>
<pre>
js> function make() {
    var a = [];
    for (var i = 0; i < 3; i++)
        a.push(function () { return i; });
    return a;
}
js> var a = make();
js> print(a[0]());
3
js> print(a[1]());
3
js> print(a[2]());
3
</pre>
<p>Changing <code>var</code> to <code>let</code> in the C-style three-part <code>for</code> loop does not help.</p>
<p>But <code>for-in</code> is different, and in Harmony we (TC39) believe it should make a fresh <code>let</code> binding per iteration. I&#8217;m proposing that the <code>let</code> be implicit and obligatory. And of course the head is paren-free, so the full fix looks like this:</p>
<pre>
js> function make() {
    var a = [];
    for i in range(3) {
        a.push(function () { return i; });
    }
    return a;
}
js> var a = make();
js> print(a[0]());
0
js> print(a[1]());
1
js> print(a[2]());
2
</pre>
<p>Part of the Zen of Python: &#8220;Explicit is better than implicit.&#8221; Of course, Python has implicit block-scoped variable declarations, so this is more of a guideline, or a Zen thing, not some Western-philosophical absolute <img src='http://brendaneich.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Having to declare an outer or global name in Python is therefore an exception, and painful. Like the sound of one hand slapping your face.</p>
<p>Of course JS shouldn&#8217;t try to bind block-scoped variables implicitly all over the place, as Python does; once again, that would be too great a change. But implicit <code>for-in</code> loop <code>let</code>-style variable declaration is winning both as sensible default, and to promulgate the closure-capture fix.</p>
<h3>Comprehensions</h3>
<p>When we implemented iterators and generators in JS1.7, I also threw in <a href="https://developer.mozilla.org/en/New_in_Javascript_1.7#Array_comprehensions_%28Merge_into_Array_comprehensions%29">array comprehensions</a>:</p>
<pre>
js> squares = [i * i for (i in range(10))];
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
js> odds = [i for (i in range(20)) if (i % 2)]
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
</pre>
<p>At first I actually implemented paren-free heads for the <code>for-in</code> parts in the square brackets, but when I got to the optional trailing <code>if</code> I balked. Too far from JS, and in practical terms, a big-enough refactoring speed-bump for anyone sugaring a <code>for-in</code> loop as a comprehension. But paren-free Harmony rules:</p>
<pre>
js> squares = [i * i for i in range(10)];
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
js> odds = [i for i in range(20) if i % 2]
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
</pre>
<p>The same win applies to <a href="https://developer.mozilla.org/en/new_in_javascript_1.8#Generator_expressions_%28Merge_into_Generator_expressions%29">generator expressions</a>.</p>
<h2>Thanks</h2>
<p>Thanks to TC39 colleagues for their general excellence &#8212; we&#8217;re a committee but I&#8217;ll try not to hold that against any of us.</p>
<p>Thanks especially to <a href="http://infrequently.org/">@AlexRussell</a> and <a href="http://twitter.com/#!/ErikArvidsson">@arv</a>, who at last week&#8217;s meeting brought some attitude about improving syntax and semantics in Harmony that I fought at first (for fear of the committee opening up all design and compatibility constraints and failing to reach Harmony). Their attitude stimulated me to think outside the box, and outside the parens.</p>
<p>Some of you may be thinking &#8220;this is crazy!&#8221; Others of you will no doubt say &#8220;more! more!&#8221; I have some other thoughts, inspired by TC39 conversations, that could help make Harmony a better language without it being over-compatible warm beer, but I&#8217;ll save them for another post.</p>
<p>My point here is not to rush another syntax strawman through TC39, but to stimulate thinking. I&#8217;m serious about paren-free FTW, but I&#8217;m more serious about making Harmony better through judicious and holistic re-imaginings, not only via stolid committee goal-tending.</p>
<p>/be</p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2010/11/paren-free/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Proxy Inception</title>
		<link>http://brendaneich.com/2010/11/proxy-inception/</link>
		<comments>http://brendaneich.com/2010/11/proxy-inception/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 08:42:28 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=345</guid>
		<description><![CDATA[After marinating for a few months, my JSConf.eu slides: Proxies are Awesome! (Mobile/No-Flash version) These are based directly on the excellent work of Mark Miller and Tom Van Cutsem, who developed the harmony:proxies proposal that is now approved for the next major iteration of the JavaScript standard (ECMA-262, probably edition 6 but we&#8217;ve learned the [...]]]></description>
			<content:encoded><![CDATA[<p>After marinating for a few months, my <a href="http://jsconf.eu/">JSConf.eu</a> slides:</p>
<div id="__ss_5303821" style="width: 640px;"><strong style="display: block; margin: 12px 0 4px;"><a title="Proxies are Awesome!" href="http://www.slideshare.net/BrendanEich/metaprog-5303821">Proxies are Awesome!</a></strong><object id="__sse5303821" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="535" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=metaprog-100928014929-phpapp01&amp;stripped_title=metaprog-5303821&amp;userName=BrendanEich" /><param name="name" value="__sse5303821" /><param name="allowfullscreen" value="true" /><embed id="__sse5303821" type="application/x-shockwave-flash" width="640" height="535" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=metaprog-100928014929-phpapp01&amp;stripped_title=metaprog-5303821&amp;userName=BrendanEich" name="__sse5303821" allowscriptaccess="always" allowfullscreen="true"></embed></object>
</div>
<p>(<a href="http://www.slideshare.net/mobile/BrendanEich/metaprog-5303821">Mobile/No-Flash version</a>)</p>
<p>These are based directly on the excellent work of Mark Miller and Tom Van Cutsem, who developed the <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proxies">harmony:proxies</a> proposal that is now approved for the next major iteration of the JavaScript standard (ECMA-262, probably edition 6 but we&#8217;ve learned the hard way not to number prematurely &#8212; anyway, approved for &#8220;<a href="http://wiki.ecmascript.org/doku.php?id=harmony:harmony">ECMAScript Harmony</a>&#8221; [<a href="https://mail.mozilla.org/pipermail/es-discuss/2008-August/003400.html">my original Harmony-coining post</a>]).</p>
<p>Harmony Proxies are already prototyped in Firefox 4 betas, thanks to <a href="http://andreasgal.com/">Andreas Gal</a>.</p>
<p>When I reached the &#8220;meta-level shifting&#8221; slide:</p>
<div>
<img src="/brendaneich_content/uploads/meta-level-shifting.png" alt="meta-level shifting" height="480" width="640" />
</div>
<p>someone in the audience tweeted about how my talk was like <a href="http://www.imdb.com/title/tt1375666/">Inception</a> (<a href="https://github.com/karthick18/inception/">github-sourced simulator</a>). Meta-meta dreams within dreams (warning: meta-to-the-4th-shifting leads to Limbo).</p>
<div>
<img src="/brendaneich_content/uploads/cobb-salad.jpg" alt="Cobb Salad" /> (h/t <a href="http://twitter.com/#!/jedschmidt">@jedschmidt</a>)
</div>
<p>The money-shot slide in my view is:</p>
<div>
<img src="/brendaneich_content/uploads/selective-interception.png" height="480" width="640" />
</div>
<p>which depicts how Proxies finally level the playing field between browser implementors using burned-into-browser-binaries C++ and web developers using downloaded JS.</p>
<p>It&#8217;s hard to overstate how this matters. The DOM (IE&#8217;s for sure, but all of them, back to the original I hacked in Netscape 2) suffers from its &#8220;VM territory&#8221; privileges, which have been abused to make all kinds of odd-ball &#8220;host objects&#8221;. Proxies both greatly reduce the weirdness of host objects and let JS hackers emulate and even implement such objects.</p>
<p>Novice JS hackers and all JS programmers happy at the base level of the language need not worry about the details of Proxies. Proxies cannot break the invariants that keep the JS lucid dream unfolding on stage. Specifically, you can&#8217;t hack traps onto an existing non-proxy object &#8212; you can only create a new proxy and start using it afresh, perhaps passing it off as a preexisting kind of object that it emulates [1].</p>
<p>But when you need to go backstage of the dream and change the rules without breaking the dreamer&#8217;s illusion, by interceding on every <code>get</code>, <code>set</code>, <code>call</code>, <code>construct</code>, etc., then Proxies are indispensable.</p>
<p>Firefox 4 is using Proxies to implement all of its <a href="https://developer.mozilla.org/en/XPConnect_security_membranes">security wrappers</a>.</p>
<p>Long-time SpiderMonkey fans will ask &#8220;why no <code>__noSuchMethod__</code>&#8221; (or: why not also have a <code>noSuchMethod</code> or <code>invoke</code> trap, or a flag to <code>get</code> telling when it is trapping a get for the entire callee part of a call expression)? The short answer is to keep the set of handler traps minimal in terms of JS semantics (modulo scalability), which do not include &#8220;invoke-only methods&#8221;. The <a href="https://mail.mozilla.org/pipermail/es-discuss/2010-October/011929.html">longer answer</a> is on <a href="https://mail.mozilla.org/listinfo/es-discuss">es-discuss</a>.</p>
<p>/be</p>
<p>[1] Inside the engine, a clever trick from Smalltalk called <code>becomes</code> is used to <a href="http://mxr.mozilla.org/mozilla-central/search?string=JSObject::swap&#038;find=jsobj.cpp">swap</a> a newborn Proxy and an existing object that has arbitrarily many live references. Thus an object requiring no behavioral intercession can avoid the overhead of traps until it escapes from a same-origin or same-thread context, and only if it does escape through a barrier will it become a trapping Proxy whose handler accesses the original object after performing access control checks or mutual exclusion.</p>
<p>The local jargon for such object/Proxy swapping is <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=580128">&#8220;brain transplants&#8221;</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2010/11/proxy-inception/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Should JS have bignums?</title>
		<link>http://brendaneich.com/2010/10/should-js-have-bignums/</link>
		<comments>http://brendaneich.com/2010/10/should-js-have-bignums/#comments</comments>
		<pubDate>Sat, 16 Oct 2010 17:27:02 +0000</pubDate>
		<dc:creator>Brendan Eich</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://brendaneich.com/?p=358</guid>
		<description><![CDATA[jwz finally learns some JS and picks at an old scab that had almost healed. I reply in various comments. I include some little-known, kind-of-funny (not always ha-ha funny) history along the way to set several records straight. The issue before us now is whether to add value types to JS, perhaps by extending proxies, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jwz.org/">jwz</a> finally learns some JS and <a href="http://jwz.livejournal.com/1307198.html">picks</a> at an old scab that had almost healed. I reply in various comments. I include some little-known, kind-of-funny (not always ha-ha funny) history along the way to set several records straight.</p>
<p>The issue before us now is whether to add <a href="http://wiki.ecmascript.org/doku.php?id=strawman:value_types">value types</a> to JS, perhaps by <a href="http://slang.soe.ucsc.edu/cormac/proxy.pdf">extending</a> <a href="http://wiki.ecmascript.org/doku.php?id=harmony:proxies&#038;s=proxies+cormac">proxies</a>, so you can implement non-reference-semantics objects with operators (because <a href="http://jroller.com/cpurdy/entry/the_seven_habits_of_highly1">without operators</a>, what&#8217;s the point?); or just add <a href="http://wiki.ecmascript.org/doku.php?id=strawman:bignums">bignums</a>; or do nothing.</p>
<p>Comments welcome (to keep up with Akismet-gaming spammers &#8212; anyone have a better WP plugin to stop comment spam?).</p>
<p>/be</p>
]]></content:encoded>
			<wfw:commentRss>http://brendaneich.com/2010/10/should-js-have-bignums/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

