<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.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>Make your code more maintainable: The evils of the Return statement </title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx</link><description>What does it mean to make code more maintainable? Certainly obfuscated code is hard to understand, by definition. A big part of maintainability is making it easier for others to read and understand what the code is doing. Your code may have been working</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>a-foton &amp;raquo; Make your code more maintainable: The evils of the Return statement</title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx#8785776</link><pubDate>Tue, 29 Jul 2008 00:45:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8785776</guid><dc:creator>a-foton &amp;raquo; Make your code more maintainable: The evils of the Return statement</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://blog.a-foton.ru/2008/07/make-your-code-more-maintainable-the-evils-of-the-return-statement/"&gt;http://blog.a-foton.ru/2008/07/make-your-code-more-maintainable-the-evils-of-the-return-statement/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Make your code more maintainable: The evils of the Return statement </title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx#8790665</link><pubDate>Wed, 30 Jul 2008 06:29:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8790665</guid><dc:creator>Blair</dc:creator><description>&lt;p&gt;That massive 1 line return is a perfect example of a code smell. Anyone who sees something like that instantly needs to refactor it so as to be able to understand what it is trying to do. &lt;/p&gt;
&lt;p&gt;Also the best 1 liner app I know of is the DSCC hack in 1 line of ugly obfusticated PERL.&lt;/p&gt;
</description></item><item><title>Reflective Perspective - Chris Alcock  &amp;raquo; The Morning Brew #147</title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx#8791142</link><pubDate>Wed, 30 Jul 2008 10:27:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8791142</guid><dc:creator>Reflective Perspective - Chris Alcock  &amp;raquo; The Morning Brew #147</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://blog.cwa.me.uk/2008/07/30/the-morning-brew-147/"&gt;http://blog.cwa.me.uk/2008/07/30/the-morning-brew-147/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Dew Drop - July 30, 2008 | Alvin Ashcraft's Morning Dew</title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx#8791495</link><pubDate>Wed, 30 Jul 2008 15:07:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8791495</guid><dc:creator>Dew Drop - July 30, 2008 | Alvin Ashcraft's Morning Dew</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.alvinashcraft.com/2008/07/30/dew-drop-july-30-2008/"&gt;http://www.alvinashcraft.com/2008/07/30/dew-drop-july-30-2008/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Make your code more maintainable: The evils of the Return statement </title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx#8792371</link><pubDate>Wed, 30 Jul 2008 23:27:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8792371</guid><dc:creator>Steve Bohlen</dc:creator><description>&lt;p&gt;This is often made even worse in the cases of a lot of the 'fluent interface' style of coding that seems to be all-the-rage lately and leads one to the 'code-as-sentence' style of developing as in...&lt;/p&gt;
&lt;p&gt;return Customer.Add(order).ToAddress(address).WithShipping(shipping).UsingTaxCode(taxCode).InPackaging(box).WithWrappingPaper(true);&lt;/p&gt;
&lt;p&gt;This may seem like a good idea, but run-on sentences in code are even worse than such things in written prose. &amp;nbsp;A (small) attempt at improved readability may be often attempted by putting each 'phrase' on a separate line as...&lt;/p&gt;
&lt;p&gt;return Customer.Add(order)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;.ToAddress(address)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;.WithShipping(shipping)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;.UsingTaxCode(taxCode)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;.InPackaging(box)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;.WithWrappingPaper(true);&lt;/p&gt;
&lt;p&gt;...but this (code formatting in the source file to address a legibility problem) always seems like an awkward crutch to me.&lt;/p&gt;
</description></item><item><title>Return is useful most anywhere when disciplined</title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx#8804021</link><pubDate>Sat, 02 Aug 2008 06:33:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8804021</guid><dc:creator>Greg</dc:creator><description>&lt;p&gt;Return statements, when used to avoid nesting are quite useful since they guarantee that nothing in the rest of the function (except finally blocks) will be executed.&lt;/p&gt;
&lt;p&gt;function x()&lt;/p&gt;
&lt;p&gt;begin&lt;/p&gt;
&lt;p&gt; &amp;nbsp;if (validate input parameters fails)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; return error value&lt;/p&gt;
&lt;p&gt; &amp;nbsp;end if&lt;/p&gt;
&lt;p&gt; &amp;nbsp;if (cannot open input file)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; return error value 2&lt;/p&gt;
&lt;p&gt; &amp;nbsp;end if&lt;/p&gt;
&lt;p&gt; &amp;nbsp;....&lt;/p&gt;
&lt;p&gt; &amp;nbsp;body of function&lt;/p&gt;
&lt;p&gt; &amp;nbsp;return (return value)&lt;/p&gt;
&lt;p&gt;end if&lt;/p&gt;
&lt;p&gt;That's much much cleaner than overly deep nested if then else blocks.&lt;/p&gt;
&lt;p&gt;This works out to:&lt;/p&gt;
&lt;p&gt;function X()&lt;/p&gt;
&lt;p&gt;begin&lt;/p&gt;
&lt;p&gt; &amp;nbsp; if (A) then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; return&lt;/p&gt;
&lt;p&gt; &amp;nbsp; end if&lt;/p&gt;
&lt;p&gt; &amp;nbsp; 'guaranteed that condition A is false&lt;/p&gt;
&lt;p&gt; &amp;nbsp; if (B) then &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;return&lt;/p&gt;
&lt;p&gt; &amp;nbsp; end if&lt;/p&gt;
&lt;p&gt; &amp;nbsp; 'guaranteed that condition B is false&lt;/p&gt;
&lt;p&gt; &amp;nbsp; ....&lt;/p&gt;
&lt;p&gt;end&lt;/p&gt;
&lt;p&gt;The anti-nesting return when combined with declaring local variables at the innermost scope that they are used can greatly reduce the amount of A) nesting at any given statement in the function and B) greatly reduce the number of NAMES (variables, constants, if conditions, etc) that are in scope for any given line of code.&lt;/p&gt;
&lt;p&gt;This will greatly simplify your code.&lt;/p&gt;
&lt;p&gt;I've seen lots of ex-vb6 developers not use returns and declare all variables at the top of the function (classic ASP maybe) much to the detriment of increasing complexity of the code.&lt;/p&gt;
</description></item><item><title> Calvin Hsia s WebLog Make your code more maintainable The evils of | low cost car insurance</title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx#9766342</link><pubDate>Wed, 17 Jun 2009 08:02:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9766342</guid><dc:creator> Calvin Hsia s WebLog Make your code more maintainable The evils of | low cost car insurance</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://lowcostcarinsurances.info/story.php?id=1039"&gt;http://lowcostcarinsurances.info/story.php?id=1039&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> Calvin Hsia s WebLog Make your code more maintainable The evils of | bar stools</title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx#9780789</link><pubDate>Fri, 19 Jun 2009 09:41:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9780789</guid><dc:creator> Calvin Hsia s WebLog Make your code more maintainable The evils of | bar stools</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://barstoolsite.info/story.php?id=2336"&gt;http://barstoolsite.info/story.php?id=2336&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> Calvin Hsia s WebLog Make your code more maintainable The evils of | debt consolidator</title><link>http://blogs.msdn.com/calvin_hsia/archive/2008/07/28/8785744.aspx#9789358</link><pubDate>Fri, 19 Jun 2009 18:35:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9789358</guid><dc:creator> Calvin Hsia s WebLog Make your code more maintainable The evils of | debt consolidator</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://mydebtconsolidator.info/story.php?id=18423"&gt;http://mydebtconsolidator.info/story.php?id=18423&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>