<?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: Goto heresy</title>
	<atom:link href="http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/feed/" rel="self" type="application/rss+xml" />
	<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/</link>
	<description>Thoughts on embedded systems by Nigel Jones</description>
	<lastBuildDate>Wed, 28 Jul 2010 00:59:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Hernan</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-1297</link>
		<dc:creator>Hernan</dc:creator>
		<pubDate>Thu, 22 Jul 2010 16:02:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-1297</guid>
		<description>Ok, great I&#039;ll read your comments then, but I think it will be, at least, a funny weekend ;), thanks</description>
		<content:encoded><![CDATA[<p>Ok, great I&#8217;ll read your comments then, but I think it will be, at least, a funny weekend <img src='http://embeddedgurus.com/stack-overflow/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> , thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-1291</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Wed, 21 Jul 2010 14:03:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-1291</guid>
		<description>Hi Hernan:
I&#039;ve taken a quick look at what you have done. Quite frankly I need more time than I have now to digest it, so I will try and get to it this weekend and give you a more thoughtful response.</description>
		<content:encoded><![CDATA[<p>Hi Hernan:<br />
I&#8217;ve taken a quick look at what you have done. Quite frankly I need more time than I have now to digest it, so I will try and get to it this weekend and give you a more thoughtful response.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hernan</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-1285</link>
		<dc:creator>Hernan</dc:creator>
		<pubDate>Tue, 20 Jul 2010 18:52:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-1285</guid>
		<description>Sometime there is a difficult choice between readability vs..  many things
I used to choose readability when I can, and I believe many things come with it ;)

I would like to answer the original e-mail,
Telling to take a look to a .h header I wrote  for [error handling] 

http://sourceforge.net/projects/delorean/

I hope you like,  thanks!</description>
		<content:encoded><![CDATA[<p>Sometime there is a difficult choice between readability vs..  many things<br />
I used to choose readability when I can, and I believe many things come with it <img src='http://embeddedgurus.com/stack-overflow/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I would like to answer the original e-mail,<br />
Telling to take a look to a .h header I wrote  for [error handling] </p>
<p><a href="http://sourceforge.net/projects/delorean/" rel="nofollow">http://sourceforge.net/projects/delorean/</a></p>
<p>I hope you like,  thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Krzsyztof Bosak</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-1088</link>
		<dc:creator>Krzsyztof Bosak</dc:creator>
		<pubDate>Thu, 17 Jun 2010 13:28:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-1088</guid>
		<description>There is one top reason of using goto.
This is a search of an element in bi-dimensional table.
This requires 2 nested for loops.
The table can be in fact an array of lists, anything heterogenous.
Very often found in numerical algorithms.

This is a top operation, often involving looking max value element in an array etc.

As break exits only one level, you can use either return or goto.
the former implies creating a separate function just for the scanning job.</description>
		<content:encoded><![CDATA[<p>There is one top reason of using goto.<br />
This is a search of an element in bi-dimensional table.<br />
This requires 2 nested for loops.<br />
The table can be in fact an array of lists, anything heterogenous.<br />
Very often found in numerical algorithms.</p>
<p>This is a top operation, often involving looking max value element in an array etc.</p>
<p>As break exits only one level, you can use either return or goto.<br />
the former implies creating a separate function just for the scanning job.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Sawyer</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-753</link>
		<dc:creator>Jim Sawyer</dc:creator>
		<pubDate>Thu, 06 May 2010 02:45:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-753</guid>
		<description>&quot; ... without using ‘break’ or ‘goto’ 
   can rapidly lead to code
   that is a nightmare to follow
&quot;

True dat.
However,

&quot; ... once one gets beyond about four or five tests of the type you are performing,
   I’d say that the code becomes impossible to follow
   unless you use either the style you have espoused
   or a goto statement.
&quot;

Not so! 
The important thing is to keep everything
        small &amp;&amp; readable
regardless of what constructs you use.

I use functional decomposition,
as in &quot;many small bite size pieces&quot;.

You might not, and that&#039;s ok.
I guess. As long as its readable.

===
 
typedef uint = unsigned int;
typedef tripleX XXX_UGLYEXTERNALLY_NAMED_THING_CRIPES_BASKULEE_OVER_DUDE;

bool aValidTripleX(tripleX toBeChecked)
  {
   if(toBeChecked==NULL) {return FALSE};
   if(!XXX_IS_ALL_GOOD) {return FALSE};
   return TRUE;
  }

uint AddVerifiableTripleXRequestExample (uint aReadableName, uint *aReadableNameHandle)
    {
      uint status;

      if (!aValidTripleX (aReadableName)) {return ERROR_InvalidInstance};
      if (aReadableNameHandle == NULL) {return ERROR_InvalidArgument};
      if(ICouldGoOnAndOnCauseItsPrettyReadable &amp;&amp; XXX_WHATEVER) {return ERROR_NoCanDo};

      status = XXX_SOME_STATUS;
      while (status == XXX_SOME_STATUS) do
          {
            status = AddTripleXRequest (aReadableName, aReadableNameHandle);
          };
      if(status == XXX_BAD_STATUS) {return WARNING_PartialRequest};

      return PROGESS_CompleteRequest;
    }


===

But what about single exit?
Suppose a change is needed, and now every path must II before EE except after CC?

===

 

uint ModifiedAddVerifiableTripleXRequestExample (bool isAfter, uint aReadableName, uint *aReadableNameHandle)
    {
    uint holdEverything;

    if(!isAfter) {DickTracyCallingJoeJitsu(II);}

    holdEverything = AddVerifiableTripleXRequestExample (uint aReadableName, uint *aReadableNameHandle);

    if(isAfter) {DickTracyCallingJoeJitsu(II);}

    return holdEverything;
    }</description>
		<content:encoded><![CDATA[<p>&#8221; &#8230; without using ‘break’ or ‘goto’<br />
   can rapidly lead to code<br />
   that is a nightmare to follow<br />
&#8221;</p>
<p>True dat.<br />
However,</p>
<p>&#8221; &#8230; once one gets beyond about four or five tests of the type you are performing,<br />
   I’d say that the code becomes impossible to follow<br />
   unless you use either the style you have espoused<br />
   or a goto statement.<br />
&#8221;</p>
<p>Not so!<br />
The important thing is to keep everything<br />
        small &amp;&amp; readable<br />
regardless of what constructs you use.</p>
<p>I use functional decomposition,<br />
as in &#8220;many small bite size pieces&#8221;.</p>
<p>You might not, and that&#8217;s ok.<br />
I guess. As long as its readable.</p>
<p>===</p>
<p>typedef uint = unsigned int;<br />
typedef tripleX XXX_UGLYEXTERNALLY_NAMED_THING_CRIPES_BASKULEE_OVER_DUDE;</p>
<p>bool aValidTripleX(tripleX toBeChecked)<br />
  {<br />
   if(toBeChecked==NULL) {return FALSE};<br />
   if(!XXX_IS_ALL_GOOD) {return FALSE};<br />
   return TRUE;<br />
  }</p>
<p>uint AddVerifiableTripleXRequestExample (uint aReadableName, uint *aReadableNameHandle)<br />
    {<br />
      uint status;</p>
<p>      if (!aValidTripleX (aReadableName)) {return ERROR_InvalidInstance};<br />
      if (aReadableNameHandle == NULL) {return ERROR_InvalidArgument};<br />
      if(ICouldGoOnAndOnCauseItsPrettyReadable &amp;&amp; XXX_WHATEVER) {return ERROR_NoCanDo};</p>
<p>      status = XXX_SOME_STATUS;<br />
      while (status == XXX_SOME_STATUS) do<br />
          {<br />
            status = AddTripleXRequest (aReadableName, aReadableNameHandle);<br />
          };<br />
      if(status == XXX_BAD_STATUS) {return WARNING_PartialRequest};</p>
<p>      return PROGESS_CompleteRequest;<br />
    }</p>
<p>===</p>
<p>But what about single exit?<br />
Suppose a change is needed, and now every path must II before EE except after CC?</p>
<p>===</p>
<p>uint ModifiedAddVerifiableTripleXRequestExample (bool isAfter, uint aReadableName, uint *aReadableNameHandle)<br />
    {<br />
    uint holdEverything;</p>
<p>    if(!isAfter) {DickTracyCallingJoeJitsu(II);}</p>
<p>    holdEverything = AddVerifiableTripleXRequestExample (uint aReadableName, uint *aReadableNameHandle);</p>
<p>    if(isAfter) {DickTracyCallingJoeJitsu(II);}</p>
<p>    return holdEverything;<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-529</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Sun, 28 Mar 2010 15:00:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-529</guid>
		<description>The C language is a small language and so I tend to use most of its constructs, including the ternary operator. I particularly like it when for readability reasons I need the source code to be compact. (For example if by using the ternary operator I can keep an entire function on the screen, thus making it easier to see the big picture). Having said that, there are compilers where the ternary operator is not as efficient as an if-then-else. You&#039;ll find my thoughts on this &lt;a href=&quot;http://embeddedgurus.com/stack-overflow/2009/02/efficient-c-tips-6-dont-use-the-ternary-operator/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>The C language is a small language and so I tend to use most of its constructs, including the ternary operator. I particularly like it when for readability reasons I need the source code to be compact. (For example if by using the ternary operator I can keep an entire function on the screen, thus making it easier to see the big picture). Having said that, there are compilers where the ternary operator is not as efficient as an if-then-else. You&#8217;ll find my thoughts on this <a href="http://embeddedgurus.com/stack-overflow/2009/02/efficient-c-tips-6-dont-use-the-ternary-operator/" rel="nofollow">here</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GroovyD</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-524</link>
		<dc:creator>GroovyD</dc:creator>
		<pubDate>Sun, 28 Mar 2010 05:10:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-524</guid>
		<description>...or better yet...

SetLedState( ledFlash ? GetLedFlashState() : GetLedNotFlashState());</description>
		<content:encoded><![CDATA[<p>&#8230;or better yet&#8230;</p>
<p>SetLedState( ledFlash ? GetLedFlashState() : GetLedNotFlashState());</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GroovyD</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-523</link>
		<dc:creator>GroovyD</dc:creator>
		<pubDate>Sun, 28 Mar 2010 05:08:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-523</guid>
		<description>Lots of good comments about &#039;goto&#039;s, now how about some regarding:

 (a) ? (b) : (c)

I hear every now and then using this construct is not clear but recently i find myself using it more often for example:

bool ledState = ledFlash ? LedFlashState() : LedNotFlashState();

Thoughts?</description>
		<content:encoded><![CDATA[<p>Lots of good comments about &#8216;goto&#8217;s, now how about some regarding:</p>
<p> (a) ? (b) : (c)</p>
<p>I hear every now and then using this construct is not clear but recently i find myself using it more often for example:</p>
<p>bool ledState = ledFlash ? LedFlashState() : LedNotFlashState();</p>
<p>Thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-493</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 24 Mar 2010 15:14:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-493</guid>
		<description>Of course not.  The more I use &#039;C&#039; the more I feel it is inappropriate for a Safety Critical system.</description>
		<content:encoded><![CDATA[<p>Of course not.  The more I use &#8216;C&#8217; the more I feel it is inappropriate for a Safety Critical system.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JuKu</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/comment-page-1/#comment-490</link>
		<dc:creator>JuKu</dc:creator>
		<pubDate>Tue, 23 Mar 2010 21:25:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/#comment-490</guid>
		<description>Goto&#039;s are not harmful (in right place), multiple destinations are. For example, I&#039;ve coded the same problem* in various products several times; I haven&#039;t tried to do-break approach, but I&#039;ve done a switch, if-else if-else if... and goto solutions. The goto solution is by far the easiest to handle, when the function grows.

*: The problem is a multiple choice scenario, and the following turns out to be easiest to maintain:

if(this condition)
{
    handle &quot;this&quot; condition;
    goto end_of_function;
}

if(that condition)
{
    handle &quot;that&quot; condition;
    goto end_of_function;
}

...

end_of_function:
cleanup, report situation etc.
return;

Now, assume there are a few ten situations to handle, each taking about a screenful of code. This 1000+ line function is very maintainable and a missed } gives an error message close to where the error is. Efficient, too.</description>
		<content:encoded><![CDATA[<p>Goto&#8217;s are not harmful (in right place), multiple destinations are. For example, I&#8217;ve coded the same problem* in various products several times; I haven&#8217;t tried to do-break approach, but I&#8217;ve done a switch, if-else if-else if&#8230; and goto solutions. The goto solution is by far the easiest to handle, when the function grows.</p>
<p>*: The problem is a multiple choice scenario, and the following turns out to be easiest to maintain:</p>
<p>if(this condition)<br />
{<br />
    handle &#8220;this&#8221; condition;<br />
    goto end_of_function;<br />
}</p>
<p>if(that condition)<br />
{<br />
    handle &#8220;that&#8221; condition;<br />
    goto end_of_function;<br />
}</p>
<p>&#8230;</p>
<p>end_of_function:<br />
cleanup, report situation etc.<br />
return;</p>
<p>Now, assume there are a few ten situations to handle, each taking about a screenful of code. This 1000+ line function is very maintainable and a missed } gives an error message close to where the error is. Efficient, too.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
