<?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>Writing less code: The &amp;quot;else&amp;quot; statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx</link><description>Source code is written once; and read over and over again. So make sure it is easy to read and understand. I keep seeing a poor coding practice. I see it in production code, in test code, in X++ code, in C# code, in C++ code, in examples on the web, when</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7857247</link><pubDate>Sat, 23 Feb 2008 16:24:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7857247</guid><dc:creator>Julian</dc:creator><description>&lt;P&gt;The first example is IMNHO better written as:&lt;/P&gt;
&lt;P&gt;boolean isNegative(int value)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return value&amp;lt;0;&lt;BR&gt;} &amp;nbsp;&lt;/P&gt;</description></item><item><title>The Superfluous </title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7857528</link><pubDate>Sat, 23 Feb 2008 17:10:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7857528</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7857602</link><pubDate>Sat, 23 Feb 2008 17:18:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7857602</guid><dc:creator>Mark Wisecarver</dc:creator><description>&lt;p&gt;Coming soon, the elseif boolean command...&lt;/p&gt;
</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7859376</link><pubDate>Sat, 23 Feb 2008 19:51:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7859376</guid><dc:creator>John S.</dc:creator><description>&lt;P&gt;I also like avoiding elses when setting string values. e.g.&lt;/P&gt;
&lt;P&gt;if (true)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;foo = "bar";&lt;BR&gt;}&lt;BR&gt;else&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;foo = "boo"&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;becomes&lt;/P&gt;
&lt;P&gt;foo = "boo";&lt;BR&gt;if (true)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;foo = "bar";&lt;BR&gt;}&lt;/P&gt;</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7862161</link><pubDate>Sat, 23 Feb 2008 23:24:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7862161</guid><dc:creator>Sean Blakemore</dc:creator><description>&lt;p&gt;Wow, I never knew people had a problem with this..&lt;/p&gt;
&lt;p&gt;Although I can see the point with the first and trivial example, I find it easier to visualise the branching in the more complex example when using the &amp;quot;else if&amp;quot; or even the fully expanded version. Actually, it makes way more sense to me to use else blocks, isn't it generally quite rare to have multiple if statements and every possible outcome returns or throws? Because as soon as there is a path that doesn't, it gets way harder to read when don't have the expanded version. Obviously this is all opinion, maybe it comes down to how different people's brains process this sort of thing, but I'm afraid you're all weirdos! :)&lt;/p&gt;
&lt;p&gt;John S: Seriously.. I can't get my head around why you prefer that! I'd just keep the if/else and lose the {}.. Even better, how's this?&lt;/p&gt;
&lt;p&gt;foo = true ? &amp;quot;bar&amp;quot; : &amp;quot;boo&amp;quot;;&lt;/p&gt;
</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7863347</link><pubDate>Sun, 24 Feb 2008 00:49:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7863347</guid><dc:creator>Thomas Widmer</dc:creator><description>&lt;p&gt;I prefer the usage of &amp;quot;else if&amp;quot; as it tells the reader that only one of the two paths is executed, without even looking at the code in-between.&lt;/p&gt;
&lt;p&gt;Because the &amp;quot;return&amp;quot; of &amp;quot;throw&amp;quot; typically is the last statement in before the next &amp;quot;if&amp;quot;, the difference is not huge. But I absolutely do not agree that this his a hard and fast rule, which must be followed &amp;quot;Never-ever-under-any-circumstances-for-any-reason-what-so-ever&amp;quot;.&lt;/p&gt;
</description></item><item><title>Compiler keywords for primitive types? Why?</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7863931</link><pubDate>Sun, 24 Feb 2008 01:33:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7863931</guid><dc:creator>Flawless Code</dc:creator><description>&lt;p&gt;Compiler keywords for primitive types? Why?&lt;/p&gt;
</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7864196</link><pubDate>Sun, 24 Feb 2008 01:51:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7864196</guid><dc:creator>Pavel</dc:creator><description>&lt;p&gt;The opposite advice would be to never ever use &amp;quot;return&amp;quot; other than before the closing brace of the function, since using it elsewhere is essentially equivalent to goto (the same goes for break/continue, by the way).&lt;/p&gt;
&lt;p&gt;Anyway, people who tend to lean towards functional style often prefer explicit &amp;quot;else&amp;quot; there, just out of habit (and because it does look clearer to them).&lt;/p&gt;
</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7864331</link><pubDate>Sun, 24 Feb 2008 02:04:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7864331</guid><dc:creator>ErikW</dc:creator><description>&lt;p&gt;I'd argue that all of your examples are poor programming style. &amp;nbsp;One of the first things drilled into me in school was &amp;quot;One Entrance, One Exit&amp;quot;, and while exceptions toss a monkey wrench in that, I've always believed you should only ever have one return statement in a function.&lt;/p&gt;
&lt;p&gt;One of my biggest beefs with most languages is that their decision and control structures are too rigid. &amp;nbsp;It's hard to get out of a deeply nested structure without using extraneous for-loop breaks or goto's (or worse, using exceptions as gotos).&lt;/p&gt;
&lt;p&gt;I'm not sure what the proper solution is, but it's not the status quo.&lt;/p&gt;
</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7874881</link><pubDate>Sun, 24 Feb 2008 13:00:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7874881</guid><dc:creator>Jared Parsons</dc:creator><description>&lt;p&gt;I'm in favor of keeping the else statements. &amp;nbsp;When the code is originally authored the intent is straight forward. &amp;nbsp;5 years from now the body if the various blocks will grow, someone will insert a block of code that does not unconditionally return and suddenly the rest of your if's will be executing in a condition which wasn't possible when you originally wrote your code. &amp;nbsp;&lt;/p&gt;
</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7877431</link><pubDate>Sun, 24 Feb 2008 16:32:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7877431</guid><dc:creator>mfp</dc:creator><description>&lt;P&gt;Thanks for all the comments. Great to see people are reading my blog.&lt;/P&gt;
&lt;P&gt;I'm also in favor of the one-entry-one-exit. I do not see that as the opposite advice. Actually my advice is a step in this direction instead of strewing the code with return statemens. I advocate ending the method with a return or throw statement - instead of having the return statements nested.&lt;/P&gt;
&lt;P&gt;What I'm advocating against is a return-statement followed by an else-statement.&lt;/P&gt;
&lt;P&gt;The examples I've used are conceived and not real-life - mostly to stress my point. &lt;/P&gt;
&lt;P&gt;Often the constructs I'm advocating against are implementations of parameter validations. Here my point is even more important, as:&lt;/P&gt;
&lt;P&gt;1. The block (containing the return statement) rarely grows over the years.&lt;/P&gt;
&lt;P&gt;2. The following code is much easier to read, if it is not indented off the screen, by nested-if-else-statements. And it is typically this code that is interesting.&lt;/P&gt;
&lt;P&gt;I had a candidate writing this code to me during an interview:&lt;/P&gt;
&lt;P&gt;int factorial(int value)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value &amp;lt; 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw new exception(...)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == 0)&lt;BR&gt;&amp;nbsp;&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;return 1;&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;else&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;if (value == 1)&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;{&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 1;&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;}&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;else&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;{&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int result = 1;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (i=1; i &amp;lt;= value; i++)&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result *= i;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return result;&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;}&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;/P&gt;
&lt;P&gt;I find it hard to see that all paths return a value, and I find that the interesting code (the loop) is buried deep inside some trivial input validations.&lt;/P&gt;
&lt;P&gt;John S: Depending on your language, you want to be carefully on making too many string assignments. &lt;/P&gt;</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7881424</link><pubDate>Sun, 24 Feb 2008 22:03:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7881424</guid><dc:creator>mfp</dc:creator><description>&lt;P&gt;Jaredpar: I put loads of consideration into the argument you are making before writing my blog post. I ended up convencing myself that even 5 years down the road (or after a "decade of decaying" as I like to call it); I think that I'm better off not cluttering the flow of the code by trying to anticipate future changes. &lt;/P&gt;
&lt;P&gt;What convenced me is that if a block (Block A below) no longer unconditionally returns; then Block C will be executed. The code in Block C will in most cases have to be updated to accomodate this change in flow. &lt;/P&gt;
&lt;P&gt;if (/* Something is true */)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Block A&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;&lt;BR&gt;}&lt;BR&gt;else&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Block B&lt;BR&gt;}&lt;BR&gt;//Block C&lt;/P&gt;
&lt;P&gt;I think you are better off collapsing Block B and C - and then update the code as/if needed.&lt;/P&gt;</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7897714</link><pubDate>Tue, 26 Feb 2008 03:55:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7897714</guid><dc:creator>dewetha</dc:creator><description>&lt;P&gt;I agree with your final statement but I believe the focus should be on good code. Using the minimal code and best code are not always the same thing IMO. I see it as good code is easy to read, easy to debug, easy to extend/modify and above all protects the data that is being processed. After all who wants a processing routine that mangles the data and is tough to debug.&lt;/P&gt;
&lt;P&gt;Your first example is simplistic but is not really all that wrong. The following examples, you were correct in saying they are terrible. Your first example allows a simple refactoring of the code on the false side of the equation. But that is splitting hairs on such a simple process.&lt;/P&gt;
&lt;P&gt;All of that, in turn must be balanced against budgets and deadlines. After all, we don't like to work for free :).&lt;/P&gt;
&lt;P&gt;I like the following code(to a degree but that is another discussion) because it is extensible. IMO, anything other than if/ else decision should be a case statement, But I digress. The following structure actually created more code but is easier to debug and subclass IMO. It requires the creation of 2 more methods.&lt;/P&gt;
&lt;P&gt;int foo(int bar) &lt;BR&gt;{&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int retValue;&lt;BR&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(this.Validate(int)); /* throw excpetion for values out of range */&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch( int)&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; case /*expr2*/:&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retValue = 1;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case /*expr3*/ &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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; default:&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retValue &amp;nbsp;= this.HandleOtherInts(int); // this deal with unhandled ints&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; return retValue;&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;The two new methods can throw errors or return a proper value. This would allow me to extend this class, and override the “HanndleOtherInts” method to add new functionality later on with having to worry about breaking any code and retesting the old code at all.&lt;/P&gt;</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7900308</link><pubDate>Tue, 26 Feb 2008 11:07:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7900308</guid><dc:creator>mfp</dc:creator><description>&lt;p&gt;dewetha: Thank you for your comments.&lt;/p&gt;
&lt;p&gt;I fully agree that focus should be on *good* code and not *minimal* code.&lt;/p&gt;
&lt;p&gt;Besides all the traits you list, good code also reduces complexity.&lt;/p&gt;
&lt;p&gt;I believe the superflous else-statements adds complexity.&lt;/p&gt;
</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7904867</link><pubDate>Tue, 26 Feb 2008 17:43:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7904867</guid><dc:creator>Will Sullivan</dc:creator><description>&lt;p&gt;Nesting brackets is a bugaboo of mine. &amp;nbsp;When I see three or four nested brackets I wanna vomit. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I keep the nested brackets to a minimum whenever possible, and live by the rule of thumb that code which must introduce a third nested bracket should be refactored into a supporting method. &amp;nbsp;&lt;/p&gt;
</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#7932237</link><pubDate>Thu, 28 Feb 2008 12:32:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7932237</guid><dc:creator>s3b</dc:creator><description>&lt;P&gt;This is inefficient in terms of CPU usage... The idea that you'd want to do this, particularly in C#, makes me want to cry. I know, I know, C# was introduced to eliminate the need to write in language such as C and ASM (apparently)... but look, in that example foo will NEVER end up being "boo", and think of how it works, just briefly in C:&lt;/P&gt;
&lt;P&gt;// foo = "boo";&lt;/P&gt;
&lt;P&gt;foo = malloc(4);&lt;/P&gt;
&lt;P&gt;*foo = 'b';&lt;/P&gt;
&lt;P&gt;*(foo+1) = 'o';&lt;/P&gt;
&lt;P&gt;*(foo+2) = 'o';&lt;/P&gt;
&lt;P&gt;*(foo+3) = '\0';&lt;/P&gt;
&lt;P&gt;// if (true) {&lt;/P&gt;
&lt;P&gt;if (true) {&lt;/P&gt;
&lt;P&gt;// foo = "bar";&lt;/P&gt;
&lt;P&gt;*foo = 'b';&lt;/P&gt;
&lt;P&gt;*(foo+1) = 'a';&lt;/P&gt;
&lt;P&gt;*(foo+2) = 'r';&lt;/P&gt;
&lt;P&gt;*(foo+3) = '\0';&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;Ignoring the call to the function malloc(), this code will go through at least 7 instructions... then it has another 2, then another 7.&lt;/P&gt;
&lt;P&gt;if (true)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; foo = "bar";&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;else&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; foo = "boo"&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;This code will end up performing 9 instructions at the most. It is almost twice as fast.&lt;/P&gt;
&lt;P&gt;&amp;lt;quote&amp;gt;&lt;/P&gt;
&lt;P&gt;I also like avoiding elses when setting string values. e.g.&lt;/P&gt;
&lt;P&gt;if (true)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; foo = "bar";&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;else&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; foo = "boo"&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;becomes&lt;/P&gt;
&lt;P&gt;foo = "boo";&lt;/P&gt;
&lt;P&gt;if (true)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; foo = "bar";&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;lt;/quote&amp;gt;&lt;/P&gt;</description></item><item><title>re: Writing less code: The "else" statement</title><link>http://blogs.msdn.com/mfp/archive/2008/02/23/writing-less-code-the-else-statement.aspx#8118356</link><pubDate>Sun, 09 Mar 2008 21:21:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8118356</guid><dc:creator>Andrew Hock</dc:creator><description>&lt;p&gt;I would agree with the commenter who stated that the lack of implementation of a single point of return largely negates your example. You're using poor coding practices to explain poor coding proctices.&lt;/p&gt;
&lt;p&gt;I realize you acknowledge this flaw, but I hope you see my point...&lt;/p&gt;
</description></item></channel></rss>