<?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: Multiple Returns from a Single Method</title>
	<atom:link href="http://agilepainrelief.com/notesfromatooluser/2008/08/multiple-returns-from-a-single-method.html/feed" rel="self" type="application/rss+xml" />
	<link>http://agilepainrelief.com/notesfromatooluser/2008/08/multiple-returns-from-a-single-method.html</link>
	<description>Best practices for your goals</description>
	<lastBuildDate>Sat, 13 Mar 2010 23:35:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dave Rooney</title>
		<link>http://agilepainrelief.com/notesfromatooluser/2008/08/multiple-returns-from-a-single-method.html/comment-page-1#comment-152</link>
		<dc:creator>Dave Rooney</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://agilepainrelief.com/2008/08/multiple-returns-from-a-single-method/#comment-152</guid>
		<description>It&#039;s funny - once upon a time I was a die-hard advocate of &quot;one entry point, one exit point&quot; for a method or function.  My main argument for this was that it greatly simplified debugging.  Then, I found out about automated testing in general and TDD in particular and I&#039;ve switched camps to be an advocate of &quot;early returns&quot;!

I would say, though, that early returns don&#039;t necessarily make code less complex.  If the code isn&#039;t well-factored to begin with, they can actually make the code less readable.  I think that maybe a better way to put this is that if the code has good automated tests and is well-factored (according to Beck&#039;s priority list), then early returns can make it even more readable than nested control structures.  There&#039;s a synergy there that needs to be brought to the surface.

Dave...
</description>
		<content:encoded><![CDATA[<p>It&#8217;s funny &#8211; once upon a time I was a die-hard advocate of &#8220;one entry point, one exit point&#8221; for a method or function.  My main argument for this was that it greatly simplified debugging.  Then, I found out about automated testing in general and TDD in particular and I&#8217;ve switched camps to be an advocate of &#8220;early returns&#8221;!</p>
<p>I would say, though, that early returns don&#8217;t necessarily make code less complex.  If the code isn&#8217;t well-factored to begin with, they can actually make the code less readable.  I think that maybe a better way to put this is that if the code has good automated tests and is well-factored (according to Beck&#8217;s priority list), then early returns can make it even more readable than nested control structures.  There&#8217;s a synergy there that needs to be brought to the surface.</p>
<p>Dave&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BlogReader</title>
		<link>http://agilepainrelief.com/notesfromatooluser/2008/08/multiple-returns-from-a-single-method.html/comment-page-1#comment-153</link>
		<dc:creator>BlogReader</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://agilepainrelief.com/2008/08/multiple-returns-from-a-single-method/#comment-153</guid>
		<description>I like multiple return statements not just for cutting down on if..then indentation but to show the reader where the meaty problems like.  That is, I exit early in simple cases to show the reader that these problems were easily taken care of.  If you continue on in the method means something harder had to be done.
</description>
		<content:encoded><![CDATA[<p>I like multiple return statements not just for cutting down on if..then indentation but to show the reader where the meaty problems like.  That is, I exit early in simple cases to show the reader that these problems were easily taken care of.  If you continue on in the method means something harder had to be done.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xcd esz</title>
		<link>http://agilepainrelief.com/notesfromatooluser/2008/08/multiple-returns-from-a-single-method.html/comment-page-1#comment-154</link>
		<dc:creator>xcd esz</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://agilepainrelief.com/2008/08/multiple-returns-from-a-single-method/#comment-154</guid>
		<description>Some of your points could be reversed.  You say &quot;If more code is added later it might accidentally get run even though its author intended the method to be finished.&quot;  The reverse is more likely to be true.  If a developer goes back to the method and wants to do something with the result set before returning, now he has to find all of the return points.

Having multiple return statements may be easier for you to write, and less &quot;lines of code&quot;.  But as someone who has to maintain others code, I often find myself having to wind my way out of a spaghetti of loose practices such as this.  Yes, if your code only has a few lines, having mutiple returns wont be a problem.  But where do you draw the line?  It is better, IMHO, to stick with the old rule.
</description>
		<content:encoded><![CDATA[<p>Some of your points could be reversed.  You say &#8220;If more code is added later it might accidentally get run even though its author intended the method to be finished.&#8221;  The reverse is more likely to be true.  If a developer goes back to the method and wants to do something with the result set before returning, now he has to find all of the return points.</p>
<p>Having multiple return statements may be easier for you to write, and less &#8220;lines of code&#8221;.  But as someone who has to maintain others code, I often find myself having to wind my way out of a spaghetti of loose practices such as this.  Yes, if your code only has a few lines, having mutiple returns wont be a problem.  But where do you draw the line?  It is better, IMHO, to stick with the old rule.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William Pietri</title>
		<link>http://agilepainrelief.com/notesfromatooluser/2008/08/multiple-returns-from-a-single-method.html/comment-page-1#comment-155</link>
		<dc:creator>William Pietri</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://agilepainrelief.com/2008/08/multiple-returns-from-a-single-method/#comment-155</guid>
		<description>I agree with Dave.

In well-factored code, early returns are fabulous. I use them all the time to dispose of contract violations and degenerate cases, so that the method code can focus on the interesting part of the problem.

They can also be nice when expressing a simple set of rules. E.g., in a Java equals method, I often find it much more readable to express it as a series of &quot;if ... return&quot; lines rather than one giant boolean expression. And I&#039;m sure they have other uses as well.

In ugly code, I do think they can make things mildly uglier. But I think the solution there is refactoring for clarity, not adding rules to try to make mud slightly less dirty.
</description>
		<content:encoded><![CDATA[<p>I agree with Dave.</p>
<p>In well-factored code, early returns are fabulous. I use them all the time to dispose of contract violations and degenerate cases, so that the method code can focus on the interesting part of the problem.</p>
<p>They can also be nice when expressing a simple set of rules. E.g., in a Java equals method, I often find it much more readable to express it as a series of &#8220;if &#8230; return&#8221; lines rather than one giant boolean expression. And I&#8217;m sure they have other uses as well.</p>
<p>In ugly code, I do think they can make things mildly uglier. But I think the solution there is refactoring for clarity, not adding rules to try to make mud slightly less dirty.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
