<story><title>Callbacks as our Generation&apos;s Goto Statement</title><url>http://tirania.org/blog/archive/2013/Aug-15.html</url></story><parent_chain><item><author>crazygringo</author><text>&amp;quot;Await&amp;quot; is fantastic, and having using it for JavaScript (via TameJS and then IcedCoffeeScript), it makes things a lot easier and clearer.&lt;p&gt;That being said, I don&amp;#x27;t think the comparison between callbacks and goto is valid.&lt;p&gt;&amp;quot;Goto&amp;quot; allows you to create horrible spaghetti-code programs, and getting rid of it forces you to structure your programs better.&lt;p&gt;&amp;quot;Await&amp;quot;, fundamentally, isn&amp;#x27;t really anything more than syntactic sugar (except for exception handling, which is a good thing). &amp;quot;Await&amp;quot; doesn&amp;#x27;t change how your program is structured at all, it just changes the &lt;i&gt;visual&lt;/i&gt; representation of your code -- from indentations in a non-linear order, to vertical and linear order. It&amp;#x27;s definitely a nice improvement, and makes code easier to understand (and allows for better exception handling), but it&amp;#x27;s not actually changing the way your program is fundamentally structured.&lt;p&gt;And finally, &amp;quot;await&amp;quot; is only applicable when a single callback gets called once at the end. If you&amp;#x27;re passing a callback that gets used repeatedly (a sorting function, for example), then normal-style callbacks are still necessary, and not harmful at all. Sometimes they can be short lambdas, sometimes they&amp;#x27;re necessarily much larger.&lt;p&gt;In sum: &amp;quot;await&amp;quot; is great, but there&amp;#x27;s nothing inherently harmful about callbacks, the way &amp;quot;goto&amp;quot; is. To the contrary -- callbacks are amazingly useful, and amazingly powerful in languages like JavaScript. &amp;quot;Await&amp;quot; just makes them nicer.</text></item></parent_chain><comment><author>blahedo</author><text>What this suggests is that &amp;quot;await&amp;quot; isn&amp;#x27;t like &lt;i&gt;all&lt;/i&gt; structured programming, it&amp;#x27;s like &lt;i&gt;one&lt;/i&gt; control construct.  The history of structured programming is the development of more constructs as people realised that they had a goto pattern that kept popping up in their code, so they named it and thereby got a cognitively-higher-level program.  Long after Dijkstra&amp;#x27;s essay, we could still occasionally find new places where goto was really the best way to do it: for instance, if you wanted to &amp;quot;break&amp;quot; out of multiple loops at once.  So someone invented named break (likewise continue), and removed yet another use of the unconstrained goto in favour of a more constrained, structured construct.&lt;p&gt;Taking the OP&amp;#x27;s premise at face value, then, if callbacks are like goto, then await takes away one place where they &lt;i&gt;were&lt;/i&gt; needed and replaces them with something more structured and safer---and this doesn&amp;#x27;t at all negate the possibility that there are other constructs yet to be invented that would continue that process.</text></comment>
<story><title>Callbacks as our Generation&apos;s Goto Statement</title><url>http://tirania.org/blog/archive/2013/Aug-15.html</url></story><parent_chain><item><author>crazygringo</author><text>&amp;quot;Await&amp;quot; is fantastic, and having using it for JavaScript (via TameJS and then IcedCoffeeScript), it makes things a lot easier and clearer.&lt;p&gt;That being said, I don&amp;#x27;t think the comparison between callbacks and goto is valid.&lt;p&gt;&amp;quot;Goto&amp;quot; allows you to create horrible spaghetti-code programs, and getting rid of it forces you to structure your programs better.&lt;p&gt;&amp;quot;Await&amp;quot;, fundamentally, isn&amp;#x27;t really anything more than syntactic sugar (except for exception handling, which is a good thing). &amp;quot;Await&amp;quot; doesn&amp;#x27;t change how your program is structured at all, it just changes the &lt;i&gt;visual&lt;/i&gt; representation of your code -- from indentations in a non-linear order, to vertical and linear order. It&amp;#x27;s definitely a nice improvement, and makes code easier to understand (and allows for better exception handling), but it&amp;#x27;s not actually changing the way your program is fundamentally structured.&lt;p&gt;And finally, &amp;quot;await&amp;quot; is only applicable when a single callback gets called once at the end. If you&amp;#x27;re passing a callback that gets used repeatedly (a sorting function, for example), then normal-style callbacks are still necessary, and not harmful at all. Sometimes they can be short lambdas, sometimes they&amp;#x27;re necessarily much larger.&lt;p&gt;In sum: &amp;quot;await&amp;quot; is great, but there&amp;#x27;s nothing inherently harmful about callbacks, the way &amp;quot;goto&amp;quot; is. To the contrary -- callbacks are amazingly useful, and amazingly powerful in languages like JavaScript. &amp;quot;Await&amp;quot; just makes them nicer.</text></item></parent_chain><comment><author>wrl</author><text>Let&amp;#x27;s not forget that &amp;quot;if&amp;quot;, &amp;quot;for&amp;quot;, &amp;quot;while&amp;quot;, &amp;quot;switch&amp;quot;, and friends, fundamentally, aren&amp;#x27;t anything more than syntactic sugar for &amp;quot;goto&amp;quot; either. ;)</text></comment>