<?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: Braceless if considered harmful</title>
	<atom:link href="http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/</link>
	<description>Longer than a blog; shorter than a book</description>
	<lastBuildDate>Tue, 09 Mar 2010 18:31:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: 123</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-377305</link>
		<dc:creator>123</dc:creator>
		<pubDate>Sat, 28 Mar 2009 22:05:43 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-377305</guid>
		<description>If you&#039;re dumba$$ enough to not notice the bug in this example IMMEDIATELY, you need to switch professions fast, not ruin others&#039; code with your overly verbose, ugly crutch.

if (x &gt; 3)
__y = x - 3;
__doSomething(x);
// continue with rest of program...</description>
		<content:encoded><![CDATA[<p>If you&#8217;re dumba$$ enough to not notice the bug in this example IMMEDIATELY, you need to switch professions fast, not ruin others&#8217; code with your overly verbose, ugly crutch.</p>
<p>if (x &gt; 3)<br />
__y = x &#8211; 3;<br />
__doSomething(x);<br />
// continue with rest of program&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean M. Cox</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-178881</link>
		<dc:creator>Sean M. Cox</dc:creator>
		<pubDate>Fri, 18 Jan 2008 22:07:35 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-178881</guid>
		<description>Personally, I like to have simple single line if statements without the braces. I did it the other way for years until I discovered that braces weren&#039;t required. (Learned it from the source library for the standard Java classes.) To me, the code is just much prettier - cleaner looking - without the braces and I, personally, have never run into any of the issues that have been described. However, I can certainly imagine that some might have trouble following the braces, or lack thereof. For me it has worked and the aesthetic satisfaction I get from looking at the code produced weighs in significantly against the potential bugs that I have never experienced.

I also like to keep my conditions separate from the code that depends on them as I find it more readable that way. (Especially when I have a moderately length condition or longer.)

Certainly this could be different in a collaborative environment.</description>
		<content:encoded><![CDATA[<p>Personally, I like to have simple single line if statements without the braces. I did it the other way for years until I discovered that braces weren&#8217;t required. (Learned it from the source library for the standard Java classes.) To me, the code is just much prettier &#8211; cleaner looking &#8211; without the braces and I, personally, have never run into any of the issues that have been described. However, I can certainly imagine that some might have trouble following the braces, or lack thereof. For me it has worked and the aesthetic satisfaction I get from looking at the code produced weighs in significantly against the potential bugs that I have never experienced.</p>
<p>I also like to keep my conditions separate from the code that depends on them as I find it more readable that way. (Especially when I have a moderately length condition or longer.)</p>
<p>Certainly this could be different in a collaborative environment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MetaphoriC++</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-151888</link>
		<dc:creator>MetaphoriC++</dc:creator>
		<pubDate>Fri, 09 Nov 2007 04:44:42 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-151888</guid>
		<description>I agree with truth machine. In 20+ years of programming (C, C++, Lisp, Java, Perl and now PHP...) we never met the problem (bug), 
&lt;code&gt;
if (x)
   y();
   z();
&lt;/code&gt;
The code should be indented with the right tool anyway (e.g. Emacs). A good programmer doesn&#039;t fall in such a &quot;trap&quot;.
In Perl when there are a lot of consecutive if-else[if] statement, the code is full of {}s even for single statements - it is harder to read. &lt;code&gt;if (a) { while (b) { if (c) { for (;d;) { e(); } } } } ??&lt;/code&gt;

As for the 
&lt;code&gt;
// A
if (x) {  
   y();
   z();
}

// vs B
if (x) 
{
   y();
   z();
}&lt;/code&gt;
I go for B. Someone will inject a line between the &quot;if&quot; and the &quot;{&quot;? and let the {}s alone??
When there is a lot of nested conditions/while/for... the code is well spaced out, and readability is increased.</description>
		<content:encoded><![CDATA[<p>I agree with truth machine. In 20+ years of programming (C, C++, Lisp, Java, Perl and now PHP&#8230;) we never met the problem (bug),<br />
<code><br />
if (x)<br />
   y();<br />
   z();<br />
</code><br />
The code should be indented with the right tool anyway (e.g. Emacs). A good programmer doesn&#8217;t fall in such a &#8220;trap&#8221;.<br />
In Perl when there are a lot of consecutive if-else[if] statement, the code is full of {}s even for single statements &#8211; it is harder to read. <code>if (a) { while (b) { if (c) { for (;d;) { e(); } } } } ??</code></p>
<p>As for the<br />
<code><br />
// A<br />
if (x) {<br />
   y();<br />
   z();<br />
}</p>
<p>// vs B<br />
if (x)<br />
{<br />
   y();<br />
   z();<br />
}</code><br />
I go for B. Someone will inject a line between the &#8220;if&#8221; and the &#8220;{&#8220;? and let the {}s alone??<br />
When there is a lot of nested conditions/while/for&#8230; the code is well spaced out, and readability is increased.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: truth machine</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-101267</link>
		<dc:creator>truth machine</dc:creator>
		<pubDate>Thu, 14 Jun 2007 08:58:09 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-101267</guid>
		<description>Anyone who can&#039;t immediately see the error in the example with two indented statements without braces is broken; such people are bug-prone in any case, and lord only knows what other blatant bugs they&#039;re missing because they are incapable of reading the language.  But even such broken people can avoid this sort of bug simply by using the right tools -- use an auto-indenting editor and such incidents simply can&#039;t happen.  That&#039;s a far better crutch for those who need one, especially since such broken people are liable to forget to add the required braces -- if they can&#039;t be bothered to notice something as obvious as that they&#039;re adding a second statement to an if block without braces, then they can&#039;t be counted on to add the extra braces.  If I had a maintenance programmer who was that sloppy, I would transfer them immediately to QA where they could experience the consequences of such behavior.</description>
		<content:encoded><![CDATA[<p>Anyone who can&#8217;t immediately see the error in the example with two indented statements without braces is broken; such people are bug-prone in any case, and lord only knows what other blatant bugs they&#8217;re missing because they are incapable of reading the language.  But even such broken people can avoid this sort of bug simply by using the right tools &#8212; use an auto-indenting editor and such incidents simply can&#8217;t happen.  That&#8217;s a far better crutch for those who need one, especially since such broken people are liable to forget to add the required braces &#8212; if they can&#8217;t be bothered to notice something as obvious as that they&#8217;re adding a second statement to an if block without braces, then they can&#8217;t be counted on to add the extra braces.  If I had a maintenance programmer who was that sloppy, I would transfer them immediately to QA where they could experience the consequences of such behavior.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-35196</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Wed, 06 Dec 2006 23:37:31 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-35196</guid>
		<description>The problems described above would not happen in a Test Driven Development environment (typically XP shops). 
If I&#039;m not attentive and forget my braces, I&#039;ll discover my error in the next few minutes.

&quot;What if someone adds another line and forgets to add the braces?&quot; - This is fear-based programming and has no place in confident, courageous coding.</description>
		<content:encoded><![CDATA[<p>The problems described above would not happen in a Test Driven Development environment (typically XP shops).<br />
If I&#8217;m not attentive and forget my braces, I&#8217;ll discover my error in the next few minutes.</p>
<p>&#8220;What if someone adds another line and forgets to add the braces?&#8221; &#8211; This is fear-based programming and has no place in confident, courageous coding.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Cafes &#187; RatJava</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-29831</link>
		<dc:creator>The Cafes &#187; RatJava</dc:creator>
		<pubDate>Mon, 13 Nov 2006 18:24:13 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-29831</guid>
		<description>[...] Smart developers have known for years that braceless multiline statements are bug prone. The problem is that the indentation can be actively misleading and cause bugs during code evolution and maintenance. For example, suppose you start with this if statement: [...]</description>
		<content:encoded><![CDATA[<p>[...] Smart developers have known for years that braceless multiline statements are bug prone. The problem is that the indentation can be actively misleading and cause bugs during code evolution and maintenance. For example, suppose you start with this if statement: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Masklinn</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-17691</link>
		<dc:creator>Masklinn</dc:creator>
		<pubDate>Sat, 23 Sep 2006 19:32:01 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-17691</guid>
		<description>&gt; will always run dosomethingelse() IT IS SUPPOSED TO WORK THAT WAY. You see?

The point of the post is that 95% of the time it isn&#039;t supposed to work that way, and it&#039;s a bug.

And when it&#039;s supposed to work that way and isn&#039;t a bug, then it&#039;s sheer stupidity, because most programmer&#039;s eyes are trained to check the fastest way to see blocks: check indentation.

Therefore most people will think that dosomethingelse() is inside the if block, and will misunderstand the code unless they take a second look at the exact code.

Therefore, that kind of code is either a &quot;software bug&quot; (the software will be buggy) or a &quot;programmer bug&quot; (the programmer won&#039;t get the code, and will be buggy).

&gt;  if (x&gt;3)
&gt; {
&gt; ####dosomething();
&gt; }
&gt; Is simply an excesive usage of space for a single-line if.

And this is why Kernighan and Ritchie invented the K&amp;R style
if (x&gt;3) {
    doSomething();
}

Look &#039;ma, no excessive use of space even for single-line conditionals!</description>
		<content:encoded><![CDATA[<p>&gt; will always run dosomethingelse() IT IS SUPPOSED TO WORK THAT WAY. You see?</p>
<p>The point of the post is that 95% of the time it isn&#8217;t supposed to work that way, and it&#8217;s a bug.</p>
<p>And when it&#8217;s supposed to work that way and isn&#8217;t a bug, then it&#8217;s sheer stupidity, because most programmer&#8217;s eyes are trained to check the fastest way to see blocks: check indentation.</p>
<p>Therefore most people will think that dosomethingelse() is inside the if block, and will misunderstand the code unless they take a second look at the exact code.</p>
<p>Therefore, that kind of code is either a &#8220;software bug&#8221; (the software will be buggy) or a &#8220;programmer bug&#8221; (the programmer won&#8217;t get the code, and will be buggy).</p>
<p>&gt;  if (x&gt;3)<br />
&gt; {<br />
&gt; ####dosomething();<br />
&gt; }<br />
&gt; Is simply an excesive usage of space for a single-line if.</p>
<p>And this is why Kernighan and Ritchie invented the K&amp;R style<br />
if (x&gt;3) {<br />
    doSomething();<br />
}</p>
<p>Look &#8216;ma, no excessive use of space even for single-line conditionals!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: disgusted</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-15545</link>
		<dc:creator>disgusted</dc:creator>
		<pubDate>Thu, 14 Sep 2006 16:09:32 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-15545</guid>
		<description>if (x&gt;3)
####dosomething();

Now if I want to add a line of code:

if (x&gt;3)
{
####dosomething();
####dosomethingelse();
}

(used # instead of spaces in the case this form would cut blank space) 
You see? I know that not using {} only works for one line. The fact that I used braceless if in the first time is proof that I already know about this. And I also know that the compiler ignores whitespace so if:

if (x&gt;3)
####dosomething();
####dosomethingelse();

will always run dosomethingelse() IT IS SUPPOSED TO WORK THAT WAY. You see? I am coding in JAVA/ C++ / C# I am sure that I am not coding in python, so I can&#039;t expect that if to cover both statements just because of the identation.


 if (x&gt;3)
 {
 ####dosomething();
 }

Is simply an excesive usage of space for a single-line if. In my opinion, others may argue that but that&#039;s the good thing about this world, I can use that syntax, I am not using a condescendant compiler that expects me to make silly mistakes.

But in my opinion the best would be if (x&gt;3) dosomething() ;  It is logical, it is short and prevents the first mistake.


&quot;However in the heat of programming, especially maintenance programming, itâ€™s really easy to miss this&quot; </description>
		<content:encoded><![CDATA[<p>if (x&gt;3)<br />
####dosomething();</p>
<p>Now if I want to add a line of code:</p>
<p>if (x&gt;3)<br />
{<br />
####dosomething();<br />
####dosomethingelse();<br />
}</p>
<p>(used # instead of spaces in the case this form would cut blank space)<br />
You see? I know that not using {} only works for one line. The fact that I used braceless if in the first time is proof that I already know about this. And I also know that the compiler ignores whitespace so if:</p>
<p>if (x&gt;3)<br />
####dosomething();<br />
####dosomethingelse();</p>
<p>will always run dosomethingelse() IT IS SUPPOSED TO WORK THAT WAY. You see? I am coding in JAVA/ C++ / C# I am sure that I am not coding in python, so I can&#8217;t expect that if to cover both statements just because of the identation.</p>
<p> if (x&gt;3)<br />
 {<br />
 ####dosomething();<br />
 }</p>
<p>Is simply an excesive usage of space for a single-line if. In my opinion, others may argue that but that&#8217;s the good thing about this world, I can use that syntax, I am not using a condescendant compiler that expects me to make silly mistakes.</p>
<p>But in my opinion the best would be if (x&gt;3) dosomething() ;  It is logical, it is short and prevents the first mistake.</p>
<p>&#8220;However in the heat of programming, especially maintenance programming, itâ€™s really easy to miss this&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Cowan</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-220</link>
		<dc:creator>John Cowan</dc:creator>
		<pubDate>Thu, 02 Mar 2006 21:19:18 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-220</guid>
		<description>I don&#039;t understand what cuddled elses (putting } on the same line as else/catch) has to do with safety.  Can someone explain that?</description>
		<content:encoded><![CDATA[<p>I don&#8217;t understand what cuddled elses (putting } on the same line as else/catch) has to do with safety.  Can someone explain that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Blewitt</title>
		<link>http://cafe.elharo.com/blogroll/braceless-if-considered-harmful/comment-page-1/#comment-178</link>
		<dc:creator>Alex Blewitt</dc:creator>
		<pubDate>Thu, 23 Feb 2006 13:10:41 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/braceless-if-considered-harmful/#comment-178</guid>
		<description>It&#039;s also a justifiable reason for always putting { on the end of the line, and } else { on the same line. Arguing about aesthetics is one thing (whichever &#039;reads&#039; better to you is the one you&#039;ve been using the most) but putting } and { on the same line as the if/while/for/else/try/catch is the only way to prevent errors by insertion of a line of code. It doesn&#039;t even have to do anything; a System.out.println() will break code if put in the wrong place.

Alex.</description>
		<content:encoded><![CDATA[<p>It&#8217;s also a justifiable reason for always putting { on the end of the line, and } else { on the same line. Arguing about aesthetics is one thing (whichever &#8216;reads&#8217; better to you is the one you&#8217;ve been using the most) but putting } and { on the same line as the if/while/for/else/try/catch is the only way to prevent errors by insertion of a line of code. It doesn&#8217;t even have to do anything; a System.out.println() will break code if put in the wrong place.</p>
<p>Alex.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
