<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Coding best practices: thinking about it</title>
	<atom:link href="http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/feed/" rel="self" type="application/rss+xml" />
	<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/</link>
	<description>A serialization of my programming ideas and day-by-day experiences</description>
	<lastBuildDate>Mon, 21 Sep 2009 19:57:23 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: fcoury</title>
		<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-10</link>
		<dc:creator>fcoury</dc:creator>
		<pubDate>Wed, 16 Aug 2006 16:44:39 +0000</pubDate>
		<guid isPermaLink="false">https://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-10</guid>
		<description>Oliver,

Yes, I think that maybe those issues are just cosmetics but anyway I like to analyze whether I want or not to have an Exception thrown in the method I am creating. 

Sometimes protecting for nulls does more harm than good. Sometimes it masks errors that should be thrown.

Well, well maybe that&#039;s just &quot;much ado about nothing&quot; :)</description>
		<content:encoded><![CDATA[<p>Oliver,</p>
<p>Yes, I think that maybe those issues are just cosmetics but anyway I like to analyze whether I want or not to have an Exception thrown in the method I am creating. </p>
<p>Sometimes protecting for nulls does more harm than good. Sometimes it masks errors that should be thrown.</p>
<p>Well, well maybe that&#8217;s just &#8220;much ado about nothing&#8221; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olivier Ansaldi</title>
		<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-9</link>
		<dc:creator>Olivier Ansaldi</dc:creator>
		<pubDate>Wed, 16 Aug 2006 13:35:31 +0000</pubDate>
		<guid isPermaLink="false">https://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-9</guid>
		<description>Felipe,
yes, your code won&#039;t blow up when it encounters a user named &lt;code&gt;null&lt;/code&gt;, but I wrote the test the other way because:

&lt;code&gt;null&lt;/code&gt; is not a valid name so throwing an exception is ok,
it makes the code more english-like: &quot;if the username is the one we are looking for&quot; rather than &quot;if the username we are looking for is the name of the user&quot;.

At this point we&#039;re discussing cosmetics! ;-)</description>
		<content:encoded><![CDATA[<p>Felipe,<br />
yes, your code won&#8217;t blow up when it encounters a user named <code>null</code>, but I wrote the test the other way because:</p>
<p><code>null</code> is not a valid name so throwing an exception is ok,<br />
it makes the code more english-like: &#8220;if the username is the one we are looking for&#8221; rather than &#8220;if the username we are looking for is the name of the user&#8221;.</p>
<p>At this point we&#8217;re discussing cosmetics! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fcoury</title>
		<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-8</link>
		<dc:creator>fcoury</dc:creator>
		<pubDate>Wed, 16 Aug 2006 11:27:52 +0000</pubDate>
		<guid isPermaLink="false">https://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-8</guid>
		<description>Last sentence should be:

&quot;Anyway, like I said, it’s *NOT* a major problem&quot;

:-)</description>
		<content:encoded><![CDATA[<p>Last sentence should be:</p>
<p>&#8220;Anyway, like I said, it’s *NOT* a major problem&#8221;</p>
<p> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fcoury</title>
		<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-7</link>
		<dc:creator>fcoury</dc:creator>
		<pubDate>Wed, 16 Aug 2006 10:46:47 +0000</pubDate>
		<guid isPermaLink="false">https://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-7</guid>
		<description>Well Tom, first of all, thanks for your comments. I tend to agree with you regarding that each case must be analyzed for the better approach: single or multiple returns.

However, I disagree that using multiple return increases the difficulty to maintain and the content/complexity of a procedure. What I found is that even in complex code, the return statement makes it clear because when another user is evaluating the code and reaches for a return statement it doesn&#039;t goes on with the evaluation thinking about something like &quot;oh! there was an if up there so this else is evaluated when...&quot;.

Anyway, like I said, it’s a major problem :-)</description>
		<content:encoded><![CDATA[<p>Well Tom, first of all, thanks for your comments. I tend to agree with you regarding that each case must be analyzed for the better approach: single or multiple returns.</p>
<p>However, I disagree that using multiple return increases the difficulty to maintain and the content/complexity of a procedure. What I found is that even in complex code, the return statement makes it clear because when another user is evaluating the code and reaches for a return statement it doesn&#8217;t goes on with the evaluation thinking about something like &#8220;oh! there was an if up there so this else is evaluated when&#8230;&#8221;.</p>
<p>Anyway, like I said, it’s a major problem <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Landspurg</title>
		<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-6</link>
		<dc:creator>Thomas Landspurg</dc:creator>
		<pubDate>Wed, 16 Aug 2006 08:03:24 +0000</pubDate>
		<guid isPermaLink="false">https://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-6</guid>
		<description>I think it&#039;s more a matter of good sense....complex functions with one return statment might be hard to understand, because they bring a lot of code to manage the single return statment. But help to maintain pre and post function checking, debugging entry point, etc...

On the opposite, using too many return statment might break the control flow of an app, increase the difficulty to maintain..By using mutliploe return statment, people usually tend to increase the content of a single procedure, and so the complexity. The worst is when an app duplicate some lines of code because there is several entry point....

My recommendation is the following:
- try to maintain a single return statment
- unless it create &quot;more &quot; (and this the difficulty) complexity than several return

So in other word, keep the single return as a recommendation, but not as an obligation.....</description>
		<content:encoded><![CDATA[<p>I think it&#8217;s more a matter of good sense&#8230;.complex functions with one return statment might be hard to understand, because they bring a lot of code to manage the single return statment. But help to maintain pre and post function checking, debugging entry point, etc&#8230;</p>
<p>On the opposite, using too many return statment might break the control flow of an app, increase the difficulty to maintain..By using mutliploe return statment, people usually tend to increase the content of a single procedure, and so the complexity. The worst is when an app duplicate some lines of code because there is several entry point&#8230;.</p>
<p>My recommendation is the following:<br />
- try to maintain a single return statment<br />
- unless it create &#8220;more &#8221; (and this the difficulty) complexity than several return</p>
<p>So in other word, keep the single return as a recommendation, but not as an obligation&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fcoury</title>
		<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-5</link>
		<dc:creator>fcoury</dc:creator>
		<pubDate>Wed, 16 Aug 2006 02:03:55 +0000</pubDate>
		<guid isPermaLink="false">https://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-5</guid>
		<description>Olivier,

Regarding your question:

You are right, getAllUsers() shouldn&#039;t return a null item at all. And
better yet, if getAllUsers() has a null user, it is desirable that a
NullPointerException is thrown there. I wrote the null check without
thinking about it ;-)

Regarding that code, there is an additional tip that I don&#039;t know if
you know yet.

Notice that in my code I wrote:

if (u != null &amp;&amp; name.equals(u.getName())) {
   return true;
}

Taking off the &quot;u != null&quot; part, I have used name.equals(u.getName()).
This is a suberb protection for users with null name. Notice that the
&quot;name&quot; parameter is not likely to be null, so you are better off
doing:

name.equals(u.getName())

than

u.getName().equals(name)

because if u.getName() is null, the first comparation will return
false and the second will raise an exception.

Hope this helps you somehow and thanks again for your comments on my
post. That&#039;s what make posting on a blog worth.

Best regards,</description>
		<content:encoded><![CDATA[<p>Olivier,</p>
<p>Regarding your question:</p>
<p>You are right, getAllUsers() shouldn&#8217;t return a null item at all. And<br />
better yet, if getAllUsers() has a null user, it is desirable that a<br />
NullPointerException is thrown there. I wrote the null check without<br />
thinking about it <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Regarding that code, there is an additional tip that I don&#8217;t know if<br />
you know yet.</p>
<p>Notice that in my code I wrote:</p>
<p>if (u != null &amp;&amp; name.equals(u.getName())) {<br />
   return true;<br />
}</p>
<p>Taking off the &#8220;u != null&#8221; part, I have used name.equals(u.getName()).<br />
This is a suberb protection for users with null name. Notice that the<br />
&#8220;name&#8221; parameter is not likely to be null, so you are better off<br />
doing:</p>
<p>name.equals(u.getName())</p>
<p>than</p>
<p>u.getName().equals(name)</p>
<p>because if u.getName() is null, the first comparation will return<br />
false and the second will raise an exception.</p>
<p>Hope this helps you somehow and thanks again for your comments on my<br />
post. That&#8217;s what make posting on a blog worth.</p>
<p>Best regards,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olivier Ansaldi</title>
		<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-4</link>
		<dc:creator>Olivier Ansaldi</dc:creator>
		<pubDate>Tue, 15 Aug 2006 22:51:40 +0000</pubDate>
		<guid isPermaLink="false">https://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-4</guid>
		<description>... if only wordpress wasn&#039;t messing up indentation in the comments!</description>
		<content:encoded><![CDATA[<p>&#8230; if only wordpress wasn&#8217;t messing up indentation in the comments!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olivier Ansaldi</title>
		<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-3</link>
		<dc:creator>Olivier Ansaldi</dc:creator>
		<pubDate>Tue, 15 Aug 2006 22:50:59 +0000</pubDate>
		<guid isPermaLink="false">https://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-3</guid>
		<description>Hi Felipe,
I would agree with your point, multiple return points in this case make the method more readable. There is just one thing that puzzles me: why do you check for a &lt;code&gt;null&lt;/code&gt; user? If &lt;code&gt;getAllUsers()&lt;/code&gt; ever returns a &lt;code&gt;null&lt;/code&gt; user, I would say this is a bug: who the heck is &lt;code&gt;null&lt;/code&gt;? Can &lt;code&gt;null&lt;/code&gt; ever log in?
Rewriting the method without this check makes it read almost like plain english:
&lt;code&gt;
private boolean userExists(String name) {
  for (User u : getAllUsers()) {
    if (u.getName().equals(name)) {
      return true;
    }
  }
  return false;
}
&lt;/code&gt;
Wouldn&#039;t you agree?</description>
		<content:encoded><![CDATA[<p>Hi Felipe,<br />
I would agree with your point, multiple return points in this case make the method more readable. There is just one thing that puzzles me: why do you check for a <code>null</code> user? If <code>getAllUsers()</code> ever returns a <code>null</code> user, I would say this is a bug: who the heck is <code>null</code>? Can <code>null</code> ever log in?<br />
Rewriting the method without this check makes it read almost like plain english:<br />
<code><br />
private boolean userExists(String name) {<br />
  for (User u : getAllUsers()) {<br />
    if (u.getName().equals(name)) {<br />
      return true;<br />
    }<br />
  }<br />
  return false;<br />
}<br />
</code><br />
Wouldn&#8217;t you agree?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcio</title>
		<link>http://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-2</link>
		<dc:creator>Marcio</dc:creator>
		<pubDate>Tue, 15 Aug 2006 20:42:15 +0000</pubDate>
		<guid isPermaLink="false">https://felipecoury.wordpress.com/2006/08/15/coding-best-practices-thinking-about-it/#comment-2</guid>
		<description>Felipe, encontrei esse link onde tem mais argumentos a favor do que você esta falando.
http://onthethought.blogspot.com/2004/12/multiple-return-statements.html</description>
		<content:encoded><![CDATA[<p>Felipe, encontrei esse link onde tem mais argumentos a favor do que você esta falando.<br />
<a href="http://onthethought.blogspot.com/2004/12/multiple-return-statements.html" rel="nofollow">http://onthethought.blogspot.com/2004/12/multiple-return-statements.html</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
