<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://consultingblogs.emc.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Anthony Steele's Blog : law</title><link>http://consultingblogs.emc.com/anthonysteele/archive/tags/law/default.aspx</link><description>Tags: law</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP3 (Build: 20423.1)</generator><item><title>A method should have only one return statement. Discuss.</title><link>http://consultingblogs.emc.com/anthonysteele/archive/2008/07/14/a-method-should-have-only-one-return-statement-discuss.aspx</link><pubDate>Mon, 14 Jul 2008 14:56:00 GMT</pubDate><guid isPermaLink="false">e847c0e7-38d9-45c0-b593-56747303e088:11833</guid><dc:creator>Anthony.Steele</dc:creator><slash:comments>0</slash:comments><comments>http://consultingblogs.emc.com/anthonysteele/comments/11833.aspx</comments><wfw:commentRss>http://consultingblogs.emc.com/anthonysteele/commentrss.aspx?PostID=11833</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;CODE&gt;&lt;FONT face="Times New Roman" size=3&gt;I heard again recently that "A method should have only one return statement" and of "The single-return law", that more than one return was a poor coding practice. I disagree. &lt;/FONT&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;CODE&gt;&lt;/CODE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;CODE&gt;public int IsThisCodeSoBad(int param)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp; if (param == 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/CODE&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;CODE&gt;&amp;nbsp;&amp;nbsp; foreach(foo in bar)&lt;BR&gt;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If foo.fish()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp; }&lt;/CODE&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;CODE&gt;&amp;nbsp;&amp;nbsp; return 2;&lt;BR&gt;}&lt;/CODE&gt;&lt;CODE&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;I&amp;nbsp;have never seen any evidence for the belief that that multiple exit points pose a coding risk, or are bad style. I do not know of any formal study that has found this to be the case, on C# code or on code in any other language. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Coding horror recently talked about "&lt;A class="" href="http://www.codinghorror.com/blog/archives/001148.html"&gt;Spartan programming&lt;/A&gt;", and mentioned "frugal use of control structures, with early return whenever possible." &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;One of the few links on the topic that I could find was "Return statements and the single exit fantasy":&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;A class="" href="http://www.leepoint.net/JavaBasics/methods/method-commentary/methcom-30-multiple-return.html"&gt;http://www.leepoint.net/JavaBasics/methods/method-commentary/methcom-30-multiple-return.html&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Take a look at some of the comments on the Daily WTF (&lt;A class="" href="http://thedailywtf.com/Articles/Refactoring_to_the_Max.aspx"&gt;http://thedailywtf.com/Articles/Refactoring_to_the_Max.aspx&lt;/A&gt; ) where this issue is raised, particularly this one:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Re: Refactoring to the Max&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;2006-04-05 02:25 • by John Hensley&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The main reason for the single return "law" in C is to make sure you &lt;/FONT&gt;&lt;FONT face="Times New Roman" size=3&gt;clean up memory, locks, handles, etc. before you leave a function.&lt;/FONT&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This, on the other hand, is Java code.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Apparently the reason for this "law" was that when coding in C or the like, it was natural to deallocate resources near the end of the function. Thus any extra exit points were an invitation to memory leaks. There are two reasons why this is no longer the case:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;B&gt;Firstly&lt;/B&gt;, garbage collected languages make explicit deallocation unnecessary in most cases.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;B&gt;Secondly&lt;/B&gt;, &lt;/FONT&gt;&lt;CODE&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;try...finally&lt;/SPAN&gt;&lt;/CODE&gt;&lt;FONT face="Times New Roman" size=3&gt; blocks and &lt;/FONT&gt;&lt;CODE&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;using&lt;/SPAN&gt;&lt;/CODE&gt;&lt;FONT face="Times New Roman" size=3&gt; statements allow deallocation to happen with greater certainly at the end of any block of code when it is needed.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;BR&gt;&lt;FONT face="Times New Roman" size=3&gt;In any event, a function with multiple exit points is a far lesser issue than a &lt;A class="" href="http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html"&gt;goto&lt;/A&gt;.&amp;nbsp;In some cases it is the simplest way to code now that we have control structures to deal with it.&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="Times New Roman" size=3&gt;But beware of returns in the middle of loops or highly nested code. All other things being equal, avoid them,&amp;nbsp;since they are&amp;nbsp;less readable and predictable. &lt;BR&gt;&lt;BR&gt;It is absolutely fine to use it as a first check on the parameters after entering a function, before getting down to the serious work and allocating those resources,– it's more readable than embedding the rest of the function in an if-block. However throwing an exception is the more usual case for this.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;My view of the matter is:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;UL style="MARGIN-TOP:0cm;"&gt;
&lt;LI class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;There are cases where a single return is more readable, and cases where it isn't. See if it reduces the number of lines of code, makes the logic clearer or makes the control structures less deeply nested.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;More than one return style may be a bad habit in C code, but there is no evidence for it being bad in more modern languages.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;There is no law requiring only one exit point for a method. Some people have an unsubstantiated belief in the superiority of this style.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Requiring fewer return statements for purposes of centralising resource deallocation is not a common need in modern languages that have garbage collection and &lt;/FONT&gt;&lt;CODE&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;try..finally&lt;/SPAN&gt;&lt;/CODE&gt;&lt;FONT face="Times New Roman" size=3&gt; blocks.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Therefore, use as many returns as suits your artistic sensibilities, because it is a layout and readability issue, not a technical one.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;There's another issue at play here, about rules being adhered to without people grasping the reason why they are adhering to them, and thus keeping the rule in force after the need for it has evaporated. Rules should be given along with reasons for them.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Addendum:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Watching the DailyWTF commentators (who have a fairly high opinion of their own coding skills, given that they are essentially gathered there to point and laugh) try and repeatedly fail to translate the following code into a single expression underscores that the multiple-exit points version can be in some cases easier to understand, read, and modify: &lt;/FONT&gt;&lt;/P&gt;&lt;PRE style="MARGIN-LEFT:36pt;"&gt;&lt;PRE style="MARGIN-LEFT:36pt;"&gt;&lt;CODE&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;if (condition1(x)) &lt;BR&gt;&amp;nbsp; return true;&lt;BR&gt;if (condition2(x)) &lt;BR&gt;&amp;nbsp; return false;&lt;BR&gt;if (condition3(x)) &lt;BR&gt;&amp;nbsp; return true;&lt;BR&gt;return false;&lt;BR&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/PRE&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Times New Roman" size=3&gt;You'd think that this is the same as &lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;CODE&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;return condition1(x) || !condition2(x) || condition3(x);&lt;/SPAN&gt;&lt;/CODE&gt;&lt;FONT face="Times New Roman" size=3&gt;, &lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;However the one-liner version returns true if all conditions are false, unlike the original. Furthermore, it evaluates condition3 if condition2 is true, which the original does not. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;You could also code it as:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;o:p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool result = false;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;if (condition1(x)) &lt;BR&gt;&amp;nbsp; result = true;&lt;BR&gt;if (condition2(x)) &lt;BR&gt;&amp;nbsp; result = false;&lt;BR&gt;if (condition3(x)) &lt;BR&gt;&amp;nbsp; result = true;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;return result;&lt;BR&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;However this also evaluates condition3 if condition2 is true, which the original does not. I'm sure that the original logic &lt;I&gt;can&lt;/I&gt; be replicated with only one return, but it's not going to be as elegant.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;&lt;o:p&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;Update: Richard Tobin has sent me this comment by email:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;This discussion is a common one that we continually face where I work.&amp;nbsp; I took your example and reworked it into a single return as follows:&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE:10pt;LINE-HEIGHT:115%;FONT-FAMILY:'Tahoma','sans-serif';"&gt;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:'Lucida Console';mso-bidi-font-family:Tahoma;"&gt;private&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;LINE-HEIGHT:115%;FONT-FAMILY:'Lucida Console';mso-bidi-font-family:Tahoma;"&gt; &lt;SPAN style="COLOR:blue;"&gt;bool&lt;/SPAN&gt; LotsOfReturns(&lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; x)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR:blue;"&gt;if&lt;/SPAN&gt; (Condition1(x))&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;true&lt;/SPAN&gt;;&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt; (Condition2(x))&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;false&lt;/SPAN&gt;;&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt; (Condition3(x))&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;true&lt;/SPAN&gt;;&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;false&lt;/SPAN&gt;;&lt;BR&gt;}&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;bool&lt;/SPAN&gt; OneReturn(&lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; x)&lt;BR&gt;{&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool&lt;/SPAN&gt; flag = Condition1(x);&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt; (!flag)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt; (!Condition2(x))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; flag = Condition3(x);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/SPAN&gt; flag;&lt;BR&gt;}&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;LINE-HEIGHT:115%;FONT-FAMILY:'Tahoma','sans-serif';"&gt;&amp;nbsp;&lt;BR&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;After compiling and looking at the IL with Reflector, the single return routine seemed more compact and efficient, and the C# source seems less tricky.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 10pt;"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;All I can really say is that he has suceeded in converting the code, and which one "seems less tricky" is going to be a matter of taste.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 10pt;"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 10pt;"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://consultingblogs.emc.com/aggbug.aspx?PostID=11833" width="1" height="1"&gt;</description><category domain="http://consultingblogs.emc.com/anthonysteele/archive/tags/code/default.aspx">code</category><category domain="http://consultingblogs.emc.com/anthonysteele/archive/tags/technical/default.aspx">technical</category><category domain="http://consultingblogs.emc.com/anthonysteele/archive/tags/code+standards/default.aspx">code standards</category><category domain="http://consultingblogs.emc.com/anthonysteele/archive/tags/code+review/default.aspx">code review</category><category domain="http://consultingblogs.emc.com/anthonysteele/archive/tags/nitpicking/default.aspx">nitpicking</category><category domain="http://consultingblogs.emc.com/anthonysteele/archive/tags/rule/default.aspx">rule</category><category domain="http://consultingblogs.emc.com/anthonysteele/archive/tags/law/default.aspx">law</category><category domain="http://consultingblogs.emc.com/anthonysteele/archive/tags/return/default.aspx">return</category></item></channel></rss>