<?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 for source code bean</title>
	<atom:link href="http://sourcecodebean.com/comments/feed" rel="self" type="application/rss+xml" />
	<link>http://sourcecodebean.com</link>
	<description>thoughts and ideas from a .net developer</description>
	<lastBuildDate>Sun, 29 Jan 2012 18:18:55 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comment on Node.js: Callbacks are polluting your code by Joe</title>
		<link>http://sourcecodebean.com/archives/callbacks-are-polluting-your-code/1488/comment-page-1#comment-19168</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Sun, 29 Jan 2012 18:18:55 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1488#comment-19168</guid>
		<description>It looks like IceCoffee Script may provide the &#039;await&#039; keyword to JavaScript.  http://maxtaco.github.com/coffee-script/</description>
		<content:encoded><![CDATA[<p>It looks like IceCoffee Script may provide the &#8216;await&#8217; keyword to JavaScript.  <a href="http://maxtaco.github.com/coffee-script/" rel="nofollow">http://maxtaco.github.com/coffee-script/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Node.js: Callbacks are polluting your code by Florian</title>
		<link>http://sourcecodebean.com/archives/callbacks-are-polluting-your-code/1488/comment-page-1#comment-19153</link>
		<dc:creator>Florian</dc:creator>
		<pubDate>Sun, 29 Jan 2012 13:04:23 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1488#comment-19153</guid>
		<description>Dealing with events has two primary fashions: imperative (synchronous) code, and callback (asynchronous) code.

Both are legitimate styles, for some situations, and none is universally better than the other.

If you are dealing with event sequences that are predicated in some way (only go in one direction, delay until another event has finishes, HTTP, etc.) then synchronous code is a superior choice for clarity. It expresses the core idea of the algorithm very cleanly.

If you are dealing with receiving many events at the same time (like keyboard/mouse input etc.) and the events are not predicated (or not much) callback styles are often a better choice.

Which style you use should not be dictated by your language/runtime environment and technical issues, but by your usecase.

An issue with imperative/synchronous semantics arises if the only way to service this semantic is blocking system calls (like recv). You can use threads to migitate this problem, but in its stead just introduces locks, raise conditions and blocking semaphores.

A better way to provide the ability to handle events in an imperative/synchronous fashion is to use non-blocking system calls (connect ex, set blocking to false etc.) and use co-routines to schedule micro-threads depending on event state. There have been a variety of blog posts and papers about this, which consistently show that for I/O bound tasks, this is a far superior model because it offers cleaner code than both callback/asynchronous events and threaded programming, while also enjoying speed benefits forgone by threads (due to locking).

There are three primary ways that co-routines can be implemented:
1) As an native code level instruction pointer switch, an example of this would be pythons greenlet implementation.
2) As a property of the virtual machine running the interpreted language, an example of which would be rubys early thread model (didn&#039;t use actual threads).
3) As a preprocessor to the virtual machine input that translated synchronous marked up codelines to asynchronous code.

These options are not entirely equivalent and some have advantages over others. 
1) Implementing micro-threads/greenlets/co-routines on a native code level is quite fast. It also automatically solves the case that a virtual machine level callback is performed in a native-code part which was not designed to support micro threads. However there might be messups of the VM state.

2) Implementing them as a property of the VM is a very safe and relatively easy thing to do, however inbetween native-code parts and callbacks to virtual machine code, the micro-threads could get broken by inconsiderate native code.

3) Implementing them as a preprocessor is a very inferior choice, because it requires code path inference. In other words, if A calls B and B calls C and C is defined as a co-routine, then B must know that C is a co-routine, which means that A must know that B is a co-routine. Since this is not possible in JS, every call would have to be a potential co-routine, which would be extremely slow and would produce extremely convoluted code (compared to relatively straightforward code as produced by Coffeescript).

However the problem is solved in the end, sticking your head in the sand is not the solution.</description>
		<content:encoded><![CDATA[<p>Dealing with events has two primary fashions: imperative (synchronous) code, and callback (asynchronous) code.</p>
<p>Both are legitimate styles, for some situations, and none is universally better than the other.</p>
<p>If you are dealing with event sequences that are predicated in some way (only go in one direction, delay until another event has finishes, HTTP, etc.) then synchronous code is a superior choice for clarity. It expresses the core idea of the algorithm very cleanly.</p>
<p>If you are dealing with receiving many events at the same time (like keyboard/mouse input etc.) and the events are not predicated (or not much) callback styles are often a better choice.</p>
<p>Which style you use should not be dictated by your language/runtime environment and technical issues, but by your usecase.</p>
<p>An issue with imperative/synchronous semantics arises if the only way to service this semantic is blocking system calls (like recv). You can use threads to migitate this problem, but in its stead just introduces locks, raise conditions and blocking semaphores.</p>
<p>A better way to provide the ability to handle events in an imperative/synchronous fashion is to use non-blocking system calls (connect ex, set blocking to false etc.) and use co-routines to schedule micro-threads depending on event state. There have been a variety of blog posts and papers about this, which consistently show that for I/O bound tasks, this is a far superior model because it offers cleaner code than both callback/asynchronous events and threaded programming, while also enjoying speed benefits forgone by threads (due to locking).</p>
<p>There are three primary ways that co-routines can be implemented:<br />
1) As an native code level instruction pointer switch, an example of this would be pythons greenlet implementation.<br />
2) As a property of the virtual machine running the interpreted language, an example of which would be rubys early thread model (didn&#8217;t use actual threads).<br />
3) As a preprocessor to the virtual machine input that translated synchronous marked up codelines to asynchronous code.</p>
<p>These options are not entirely equivalent and some have advantages over others.<br />
1) Implementing micro-threads/greenlets/co-routines on a native code level is quite fast. It also automatically solves the case that a virtual machine level callback is performed in a native-code part which was not designed to support micro threads. However there might be messups of the VM state.</p>
<p>2) Implementing them as a property of the VM is a very safe and relatively easy thing to do, however inbetween native-code parts and callbacks to virtual machine code, the micro-threads could get broken by inconsiderate native code.</p>
<p>3) Implementing them as a preprocessor is a very inferior choice, because it requires code path inference. In other words, if A calls B and B calls C and C is defined as a co-routine, then B must know that C is a co-routine, which means that A must know that B is a co-routine. Since this is not possible in JS, every call would have to be a potential co-routine, which would be extremely slow and would produce extremely convoluted code (compared to relatively straightforward code as produced by Coffeescript).</p>
<p>However the problem is solved in the end, sticking your head in the sand is not the solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Platform as a Service vs Infrastructure as a Service by Joe</title>
		<link>http://sourcecodebean.com/archives/platform-as-a-service-vs-infrastructure-as-a-service/1379/comment-page-1#comment-19045</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Fri, 27 Jan 2012 18:12:41 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1379#comment-19045</guid>
		<description>I think we haven&#039;t seen true PaaS offering yet in Azure.  If you use a webrole you&#039;re still running on your own VM.  This is still not true multi-tenancy with pay-for-use.  

With a true asycnrhonous event model you can imagine a more pure PaaS solution where your stateless application can really be running anywhere.  I think then economics will drive to PaaS over IaaS.</description>
		<content:encoded><![CDATA[<p>I think we haven&#8217;t seen true PaaS offering yet in Azure.  If you use a webrole you&#8217;re still running on your own VM.  This is still not true multi-tenancy with pay-for-use.  </p>
<p>With a true asycnrhonous event model you can imagine a more pure PaaS solution where your stateless application can really be running anywhere.  I think then economics will drive to PaaS over IaaS.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Node.js: Callbacks are polluting your code by Joe</title>
		<link>http://sourcecodebean.com/archives/callbacks-are-polluting-your-code/1488/comment-page-1#comment-19044</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Fri, 27 Jan 2012 18:08:31 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1488#comment-19044</guid>
		<description>Great post, my sentiments exactly.  Given Microsoft&#039;s involvement with node.js recently I wouldn&#039;t be surprised if Glenn Block &amp; co are busy working on an asynchronous version of .NET.</description>
		<content:encoded><![CDATA[<p>Great post, my sentiments exactly.  Given Microsoft&#8217;s involvement with node.js recently I wouldn&#8217;t be surprised if Glenn Block &amp; co are busy working on an asynchronous version of .NET.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Node.js: Callbacks are polluting your code by Daniel Kullmann</title>
		<link>http://sourcecodebean.com/archives/callbacks-are-polluting-your-code/1488/comment-page-1#comment-19036</link>
		<dc:creator>Daniel Kullmann</dc:creator>
		<pubDate>Fri, 27 Jan 2012 12:32:59 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1488#comment-19036</guid>
		<description>Peter, I absolutely agree with your post. In my opinion, asynchronous method calls should be supported by the language internally, just as C# does this with async/await 
(It seems that tamejs does exactly that, using a somewhat quirky syntax).

As far as I understand it, the need for callbacks arises from the wish to better use computing resources: The code is divided into small blocks of non-blocking code, that optionally end with a call to a function that is blocking. 

When structuring the code like this, the runtime will only need to create a thread or two for each core the computer has, and these will get these small chunks of code from a queue, process them, and give the blocking pieces back to the queue manager, which will add the callback to the queue when the blocking call ends.

When you tell the language which functions are blocking, you can write your code in a synchronous/sequential style, while the compiler does the work of making it work efficiently.</description>
		<content:encoded><![CDATA[<p>Peter, I absolutely agree with your post. In my opinion, asynchronous method calls should be supported by the language internally, just as C# does this with async/await<br />
(It seems that tamejs does exactly that, using a somewhat quirky syntax).</p>
<p>As far as I understand it, the need for callbacks arises from the wish to better use computing resources: The code is divided into small blocks of non-blocking code, that optionally end with a call to a function that is blocking. </p>
<p>When structuring the code like this, the runtime will only need to create a thread or two for each core the computer has, and these will get these small chunks of code from a queue, process them, and give the blocking pieces back to the queue manager, which will add the callback to the queue when the blocking call ends.</p>
<p>When you tell the language which functions are blocking, you can write your code in a synchronous/sequential style, while the compiler does the work of making it work efficiently.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Node.js: Callbacks are polluting your code by Peter</title>
		<link>http://sourcecodebean.com/archives/callbacks-are-polluting-your-code/1488/comment-page-1#comment-19034</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 27 Jan 2012 12:06:46 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1488#comment-19034</guid>
		<description>zorg: SJS looks very interesting!</description>
		<content:encoded><![CDATA[<p>zorg: SJS looks very interesting!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Node.js: Callbacks are polluting your code by Peter</title>
		<link>http://sourcecodebean.com/archives/callbacks-are-polluting-your-code/1488/comment-page-1#comment-19033</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 27 Jan 2012 12:04:58 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1488#comment-19033</guid>
		<description>KR: Sure the code does not move forward, but the executing thread does not block. When calling await it will continue processing other requests, and when someAsyncOperation is done it will resume execution of this method on the statement after await.</description>
		<content:encoded><![CDATA[<p>KR: Sure the code does not move forward, but the executing thread does not block. When calling await it will continue processing other requests, and when someAsyncOperation is done it will resume execution of this method on the statement after await.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Node.js: Callbacks are polluting your code by Peter</title>
		<link>http://sourcecodebean.com/archives/callbacks-are-polluting-your-code/1488/comment-page-1#comment-19031</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 27 Jan 2012 11:54:28 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1488#comment-19031</guid>
		<description>gin5eng: I don&#039;t blame Node anywhere in the post, if you think so you have clearly misunderstood the post. If anyone would be to blame it would be Javascript, but I rather see this as a potential improvement of Javascript.</description>
		<content:encoded><![CDATA[<p>gin5eng: I don&#8217;t blame Node anywhere in the post, if you think so you have clearly misunderstood the post. If anyone would be to blame it would be Javascript, but I rather see this as a potential improvement of Javascript.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Node.js: Callbacks are polluting your code by KR</title>
		<link>http://sourcecodebean.com/archives/callbacks-are-polluting-your-code/1488/comment-page-1#comment-19030</link>
		<dc:creator>KR</dc:creator>
		<pubDate>Fri, 27 Jan 2012 11:34:47 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1488#comment-19030</guid>
		<description>Even at the risk of making a complete fool out of myself by now: 

&lt;pre&gt;
[...]  

if (some contidion) {
    x.result = await someAsyncOperation();
  }
 
  await x.save()
[...]
&lt;/pre&gt;

If what happens here obviously is synchronous (as, using &quot;await&quot;, things don&#039;t seem to move any further until x.save() or someAsyncOperation() has finished), why would I want to make it asynchronous, after all?</description>
		<content:encoded><![CDATA[<p>Even at the risk of making a complete fool out of myself by now: </p>
<pre>
[...]  

if (some contidion) {
    x.result = await someAsyncOperation();
  }

  await x.save()
[...]
</pre>
<p>If what happens here obviously is synchronous (as, using &#8220;await&#8221;, things don&#8217;t seem to move any further until x.save() or someAsyncOperation() has finished), why would I want to make it asynchronous, after all?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Node.js: Callbacks are polluting your code by Bob Gregory</title>
		<link>http://sourcecodebean.com/archives/callbacks-are-polluting-your-code/1488/comment-page-1#comment-19029</link>
		<dc:creator>Bob Gregory</dc:creator>
		<pubDate>Fri, 27 Jan 2012 11:30:40 +0000</pubDate>
		<guid isPermaLink="false">http://sourcecodebean.com/?p=1488#comment-19029</guid>
		<description>@Ricardo has the right idea here. I&#039;d use continuation-passing style to express the flow of execution.</description>
		<content:encoded><![CDATA[<p>@Ricardo has the right idea here. I&#8217;d use continuation-passing style to express the flow of execution.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: sourcecodebean.com @ 2012-02-06 07:02:17 -->
