<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: JavaScript Needs Blocks</title>
	<atom:link href="http://yehudakatz.com/2012/01/10/javascript-needs-blocks/feed/" rel="self" type="application/rss+xml" />
	<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/</link>
	<description>Random Geek-Related Thoughts</description>
	<lastBuildDate>Sat, 20 Apr 2013 07:23:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Grant Austin</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-25752</link>
		<dc:creator>Grant Austin</dc:creator>
		<pubDate>Tue, 20 Nov 2012 21:12:04 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-25752</guid>
		<description><![CDATA[@pragdave Why is that? Is it because you don&#039;t want to call close on nil if, for example, File.open causes Errno::ENOENT?]]></description>
		<content:encoded><![CDATA[<p>@pragdave Why is that? Is it because you don&#8217;t want to call close on nil if, for example, File.open causes Errno::ENOENT?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pragdave</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-25238</link>
		<dc:creator>pragdave</dc:creator>
		<pubDate>Sat, 31 Mar 2012 04:37:51 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-25238</guid>
		<description><![CDATA[This is orthogonal to the overall argument, but the code examples have the File.open inside the exception handling—a common mistake. It should be outside:

    f = File.open(&quot;...&quot;)
    begin
        # ...
    ensure
      f.close
    end]]></description>
		<content:encoded><![CDATA[<p>This is orthogonal to the overall argument, but the code examples have the File.open inside the exception handling—a common mistake. It should be outside:</p>
<p>    f = File.open(&#8220;&#8230;&#8221;)<br />
    begin<br />
        # &#8230;<br />
    ensure<br />
      f.close<br />
    end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Enrique Amodeo</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-25235</link>
		<dc:creator>Enrique Amodeo</dc:creator>
		<pubDate>Thu, 29 Mar 2012 09:05:24 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-25235</guid>
		<description><![CDATA[I liked your post. Certainly, as you said, blocks can be more elegant for the case of iterators. But I can think of no more use cases for lambdas in JS. We don&#039;t have mutex or any other synchronization construct in JS, since the language is single threaded. Although there are some synchronous API, the IO paradigm in JS is asynchronous, so I don&#039;t see a clear use case for blocks there. So we don&#039;t need blocks for resource management.
Of course, the syntax for functions in JS is awful, and that&#039;s why things like coffeescript are successful. Of course I expect some modification to the JS syntax in the future.
Good post nonetheless!]]></description>
		<content:encoded><![CDATA[<p>I liked your post. Certainly, as you said, blocks can be more elegant for the case of iterators. But I can think of no more use cases for lambdas in JS. We don&#8217;t have mutex or any other synchronization construct in JS, since the language is single threaded. Although there are some synchronous API, the IO paradigm in JS is asynchronous, so I don&#8217;t see a clear use case for blocks there. So we don&#8217;t need blocks for resource management.<br />
Of course, the syntax for functions in JS is awful, and that&#8217;s why things like coffeescript are successful. Of course I expect some modification to the JS syntax in the future.<br />
Good post nonetheless!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ultimater</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-25225</link>
		<dc:creator>Ultimater</dc:creator>
		<pubDate>Mon, 12 Mar 2012 17:37:54 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-25225</guid>
		<description><![CDATA[I approve of the idea for wanting to add such a feature to JavaScript, but I disapprove of the proposed syntax that was chosen. It would be a nightmare having to browse through someone else&#039;s code not knowing whether you are staring at a Bitwise-OR(&#124;) operation, a ternary-like-OR operation(&#124;&#124;), a function, a switch, an if statement, a try/catch block or some actual invalid syntax that would error if executed. Its too crypric... I&#039;m sorry, it just doesn&#039;t look like JavaScript anymore. I would have a hard time making heads or tails of such code written with a syntax like that. The readability of it is poor and I think Javascript deserves better treatment than that. Its JavaScript, not Python, not C++, not Java, and not heaven forbid &quot;Lisp&quot;.

Let&#039;s say for example a coder were to mistype an if statement and forgot the parentheses. Now all of a sudden it becomes valid lambda block syntax? How would the JavaScript interpreter know what to do with such a cryptic block? This will make parsing JavaScript much harder and probably introduce loads of bugs along the way among the browsers that try to implement such a complex and confusing syntax. Not to mention the &quot;overhead&quot; that an interpreter would have to deal with when trying to make sense of the unreadable code. This means slower code execution simply because the interpreter wouldn&#039;t know what kind of block its dealing with because the JavaScript engine would need to be re-designed and have to deal with extra syntax scenarios.

I&#039;m in favor of having lambda-like blocks in JavaScript but I dislike the purposed syntax. I would have expected a lamba block to look like a switch block, while, or try/catch block in JavaScript: e.g. lamba{} or lamba(){}

I believe if a lamba-block-like feature were added to ECMAScript, it shouldn&#039;t smell-up the language, as a drawback, with foreign syntax that would make a scripters run up the walls in confusion and frustration. In my experience, working with the GIMP, the &quot;lambda&quot; expression is available in the Lisp programming language as well as &quot;let&quot; identities. Is that what we are essentially doing here? Smelling up JavaScript with Lisp syntax?

I can see manys advantages and disadvantages to such a change. But I think the proposal should be revised a bit more before it goes mainstream so it can better fit-in and blend-in with the already existing JavaScript syntax.


-Ulti]]></description>
		<content:encoded><![CDATA[<p>I approve of the idea for wanting to add such a feature to JavaScript, but I disapprove of the proposed syntax that was chosen. It would be a nightmare having to browse through someone else&#8217;s code not knowing whether you are staring at a Bitwise-OR(|) operation, a ternary-like-OR operation(||), a function, a switch, an if statement, a try/catch block or some actual invalid syntax that would error if executed. Its too crypric&#8230; I&#8217;m sorry, it just doesn&#8217;t look like JavaScript anymore. I would have a hard time making heads or tails of such code written with a syntax like that. The readability of it is poor and I think Javascript deserves better treatment than that. Its JavaScript, not Python, not C++, not Java, and not heaven forbid &#8220;Lisp&#8221;.</p>
<p>Let&#8217;s say for example a coder were to mistype an if statement and forgot the parentheses. Now all of a sudden it becomes valid lambda block syntax? How would the JavaScript interpreter know what to do with such a cryptic block? This will make parsing JavaScript much harder and probably introduce loads of bugs along the way among the browsers that try to implement such a complex and confusing syntax. Not to mention the &#8220;overhead&#8221; that an interpreter would have to deal with when trying to make sense of the unreadable code. This means slower code execution simply because the interpreter wouldn&#8217;t know what kind of block its dealing with because the JavaScript engine would need to be re-designed and have to deal with extra syntax scenarios.</p>
<p>I&#8217;m in favor of having lambda-like blocks in JavaScript but I dislike the purposed syntax. I would have expected a lamba block to look like a switch block, while, or try/catch block in JavaScript: e.g. lamba{} or lamba(){}</p>
<p>I believe if a lamba-block-like feature were added to ECMAScript, it shouldn&#8217;t smell-up the language, as a drawback, with foreign syntax that would make a scripters run up the walls in confusion and frustration. In my experience, working with the GIMP, the &#8220;lambda&#8221; expression is available in the Lisp programming language as well as &#8220;let&#8221; identities. Is that what we are essentially doing here? Smelling up JavaScript with Lisp syntax?</p>
<p>I can see manys advantages and disadvantages to such a change. But I think the proposal should be revised a bit more before it goes mainstream so it can better fit-in and blend-in with the already existing JavaScript syntax.</p>
<p>-Ulti</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Kuča</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-25158</link>
		<dc:creator>Jan Kuča</dc:creator>
		<pubDate>Sat, 04 Feb 2012 10:37:20 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-25158</guid>
		<description><![CDATA[Thanks for the article. I always wondered what is the actual difference between Ruby blocks and JS anonymous functions.

However, I really don&#039;t think that JS would benefit from this kind of behavior because of its asynchronous nature. The example you gave would be asynchronous in JavaScript and the outer function would return before the inner one (the callback) would even start being executed.

There are really very few cases where a block would be useful. I think that the only improvement would be the execution context shift as we would not have to create variables such as self = this.]]></description>
		<content:encoded><![CDATA[<p>Thanks for the article. I always wondered what is the actual difference between Ruby blocks and JS anonymous functions.</p>
<p>However, I really don&#8217;t think that JS would benefit from this kind of behavior because of its asynchronous nature. The example you gave would be asynchronous in JavaScript and the outer function would return before the inner one (the callback) would even start being executed.</p>
<p>There are really very few cases where a block would be useful. I think that the only improvement would be the execution context shift as we would not have to create variables such as self = this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Fritze</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-25115</link>
		<dc:creator>Alex Fritze</dc:creator>
		<pubDate>Tue, 31 Jan 2012 20:21:16 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-25115</guid>
		<description><![CDATA[Hi Yehuda,

Thanks for putting forward the case for block lambdas so eloquently. Your post made us implement block lambda support in Stratified JavaScript - https://groups.google.com/d/topic/oni-apollo/eb3gtiwTOD4/discussion]]></description>
		<content:encoded><![CDATA[<p>Hi Yehuda,</p>
<p>Thanks for putting forward the case for block lambdas so eloquently. Your post made us implement block lambda support in Stratified JavaScript &#8211; <a href="https://groups.google.com/d/topic/oni-apollo/eb3gtiwTOD4/discussion" rel="nofollow">https://groups.google.com/d/topic/oni-apollo/eb3gtiwTOD4/discussion</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-24961</link>
		<dc:creator>chris</dc:creator>
		<pubDate>Tue, 17 Jan 2012 10:49:01 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-24961</guid>
		<description><![CDATA[I&#039;m not a rubyist and I find this sytax awkward regarding the js philosophy.

I&#039;m used to callback chaining in javascript, i.e something like

function FileInfo(name) {
  this.name = name;
}

FileInfo.prototype = {
 mtime: function(cbk) {
  //open file &#039;fname&#039; and call &#039;this.process&#039; scoped with &#039;this&#039; and with arguments [cbk]
  //the method File.process opens the file, calls the cbk and performs cleaning
  File.process(fname, this.process, this, [cbk])
 },
 process: function(cbk, f) {
   var mtime = f.mtime();
   cbk(mtime);
 }
}

And doing this is awkward when the language does not support NIO.

I would rather write : 
var mtime = File.mtime(fname) and the language platform should automatically perform NIO if necessary !

using a new syntax to perform the exact same thing]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m not a rubyist and I find this sytax awkward regarding the js philosophy.</p>
<p>I&#8217;m used to callback chaining in javascript, i.e something like</p>
<p>function FileInfo(name) {<br />
  this.name = name;<br />
}</p>
<p>FileInfo.prototype = {<br />
 mtime: function(cbk) {<br />
  //open file &#8216;fname&#8217; and call &#8216;this.process&#8217; scoped with &#8216;this&#8217; and with arguments [cbk]<br />
  //the method File.process opens the file, calls the cbk and performs cleaning<br />
  File.process(fname, this.process, this, [cbk])<br />
 },<br />
 process: function(cbk, f) {<br />
   var mtime = f.mtime();<br />
   cbk(mtime);<br />
 }<br />
}</p>
<p>And doing this is awkward when the language does not support NIO.</p>
<p>I would rather write :<br />
var mtime = File.mtime(fname) and the language platform should automatically perform NIO if necessary !</p>
<p>using a new syntax to perform the exact same thing</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Falk</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-24959</link>
		<dc:creator>Falk</dc:creator>
		<pubDate>Tue, 17 Jan 2012 10:37:36 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-24959</guid>
		<description><![CDATA[Javascript really should evolve. 
+1 for blocks in Javascript!]]></description>
		<content:encoded><![CDATA[<p>Javascript really should evolve.<br />
+1 for blocks in Javascript!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-24868</link>
		<dc:creator>Anthony</dc:creator>
		<pubDate>Fri, 13 Jan 2012 23:36:51 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-24868</guid>
		<description><![CDATA[The fact that the block must be executed immediately seems to make it needlessly complicated as opposed to functions. For example, if you were using an API, you might not know whether the method allows blocks, or requires a function.

This also confuses me: Consider a forEach function:
Array.prototype.forEach = function(block){
	var i,l;
	for(i=0,l=this.length;i&lt;l;i++){
		block(this[i]);
	}
}
But then if you were to do the following, then the block would be called again when inactive:
function firstValue(){
  [1,2,3].forEach { &#124;x&#124;
    return x;
  }
}

Right? To avoid this you would need to put a try {...} in the forEach which again makes it even more complicated. I&#039;m new to blocks so maybe I&#039;m missing something.]]></description>
		<content:encoded><![CDATA[<p>The fact that the block must be executed immediately seems to make it needlessly complicated as opposed to functions. For example, if you were using an API, you might not know whether the method allows blocks, or requires a function.</p>
<p>This also confuses me: Consider a forEach function:<br />
Array.prototype.forEach = function(block){<br />
	var i,l;<br />
	for(i=0,l=this.length;i&lt;l;i++){<br />
		block(this[i]);<br />
	}<br />
}<br />
But then if you were to do the following, then the block would be called again when inactive:<br />
function firstValue(){<br />
  [1,2,3].forEach { |x|<br />
    return x;<br />
  }<br />
}</p>
<p>Right? To avoid this you would need to put a try {&#8230;} in the forEach which again makes it even more complicated. I&#039;m new to blocks so maybe I&#039;m missing something.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Novelli</title>
		<link>http://yehudakatz.com/2012/01/10/javascript-needs-blocks/comment-page-1/#comment-24828</link>
		<dc:creator>Tom Novelli</dc:creator>
		<pubDate>Thu, 12 Jan 2012 15:35:22 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=698#comment-24828</guid>
		<description><![CDATA[Yehuda, the more I think about it, I kinda like the block lambda proposal. But your example raises some superficial distractions. You need a simple *working* example to sell Javascripters on this idea. Or at least, instead of an imaginary File.open, use fs.openSync(name, &quot;r&quot;) in Node.js. But it&#039;d be best to start with a non-OO example that works in both server-side and browser-side JS.

Also, you really ought to link to the block lambda proposal at the top of this post, along with a good concise summary of Ruby blocks (from a language design perspective, ideally). I don&#039;t like blog posts littered with links, but this is necessary background reading for non-Rubyists.

OO is another whole can of worms, with &quot;this&quot; and &quot;.call(this_value)&quot; and so on in JS. The way other languages deal with OO is &quot;interesting&quot;. Python has the self-as-first-param kludge, which is simpler to implement but violates the correspondence principle to an irritating extent. Lua has it too, if my memory serves. C++ has classes and inheritance and all kinds of craziness, copied by other languages for no good reason. Go eschews inheritance as a Bad Idea... and I vaguely agree. Last I knew, there was a lively debate about the future of OO in Javascript... so, there are two lines of thought to pursue: (1) How would block lambdas fit into JS&#039;s existing kludgy OO system? (2) How would they fit into the various proposals for brand-new OO systems?  (And I&#039;m not very interested in that discussion... I only use OO when it&#039;s useful to me, which isn&#039;t very often.)]]></description>
		<content:encoded><![CDATA[<p>Yehuda, the more I think about it, I kinda like the block lambda proposal. But your example raises some superficial distractions. You need a simple *working* example to sell Javascripters on this idea. Or at least, instead of an imaginary File.open, use fs.openSync(name, &#8220;r&#8221;) in Node.js. But it&#8217;d be best to start with a non-OO example that works in both server-side and browser-side JS.</p>
<p>Also, you really ought to link to the block lambda proposal at the top of this post, along with a good concise summary of Ruby blocks (from a language design perspective, ideally). I don&#8217;t like blog posts littered with links, but this is necessary background reading for non-Rubyists.</p>
<p>OO is another whole can of worms, with &#8220;this&#8221; and &#8220;.call(this_value)&#8221; and so on in JS. The way other languages deal with OO is &#8220;interesting&#8221;. Python has the self-as-first-param kludge, which is simpler to implement but violates the correspondence principle to an irritating extent. Lua has it too, if my memory serves. C++ has classes and inheritance and all kinds of craziness, copied by other languages for no good reason. Go eschews inheritance as a Bad Idea&#8230; and I vaguely agree. Last I knew, there was a lively debate about the future of OO in Javascript&#8230; so, there are two lines of thought to pursue: (1) How would block lambdas fit into JS&#8217;s existing kludgy OO system? (2) How would they fit into the various proposals for brand-new OO systems?  (And I&#8217;m not very interested in that discussion&#8230; I only use OO when it&#8217;s useful to me, which isn&#8217;t very often.)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
