<?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: A matter of style</title>
	<atom:link href="http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/feed/" rel="self" type="application/rss+xml" />
	<link>http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/</link>
	<description>Coding under the close supervision of cats</description>
	<lastBuildDate>Fri, 09 Jul 2010 18:22:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: rem</title>
		<link>http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/comment-page-1/#comment-23</link>
		<dc:creator>rem</dc:creator>
		<pubDate>Fri, 20 Oct 2006 19:44:08 +0000</pubDate>
		<guid isPermaLink="false">http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/#comment-23</guid>
		<description>Is this kind of problem where you use goto not a problem where exceptions where designed for?</description>
		<content:encoded><![CDATA[<p>Is this kind of problem where you use goto not a problem where exceptions where designed for?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/comment-page-1/#comment-18</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Wed, 18 Oct 2006 17:35:16 +0000</pubDate>
		<guid isPermaLink="false">http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/#comment-18</guid>
		<description>&lt;p&gt;Thanks for the comments! You&#039;ve made this the most active thread in the history of the blog. ;-)&lt;/p&gt;

&lt;p&gt;Daniel, I agree that nested &lt;code&gt;if&lt;/code&gt; structures are appropriate for some situations. However, a typical pattern is to check for fatal errors at the beginning of a function, and I prefer not have my entire implementation within a giant &lt;code&gt;if&lt;/code&gt; clause. If I understand what you&#039;re describing, I think that mid-implementation cleanup code could be accommodated within the &lt;code&gt;goto&lt;/code&gt; schema, though of course it depends on the exact nature of the code. To clarify, I am advocating a single exit point rather than multiple &lt;code&gt;goto&lt;/code&gt; destinations.&lt;/p&gt;

&lt;p&gt;Another advantage I see with &lt;code&gt;goto&lt;/code&gt; statements is that if you customize the labels according to the function, e.g., &lt;code&gt;returnFromDoSomethingWithArgument:&lt;/code&gt;, then at any time you can perform a project search and immediately find not only the end of the function but all of the exit conditions for the function as well.&lt;/p&gt;

&lt;p&gt;Lars, the label could appear at the same level as the closing brace, unindented. Another approach would be to use boldface, color, or comments to highlight the label. In any case, the label would always go near the end of the function.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Thanks for the comments! You&#8217;ve made this the most active thread in the history of the blog. <img src='http://lapcatsoftware.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Daniel, I agree that nested <code>if</code> structures are appropriate for some situations. However, a typical pattern is to check for fatal errors at the beginning of a function, and I prefer not have my entire implementation within a giant <code>if</code> clause. If I understand what you&#8217;re describing, I think that mid-implementation cleanup code could be accommodated within the <code>goto</code> schema, though of course it depends on the exact nature of the code. To clarify, I am advocating a single exit point rather than multiple <code>goto</code> destinations.</p>
<p>Another advantage I see with <code>goto</code> statements is that if you customize the labels according to the function, e.g., <code>returnFromDoSomethingWithArgument:</code>, then at any time you can perform a project search and immediately find not only the end of the function but all of the exit conditions for the function as well.</p>
<p>Lars, the label could appear at the same level as the closing brace, unindented. Another approach would be to use boldface, color, or comments to highlight the label. In any case, the label would always go near the end of the function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars</title>
		<link>http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/comment-page-1/#comment-16</link>
		<dc:creator>Lars</dc:creator>
		<pubDate>Wed, 18 Oct 2006 01:17:14 +0000</pubDate>
		<guid isPermaLink="false">http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/#comment-16</guid>
		<description>&quot; The point of this experimentation was not simply aesthetic, although I do believe that eye-appeal is important when youâ€™re staring at something for hours a day&quot;

Hear, hear! I wish more programmers would take this sentence to heart!

Among the books[1] I read for my software development, two of the more important ones had nothing to do with programming at all - instead they covered the ins and outs of text design and layout. Reading them gave me an appreciation for how much information can be conveyed by the mere arrangement of text elements. Since then, I try to make the code I write to pass the squint test: if I squint my eyes so that the individual letters would blur into a gray blobs, coud I still make out the control flow of my program. If not, I did something wrong (for example the goto example would fail the test as the goto label is too far indented for its possible uses).

[1] Since I&#039;m not paid for it, I might as well mention one of them: Robin Williams &quot;The Non-Designer&#039;s Design Book&quot;.</description>
		<content:encoded><![CDATA[<p>&#8221; The point of this experimentation was not simply aesthetic, although I do believe that eye-appeal is important when youâ€™re staring at something for hours a day&#8221;</p>
<p>Hear, hear! I wish more programmers would take this sentence to heart!</p>
<p>Among the books[1] I read for my software development, two of the more important ones had nothing to do with programming at all &#8211; instead they covered the ins and outs of text design and layout. Reading them gave me an appreciation for how much information can be conveyed by the mere arrangement of text elements. Since then, I try to make the code I write to pass the squint test: if I squint my eyes so that the individual letters would blur into a gray blobs, coud I still make out the control flow of my program. If not, I did something wrong (for example the goto example would fail the test as the goto label is too far indented for its possible uses).</p>
<p>[1] Since I&#8217;m not paid for it, I might as well mention one of them: Robin Williams &#8220;The Non-Designer&#8217;s Design Book&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/comment-page-1/#comment-15</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Wed, 18 Oct 2006 00:01:55 +0000</pubDate>
		<guid isPermaLink="false">http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/#comment-15</guid>
		<description>I hate dangling braces {
Very hard to read and match them up. You can spend hours wondering why a simple function won&#039;t work properly.
I always have them on a line by themselves
    {
    and the code goes here
    }

And the * always goes next to the identifier, not the type:
int        *x, *y;

Too many of these () is a waste of my time and yours trying to figure out what is going on. One or two extra for things like (a &amp; b) &amp;&amp; (c &amp; d) for those times when you can&#039;t recall what happens first.

Goto:
How about:
if (something bad)
   return kFailure;
if (something else bad)
  return kAnotherError;

// good code goes here

return kAllGood;</description>
		<content:encoded><![CDATA[<p>I hate dangling braces {<br />
Very hard to read and match them up. You can spend hours wondering why a simple function won&#8217;t work properly.<br />
I always have them on a line by themselves<br />
    {<br />
    and the code goes here<br />
    }</p>
<p>And the * always goes next to the identifier, not the type:<br />
int        *x, *y;</p>
<p>Too many of these () is a waste of my time and yours trying to figure out what is going on. One or two extra for things like (a &amp; b) &amp;&amp; (c &amp; d) for those times when you can&#8217;t recall what happens first.</p>
<p>Goto:<br />
How about:<br />
if (something bad)<br />
   return kFailure;<br />
if (something else bad)<br />
  return kAnotherError;</p>
<p>// good code goes here</p>
<p>return kAllGood;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Jalkut</title>
		<link>http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/comment-page-1/#comment-14</link>
		<dc:creator>Daniel Jalkut</dc:creator>
		<pubDate>Tue, 17 Oct 2006 21:25:12 +0000</pubDate>
		<guid isPermaLink="false">http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/#comment-14</guid>
		<description>While I&#039;m not completely against goto statements, in general I stick with the nested if structures. If they start to get too deep, it&#039;s probably a sign that you should add another function call. The use of gotos as you describe usually involves either a layered number of goto destinations at the end of the function, or diligent testing in the &quot;end:&quot; label to make sure everything is properly cleaned up. I prefer nested if loops because I can add the associated cleanup code inside the brackets as soon as I add them, and then fill in the next level of code. And I really don&#039;t think gotos make code any more readable than nested structure.</description>
		<content:encoded><![CDATA[<p>While I&#8217;m not completely against goto statements, in general I stick with the nested if structures. If they start to get too deep, it&#8217;s probably a sign that you should add another function call. The use of gotos as you describe usually involves either a layered number of goto destinations at the end of the function, or diligent testing in the &#8220;end:&#8221; label to make sure everything is properly cleaned up. I prefer nested if loops because I can add the associated cleanup code inside the brackets as soon as I add them, and then fill in the next level of code. And I really don&#8217;t think gotos make code any more readable than nested structure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/comment-page-1/#comment-13</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Tue, 17 Oct 2006 21:21:57 +0000</pubDate>
		<guid isPermaLink="false">http://lapcatsoftware.com/blog/2006/10/17/a-matter-of-style/#comment-13</guid>
		<description>â€œâ€¦int *array[50] does not declare a pointer to an array of integers but rather an array of pointers to integersâ€¦â€

You might think that you could introduce parentheses to clarify this: &lt;code&gt;int (*array)[50]&lt;/code&gt;. But C (or at least GCC) gets this backwards: That gets you a pointer to an array, not an array of pointers. The parenthesized code for what you wanted is &lt;code&gt;int *(array[50])&lt;/code&gt;, which of course reads the other way (as a pointer to an array).

I suppose this is one reason why people don&#039;t parenthesize their declarations.</description>
		<content:encoded><![CDATA[<p>â€œâ€¦int *array[50] does not declare a pointer to an array of integers but rather an array of pointers to integersâ€¦â€</p>
<p>You might think that you could introduce parentheses to clarify this: <code>int (*array)[50]</code>. But C (or at least GCC) gets this backwards: That gets you a pointer to an array, not an array of pointers. The parenthesized code for what you wanted is <code>int *(array[50])</code>, which of course reads the other way (as a pointer to an array).</p>
<p>I suppose this is one reason why people don&#8217;t parenthesize their declarations.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
