<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9049149725661044069</id><updated>2011-08-01T13:20:47.751-07:00</updated><category term='declaration order'/><category term='2 AM call'/><category term='conditionals'/><category term='documentation'/><category term='bugs'/><category term='death'/><category term='Eddie Izzard'/><category term='Linus Torvalds'/><category term='black box testing'/><category term='goto'/><category term='computers'/><category term='stack overflow'/><category term='cohesion'/><category term='style'/><category term='glass box testing'/><category term='caffeine'/><category term='white box testing'/><category term='stupid mistakes'/><category term='software'/><category term='quality software'/><category term='maintenance'/><category term='ternary operator'/><category term='code'/><category term='readability'/><category term='C-based languages'/><category term='cake'/><category term='software testing'/><category term='method exit'/><category term='Star Trek'/><category term='comments'/><title type='text'>Code or Death</title><subtitle type='html'>Robust software FTW!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://code-or-death.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9049149725661044069/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://code-or-death.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Gene</name><uri>http://www.blogger.com/profile/04152944243952914371</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://4.bp.blogspot.com/_w7AJvLJXRXA/Sp1xrtUO2pI/AAAAAAAAAAc/Z8dDwZdHbl4/S220/6360_112586117913_617002913_2386493_4407578_n.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9049149725661044069.post-827912822903244172</id><published>2009-11-10T12:23:00.000-08:00</published><updated>2009-11-10T12:23:00.033-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='stupid mistakes'/><category scheme='http://www.blogger.com/atom/ns#' term='caffeine'/><category scheme='http://www.blogger.com/atom/ns#' term='stack overflow'/><title type='text'>Stack Overflow ("You CAN teach an old coder stupid tricks!")</title><content type='html'>&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;A quick aside: everyone makes stupid mistakes.&amp;nbsp; I made one today that caused a stack overflow.&amp;nbsp; In retrospect, it was insanely obvious, but when surrounded by 1000 lines of other code and comments, stupid mistakes can be quite good at hiding.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;What happened was I wanted to add a transactional model to a class, so if there's a failure, the existing values can be put back in place through a Rollback call.&amp;nbsp; Great idea, right?&amp;nbsp; I also needed a convenient place to store all the fields, so I ended up with:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;class&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;UrlProfile&lt;/span&gt;&lt;br /&gt;&lt;span style="color: black;"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&amp;nbsp;(Somewhere around 1000 lines of code, white space, and comments)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;private&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;UrlProfile&lt;/span&gt;&lt;span style="color: black;"&gt; ProfileCache = &lt;/span&gt;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;UrlProfile&lt;/span&gt;&lt;span style="color: black;"&gt;();&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Okay then, create a new UrlProfile object.&amp;nbsp; Voila!&amp;nbsp; Stack overflow.&amp;nbsp; (Of course my tests caught this....)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Twelve years in the field.... for shame!&amp;nbsp; I just need more caffeine.&amp;nbsp; Yeah, that's it!&amp;nbsp; :)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Everyone makes stupid mistakes!&amp;nbsp; I'm certainly no exception.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;(The solution, BTW, was to put ProfileCache into a property whose accessor creates a new instance if the underlying field is null.)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9049149725661044069-827912822903244172?l=code-or-death.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-or-death.blogspot.com/feeds/827912822903244172/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-or-death.blogspot.com/2009/11/stack-overflow-you-can-teach-old-coder_10.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9049149725661044069/posts/default/827912822903244172'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9049149725661044069/posts/default/827912822903244172'/><link rel='alternate' type='text/html' href='http://code-or-death.blogspot.com/2009/11/stack-overflow-you-can-teach-old-coder_10.html' title='Stack Overflow (&quot;You CAN teach an old coder stupid tricks!&quot;)'/><author><name>Gene</name><uri>http://www.blogger.com/profile/04152944243952914371</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://4.bp.blogspot.com/_w7AJvLJXRXA/Sp1xrtUO2pI/AAAAAAAAAAc/Z8dDwZdHbl4/S220/6360_112586117913_617002913_2386493_4407578_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9049149725661044069.post-7542859859860105388</id><published>2009-11-03T09:21:00.000-08:00</published><updated>2009-11-03T10:35:07.163-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ternary operator'/><category scheme='http://www.blogger.com/atom/ns#' term='readability'/><category scheme='http://www.blogger.com/atom/ns#' term='documentation'/><category scheme='http://www.blogger.com/atom/ns#' term='maintenance'/><category scheme='http://www.blogger.com/atom/ns#' term='C-based languages'/><category scheme='http://www.blogger.com/atom/ns#' term='method exit'/><category scheme='http://www.blogger.com/atom/ns#' term='goto'/><category scheme='http://www.blogger.com/atom/ns#' term='style'/><category scheme='http://www.blogger.com/atom/ns#' term='cohesion'/><category scheme='http://www.blogger.com/atom/ns#' term='comments'/><category scheme='http://www.blogger.com/atom/ns#' term='Linus Torvalds'/><category scheme='http://www.blogger.com/atom/ns#' term='declaration order'/><category scheme='http://www.blogger.com/atom/ns#' term='2 AM call'/><category scheme='http://www.blogger.com/atom/ns#' term='conditionals'/><title type='text'>Coding Style ("Other coders dis me / say my code is sissy!  Why?")</title><content type='html'>&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Before we get into the fun of actually writing code, I want to talk a bit about coding style.&amp;nbsp; The simple truth is that for every developer out there, there's a different style of writing code.&amp;nbsp; Some elements of this style are inherent in the developer and some are inherent in the language being used by the developer.&amp;nbsp; So, everyone who brings this up will tell you something different and likely argue vehemently that his style is the best style one could employ.&amp;nbsp; Who am I to work against such a time-honored tradition?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;It isn't&amp;nbsp;important for a single style be used by all developers, even within the same language.&amp;nbsp; It is important, however, that the same style be used everywhere throughout a project, even if multiple developers are all contributing different components.&amp;nbsp; Why?&amp;nbsp; Because using a consistent style within a project promotes code readability.&amp;nbsp; High readability eases development, integration, testing, and maintenance of the code.&amp;nbsp;&amp;nbsp;Coding style is therefore an important part of any discussion about&amp;nbsp;writing robust software.&amp;nbsp; So I'm going to talk a little about my style and why it's the best style one could employ!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Although the examples in this blog are written using C#, most of the concepts within are applicable to any language.&amp;nbsp; To be ornery, though, I'm going to start out by talking about style issues&amp;nbsp;largely tied to C-based languages.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family: Arial;"&gt;Conditionals, boolean:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;I always explicitly list the expected value in a boolean comparision.&amp;nbsp; For died-in-the-wool C family&amp;nbsp;developers, this syntax is verbose, reminiscent of BASIC,&amp;nbsp;and, well, kinda wussy (hence the title of this entry).&amp;nbsp; But there are methods to my madness, all intended to bolster readability.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Compare&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt; (ready == &lt;/span&gt;&lt;span style="color: blue;"&gt;true&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: black;"&gt;...&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;And&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt; (ready == &lt;/span&gt;&lt;span style="color: blue;"&gt;false&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;To&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt; (ready)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: black;"&gt;...&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;And&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt; (!ready)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;What's wrong with leaving out &lt;span style="color: blue; font-family: Monospace; font-size: 10pt;"&gt;true&lt;/span&gt; and &lt;span style="color: blue; font-family: Monospace; font-size: 10pt;"&gt;false&lt;/span&gt;?&amp;nbsp; From the compiler's point of view (and that of many developers) absolutely nothing.&amp;nbsp; But, commercial software development is &lt;em&gt;not&lt;/em&gt; a leisurely stroll through the park.&amp;nbsp; When you've been called in at 2 AM because some service has gone offline and goodness knows why, you want the deck stacked in favor of your being able to solve the problem as quickly as possible so you can go back to sleep.&amp;nbsp; If when skimming over the code, you see a &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: x-small;"&gt;!&lt;/span&gt; that isn't there or don't see one that is there, your understanding of the code is exactly the opposite of what it should be.&amp;nbsp; And if that mistake means the computer has been told to do something stupid, you better believe it will happily do just that.&amp;nbsp; So do yourself the favor and type in the extra six or so characters.&amp;nbsp; You'll thank yourself sooner or later!&lt;br /&gt;&lt;br /&gt;For C#, code written this way will always work as expected.&amp;nbsp; But C, C++, JavaScript, etc., have an additional issue.&amp;nbsp; C# will not allow an assignment statement within an &lt;span style="color: blue;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;if&lt;/span&gt; &lt;/span&gt;statement.&amp;nbsp; This is not always the case for the other C-based languages.&amp;nbsp; Leaving out an &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;=&lt;/span&gt; can be as bad if not worse than leaving out a &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;!&lt;/span&gt;.&amp;nbsp; So what can be done?&amp;nbsp; Set&amp;nbsp;your compiler to flag assignments in conditionals as errors.&amp;nbsp; If your compiler cannot be set to do that or if you're (shudder) using an interpreted language, reverse the order of the operands in the &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;if&lt;/span&gt; statement.&amp;nbsp; The statement &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt; (ready = &lt;span style="color: blue;"&gt;false&lt;/span&gt;)&lt;/span&gt; will compile (and always return true), but &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt; (&lt;span style="color: blue;"&gt;false&lt;/span&gt; = ready)&lt;/span&gt; will not.&amp;nbsp; This allows the compiler to do more work so you don't have to!&amp;nbsp; It's a minor hit to readability, but I argue that relying on the tiny and easily missed &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;!&lt;/span&gt; is worse.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conditionals, while loops, etc., and braces:&lt;/strong&gt;&lt;br /&gt;I also always surround conditional blocks and the like in open and close curly braces, even if there's only one line of code within them.&amp;nbsp; In all C-based languages, the following structure is legal:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt; (ready == &lt;/span&gt;&lt;span style="color: blue;"&gt;true&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;Console&lt;/span&gt;&lt;span style="color: black;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color: #a31515;"&gt;"Ready"&lt;/span&gt;&lt;span style="color: black;"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Now, imagine I also need to flip a flag if ready is true.&amp;nbsp; I'm in a hurry so I forget that I need to add curly braces because I now have two statements in my conditional block.&amp;nbsp; Worse, my evil editor does automatic indentation.&amp;nbsp; So, I end up with:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt; (ready == &lt;/span&gt;&lt;span style="color: blue;"&gt;true&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;Console&lt;/span&gt;&lt;span style="color: black;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color: #a31515;"&gt;"Ready"&lt;/span&gt;&lt;span style="color: black;"&gt;);&lt;br /&gt;waiting = &lt;span style="color: blue;"&gt;false&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Hey, we're doing some kind of resource sharing or thread synchronization thing, aren't we?&amp;nbsp; Only now we just signaled that a thread is done using some resource when it isn't.&amp;nbsp; Poof!-- if you're lucky.&amp;nbsp; Otherwise the code may just behave... oddly... and require extensive debugging.&amp;nbsp; The error may not be immediately obvious either, because our helpful little (evil) editor removed the indent that might have tipped us off.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;The solution?&amp;nbsp; Always use curly braces with conditional blocks and the like.&amp;nbsp; Always.&amp;nbsp; That way you'll never forget them.&amp;nbsp; In fact, the moment I put the closing paren on the &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;if&lt;/span&gt; statement, I add &lt;em&gt;both&lt;/em&gt; the open and the closing curly brace before adding anything to the block.&amp;nbsp;&amp;nbsp;That also prevents me from including anything I didn't mean to include within the&amp;nbsp;conditional block (the opposite of the problem above).&amp;nbsp; Using curly braces every time produces more readable code, too, because it's more orthogonal to always use something than to only use it sometimes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family: Arial;"&gt;Conditionals, ternary operator:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;This thing is just plain evil.&amp;nbsp; Never use it.&amp;nbsp; It's the only thing I always reject out of hand during code reviews.&amp;nbsp; The problem with it is that it's just plain unreadable.&amp;nbsp; Consider:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;int&lt;/span&gt;&lt;span style="color: black;"&gt; numWaiting = (ready == &lt;/span&gt;&lt;span style="color: blue;"&gt;true&lt;/span&gt;&lt;span style="color: black;"&gt;) ? 0 : 1;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;This statement is so dense reading it&amp;nbsp;is like looking for a full stop in a Charles Dickens novel.&amp;nbsp; The code below is immeasurably more readable:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;int&lt;/span&gt;&lt;span style="color: black;"&gt; numWaiting;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt; (ready == &lt;/span&gt;&lt;span style="color: blue;"&gt;true&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;numWaiting = 0;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue;"&gt;else&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;numWaiting = 1;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;And this is (at worst only&amp;nbsp;almost) the exact same thing from the compiler / runtime point of view, but a human can actually read it.&amp;nbsp; And if there is a runtime difference here, we're talking nanoseconds.&amp;nbsp; What are you doing using managed code if time of that scale matters to you?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;All that being said, I absolutely love the C family &lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;for&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; statement, despite its density, which one could argue is comparable to that of the ternary operator.&amp;nbsp; The semi-colons separate the loop constructs cleanly and obviously, and I maintain it helps bolster readability to have all loop control elements on one line instead of (potentially) dozens of lines apart.&amp;nbsp; It also helps guard against forgetting to add your loop counter increment statement, an oversight that usually results in an infinite loop.&amp;nbsp; So remember, ternary operator = evil, &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;for&lt;/span&gt; statement = good.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family: Arial;"&gt;Comments:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;I would say that mentioning code commenting standards in a room full of developers is like banging a cymbal near the summit of a mountain, except being buried by an avalanche of snow and ice is probably less painful.&amp;nbsp; While there are many contentious style debates, the extent to which comments should be added to code can become one of the most heated.&amp;nbsp; Some developers feel that lack of comments renders code useless, whereas others feel that code should be &lt;em&gt;self-commenting&lt;/em&gt;, that it should be written in such a way that the code itself conveys its intentions to the reader.&amp;nbsp; Sara J. Chipps, AKA Girl Developer, is one proponent of the latter approach.&amp;nbsp; In her blog, she writes a scathing op/ed piece on the evils of comments called &lt;a href="http://girldeveloper.com/waxing-dev/documentation-a-sure-sign-of-garbage-code/"&gt;Documentation: A Sure Sign of Garbage Code&lt;/a&gt;.&amp;nbsp; (And I thought I had strong opinions!)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;The thing is, I absolutely agree with most of her sentiments.&amp;nbsp; You really should write your code in such a way that someone could read it and understand what it does without needing to read extensive natural language documentation.&amp;nbsp; You should make your code as readable as possible for all the reasons listed in the sections above.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;And then you should comment it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Why?&amp;nbsp; Because when you work on projects with other people (and it is safe to assume that you will sooner or later) you never know what skill level they may possess.&amp;nbsp; Sara says "[I]f your programmer&amp;nbsp;needs documentation in order to be able to quickly pick up on what&amp;nbsp;[your code]&amp;nbsp;is doing one of two things are true: either the programmer sucks or, more likely, your code sucks."&amp;nbsp;&amp;nbsp;If you take care of business as described throughout this blog, you ought to be able to rule out the possibility that your code sucks.&amp;nbsp; The problem is that oftentimes the other programmer &lt;em&gt;does&lt;/em&gt; suck.&amp;nbsp; Or, to put it more politely, the other developer may not have the mad skills you posses, but (s)he may still be the one who has to make modifications to your code down the road.&amp;nbsp; Do you really want to get called in every time someone with a lesser skill set than you have needs to work with your old code?&amp;nbsp; Especially at 2 AM?&amp;nbsp; If not, then it's in your best interests to arm the other developer with all the information you can to stack the deck in favor of you never receiving that call.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Another reason to add comments lies in the ability to easily convey interfaces to other developers who intend to leverage your code.&amp;nbsp; The beauty of XML comments within C# is that anyone can use these to build an MSDN-like knowledge repository for how to leverage their libraries and services.&amp;nbsp; If you comment your code appropriately, this becomes something you can provide people for free-- no extra effort on your part to write separate documentation.&amp;nbsp; Otherwise, you either have to take the plunge and write separate documentation or get interrupted every time someone else has a question regarding your code.&amp;nbsp; And, as you should know, there's a lot of overhead in servicing interrupts.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;So, then, in my humble opinion, what kind of commenting is needed?&amp;nbsp; It varies from project to project, but in general, I do the following:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-family: Arial;"&gt;File header:&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;A file header tells people when they open your file what they can find in that file.&amp;nbsp; If they read the header (and, yes, there's always the possibility no one will bother to read the comments) they should know whether the file might contain what they are looking for.&amp;nbsp; This can be extremely helpful when your project is of sufficient scope that it contains hundreds of files.&amp;nbsp; An example file header:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: green;"&gt;//************************************************************************************************************************************&lt;br /&gt;// System: XML Communication Sample&lt;br /&gt;// Subsystem: Web Services&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;//&lt;br /&gt;// File: XmlImporter.cs&lt;br /&gt;// Purpose: Contains the XmlImporter class which is used to import XML blobs into the store.&lt;br /&gt;// &lt;br /&gt;// Copyright (C) 2009 Gene DeClark. All rights reserved.&lt;br /&gt;//************************************************************************************************************************************&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;The copyright notice is important if you want to protect your work.&amp;nbsp; Note that&amp;nbsp;if you are writing this code for pay, this notice should typically contain your employer's name instead of your own.&amp;nbsp; If you happen to be copyrighting your code via a certain kind of license, such as the GNU Public License, you should note that here.&amp;nbsp; If you (and your employer) don't care if others directly leverage your source code, though, you don't need to include a copyright notice.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Note that the above is not XML and is not included when XML comments are built into documentation files by Visual Studio.&amp;nbsp; That's because from an interface point of view, source files are irrelevant.&amp;nbsp; But someone actually looking at your project will benefit from you including these file&amp;nbsp;headers.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Finally, the "borders" can certainly be omitted if you prefer. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;&lt;em&gt;Class headers:&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;A class header tells people the role your class plays within the overarching product.&amp;nbsp; Because class headers are included within XML comments, they're automatically built into documentation files by Visual Studio.&amp;nbsp; Further, when the Visual Studio IDE is used, context-sensitive tooltips will show these comments to code readers and writers when appropriate.&amp;nbsp; So your documentation effort pays off even if no one sets out to read the docs.&amp;nbsp; Very cool!&amp;nbsp; An example class header:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Provides functionality to import XML blobs into the store, including schema verification via XSD, creation of new blob&lt;/span&gt;&lt;br /&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; entries, and existing blob updates.&lt;/span&gt;&lt;span style="color: green;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;class&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;XmlImporter&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;em&gt;Method, property, etc. headers:&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;XML comments can also be used to create headers for methods, properties, and the like.&amp;nbsp; Of all headers, these are the most important, because they tell other people how to make calls into your code.&amp;nbsp; Leaving these comments out is a good way to ensure questions get sent to your inbox (or your cell phone) at the worst imaginable times.&amp;nbsp; The XML comment schema for these elements is fairly rich, so you should spend some time researching the possibilities.&amp;nbsp; An example method header:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Deserializes the specified data into a new XmlImporter.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;param name="serializedData"&amp;gt;&lt;/span&gt;&lt;span style="color: green;"&gt;Serialized data to deserialize into a new XmlImporter.&lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green;"&gt;XmlImporter populated with deserialized data if successful. Else returns null.&lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;exception cref="NullReferenceException"&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Parameter serializedData is null.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;exception cref="ArgumentNullException"&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; The OuterXml property of parameter serializedData is null.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;exception cref="InvalidOperationException"&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Deserialization failed. The InnerException property contains further information on the failure.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/exception&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;static&lt;/span&gt;&lt;span style="color: black;"&gt; XmlImporter Deserialize(&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;XmlElement&lt;/span&gt;&lt;span style="color: black;"&gt; serializedData)&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Note the list of&amp;nbsp;Exceptions.... We'll talk about those and the role of method preconditions (which can be included in the &lt;span style="color: grey; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;&amp;lt;remarks&amp;gt;&lt;/span&gt; element) in more detail in a later entry.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;&lt;em&gt;Inline comments:&lt;br /&gt;&lt;/em&gt;So now that we know what each&amp;nbsp;file does, what each class does, and what each method, property, etc., does, what else do we need?&amp;nbsp; Well, we need to understand what the code inside the method does.&amp;nbsp; If you follow all the other advice in this entry, you may be able to add comments inline within your code very sparingly and be just fine.&amp;nbsp; I still elect to add comments rather liberally so that people unfamiliar with the code can jump in unaided (assuming they understand the language I write the comments in, which also, granted, may not be true).&amp;nbsp; So, when do I add an inline comment?&amp;nbsp; Generally, before any loop or branch and before a section of code that performs a portion of a larger job.&amp;nbsp; For example, assuming serialization code was short enough, I might serialize an entire object within a single method.&amp;nbsp; Since each property is a discrete portion of a larger job, I might include a comment above each property's corresponding lines of code.&amp;nbsp; Or I might not.&amp;nbsp; Whether I do or not depends upon whether I think that &lt;em&gt;anyone&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt; &lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;I work with or may work with in the future might be confused if I don't add the comment.&amp;nbsp; So in general, I add the comment.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;&lt;strong&gt;Declaration order:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Once upon a time, back when C was king, elements had to be declared in a certain order.&amp;nbsp; Variables had to come before functions, functions that were called by other functions had to be declared first, and so on.&amp;nbsp; The problem was that all the minutiae always came first within a file.&amp;nbsp; The really important code was always further down.&amp;nbsp; This approach also could cause problems in other scenarios, such as mutual recursion.&amp;nbsp; Along came C++ and the concept of classes.&amp;nbsp; Within C++, the class declaration and implementation were in separate files.&amp;nbsp; So, the order of declaration still mattered, but at least the minutiae was out of the way.&amp;nbsp; When C# came out, however, separate declaration and implementation files went the way of the dinosaur, and all the minutiae once again ended up at the top of the class, above the really important code.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;The thing is that order of declaration doesn't matter in C#.&amp;nbsp; So long as a reference can be resolved at build time, declarations can come in any order.&amp;nbsp; So it makes no sense to include all the minutiae at the top of a class.&amp;nbsp; Instead, I always organize my code so that the most important elements appear at the top.&amp;nbsp; This usually means that construction and destruction come first, followed by public properties, then public methods, followed by interface implementations, then&amp;nbsp;protected and / or private methods, followed by protected and / or private properties and fields, and finally constants.&amp;nbsp; Everything is easy to find thanks to Intellisense, anyway, but with this arrangement, the code someone most wants to see when they open the file is usually right on top.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;As an aside, it is possible as of .NET Framework 2.0 to split elements of classes between files through the use of&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;partial&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; classes.&amp;nbsp; If you see people doing this, they're probably died-in-the-wool &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;C++ programmers!&amp;nbsp; You can indeed separate some elements of a class into separate files, and there are times when this may be a good choice.&amp;nbsp; But, generally, placing class minutiae into a &lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;#region&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; declaration will sweep it under the rug sufficiently that the overhead of maintaining a separate file isn't really justifiable.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Method entry and exit:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;A method, in general, can only be entered at its beginning.&amp;nbsp; It can have any number of exit points, however.&amp;nbsp; This is the potential source of much gnashing of teeth in the world of unmanaged code, but don't be fooled into thinking managed code solves this problem.&amp;nbsp; That way leads to suffering even for C# programmers.&amp;nbsp; Consider:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; font-family: Monospace; font-size: 10pt;"&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Used to specify the result of an attempted cache update.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;enum&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;CacheUpdateResultCode&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Indicates the cache update operation succeeded.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Success,&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Indicates the cache update operation failed because the specified file could not be found.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Error_FileNotFound,&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Indicates the cache update operation failed because the specified cache key could not be found.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Error_CacheKeyNotFound&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Cached file contents.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;static&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;Dictionary&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&lt;span style="color: black;"&gt;, &lt;/span&gt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;gt; FileCache = &lt;/span&gt;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;Dictionary&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&lt;span style="color: black;"&gt;, &lt;/span&gt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; Updates the cached copy of the specified text file.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: grey;"&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;param name="filePath"&amp;gt;&lt;/span&gt;&lt;span style="color: green;"&gt;Path and name of file whose contents to update in the cache.&lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;param name="key"&amp;gt;&lt;/span&gt;&lt;span style="color: green;"&gt;Key of file to update in the cache.&lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="color: green;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green;"&gt;Result code of the cache update operation.&lt;/span&gt;&lt;span style="color: grey;"&gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;static&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;CacheUpdateResultCode&lt;/span&gt;&lt;span style="color: black;"&gt; UpdateFileCache(&lt;/span&gt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&lt;span style="color: black;"&gt; filePath,&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;&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;&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;/span&gt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&lt;span style="color: black;"&gt; key)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: green;"&gt;// Make sure the file exists.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt; (&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;File&lt;/span&gt;&lt;span style="color: black;"&gt;.Exists(filePath) == &lt;/span&gt;&lt;span style="color: blue;"&gt;true&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;br /&gt;&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;&lt;/span&gt;&lt;span style="color: green;"&gt;// Open the file and read in its contents.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;TextReader&lt;/span&gt;&lt;span style="color: black;"&gt; textReader = &lt;/span&gt;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;StreamReader&lt;/span&gt;&lt;span style="color: black;"&gt;(filePath);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&lt;span style="color: black;"&gt; contents = textReader.ReadToEnd();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: green;"&gt;// Update cached version of file.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt; (FileCache.Keys.Contains(key) == &lt;/span&gt;&lt;span style="color: blue;"&gt;true&lt;/span&gt;&lt;span style="color: black;"&gt;)&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;&amp;nbsp;FileCache[key] = contents;&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;&lt;/span&gt;&lt;span style="color: blue;"&gt;else&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&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;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;return&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;CacheUpdateResultCode&lt;/span&gt;&lt;span style="color: black;"&gt;.Error_CacheKeyNotFound;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: green;"&gt;// Free resources.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;textReader.Close();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;textReader.Dispose();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;textReader = &lt;/span&gt;&lt;span style="color: blue;"&gt;null&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;return&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;CacheUpdateResultCode&lt;/span&gt;&lt;span style="color: black;"&gt;.Success;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;else&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&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;&lt;/span&gt;&lt;span style="color: green;"&gt;// The file did not exist, so return false.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;return&lt;/span&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;CacheUpdateResultCode&lt;/span&gt;&lt;span style="color: black;"&gt;.Error_FileNotFound;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Look how responsible we're being!&amp;nbsp; We're checking if the file exists (which also indirectly checks to see if the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;filePath&lt;/span&gt; parameter argument is null or empty), w&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;e're cleaning up the resource, heck we're even setting &lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;textReader&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt; to &lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;null&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; when we're done.&amp;nbsp; And we commented the HECK out of the thing.&amp;nbsp; So what's wrong?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Several things, really, many of which I will talk about in the entry on exception handling.&amp;nbsp;&amp;nbsp;The one I want to focus on right now, though,&amp;nbsp;is that this code includes three return statements.&amp;nbsp; On the surface, this doesn't appear to cause any harm.&amp;nbsp; But, if the file is read successfully but the key is not already in the Dictionary, the method exits without cleaning up the file resource.&amp;nbsp; If this code path is executed frequently, congratulations, you've got a bad&amp;nbsp;memory leak.&amp;nbsp; This happens because files are unmanaged resources accessed through managed classes.&amp;nbsp; If you don't call &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;Dispose&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;, the unmanaged resources aren't freed.&amp;nbsp; One way to help ensure &lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;Dispose&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt; is always called is to make sure a method only ever has one exit point.&amp;nbsp; This, combined with exception handling and the &lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;using&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; pattern, both of which we'll talk about in a later entry, will ensure &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;Dispose&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt; is always called (barring power outages and the like!).&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Cohesion:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Files, classes, methods, in essence all elements of a program should be highly cohesive.&amp;nbsp; They should perform a single task, model a single entity, and so on.&amp;nbsp; And they should be as short as they can be.&amp;nbsp; Specifically:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family: Arial;"&gt;A file should, in general, contain only one class, interface, etc..&lt;/span&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family: Arial;"&gt;You will see me break this rule on occasion.&amp;nbsp; (Naughty, naughty!)&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;span style="font-family: Arial;"&gt;A class should represent a single entity, its state, and the actions that entity can take.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: Arial;"&gt;Methods should perform one small function and nothing more.&lt;/span&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family: Arial;"&gt;As a corollary, methods should be limited in length.&amp;nbsp; If you're approaching 100 lines of code&amp;nbsp;(including comments and whitespace!) or if you have so many loops and conditionals your lines are starting halfway across the screen, you should strongly consider refactoring your method into smaller functional units.&amp;nbsp; Don't be afraid of private helper methods.&amp;nbsp; And don't even &lt;em&gt;talk&lt;/em&gt; to me about function call overhead-- this is managed code for ELIZA's sake!&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family: Arial;"&gt;GOTO:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Remember how I said earlier that the ternary operator is the only thing I ever reject out of hand in a code review?&amp;nbsp; That's because no one's ever had the audacity to hand me code with a &lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;goto&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; in it.&amp;nbsp; (Please understand that I'm not including within this discussion languages that don't include control structures other than &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;goto&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt;-like&lt;/span&gt;&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; statements such as assembly and line number BASIC.&amp;nbsp; We should all feel dirty for ever having used line number BASIC, anyway!)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;In my personal opinion, if Dante's &lt;strong&gt;Inferno&lt;/strong&gt; had included a tenth circle of hell, its sole occupant would be the &lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;goto&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; statement.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt;Using &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;goto&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt;s is the fastest, surest way of producing unreadable, unmaintainable, incomprehensible code.&amp;nbsp; But don't take my word for it.&amp;nbsp; Read, for example, Edsger Dijkstra's letter &lt;a href="http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF"&gt;A case against the GO TO statement&lt;/a&gt;&amp;nbsp;written over 40 years ago!&amp;nbsp; Beyond this, though, even further back in history it was &lt;a href="http://en.wikipedia.org/wiki/Structured_program_theorem"&gt;proven&lt;/a&gt; that languages that can model structured programming (which all C-based languages can do, even the venerable C) have absolutely no need of &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;goto&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt;s.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;So, if this debate was settled over 40 years ago, why am I bringing it up?&amp;nbsp; Because it wasn't settled.&amp;nbsp; Some important people in the industry still hold that use of &lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;goto&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt;s, in at least some cases, is better than use of structured programming.&amp;nbsp; One such proponent is &lt;a href="http://kerneltrap.org/node/553/2131"&gt;Linus Torvalds&lt;/a&gt;, who is best known for having started a little project known as Linux.&amp;nbsp; If you follow the link above and read the argument, he is at least partly basing the defense of &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;goto&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt;s on the fact that some languages such as Pascal don't have a &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;break&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; statement.&amp;nbsp; It's true that when I was coding in Pascal some 20 years ago, the lack of a &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;break&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; statement did create an occasional lack of elegance.&amp;nbsp; But this isn't 20 years ago.&amp;nbsp; And we're not using Pascal.&amp;nbsp; And all C-based languages &lt;em&gt;do &lt;/em&gt;have a &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;break&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; statement.&amp;nbsp; So I don't think it's a very strong argument.&amp;nbsp; Still, more people know Linus's name than mine, so I really have to present that side of the argument as well.&amp;nbsp; I would encourage you to do your own research and decide for yourself.&amp;nbsp; Just don't ask me to review your code if you use &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;goto&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt;s.&amp;nbsp; My constitution is too delicate for such rot.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family: Arial;"&gt;Conclusion:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Wow, this is a long entry!&amp;nbsp; You should know that I've spent a long, long time developing a style.&amp;nbsp; Your style will undoubtedly differ from mine.&amp;nbsp; So long as you have defensible reasons for why you use a particular style, have at ye!&amp;nbsp; And be prepared to evolve your style over time and to be surprised by some style standards you learn about.&amp;nbsp; Just the other day, for example, I learned that it's considered preferable to have &lt;/span&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;using&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; statements &lt;em&gt;inside &lt;/em&gt;the &lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;"&gt;namespace&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; block.&amp;nbsp; I'd never seen this before and hadn't considered it.&amp;nbsp; But, I can't think of any reason not to do so, and doing so just plain &lt;em&gt;feels&lt;/em&gt; like an improvement.&amp;nbsp; So guess what I'm doing with my &lt;span style="color: blue; font-family: Courier New;"&gt;using&lt;span style="color: black; font-family: Arial, Helvetica, sans-serif;"&gt; statements now?&amp;nbsp; My carefully developed style got slapped upside the head and I adapted.&amp;nbsp; You'll need to do so, too, so don't be surprised when it happens!&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9049149725661044069-7542859859860105388?l=code-or-death.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-or-death.blogspot.com/feeds/7542859859860105388/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-or-death.blogspot.com/2009/11/coding-style-other-coders-dis-me-say-my.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9049149725661044069/posts/default/7542859859860105388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9049149725661044069/posts/default/7542859859860105388'/><link rel='alternate' type='text/html' href='http://code-or-death.blogspot.com/2009/11/coding-style-other-coders-dis-me-say-my.html' title='Coding Style (&quot;Other coders dis me / say my code is sissy!  Why?&quot;)'/><author><name>Gene</name><uri>http://www.blogger.com/profile/04152944243952914371</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://4.bp.blogspot.com/_w7AJvLJXRXA/Sp1xrtUO2pI/AAAAAAAAAAc/Z8dDwZdHbl4/S220/6360_112586117913_617002913_2386493_4407578_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9049149725661044069.post-4487401062884008095</id><published>2009-10-02T14:27:00.000-07:00</published><updated>2009-11-03T10:34:37.692-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bugs'/><category scheme='http://www.blogger.com/atom/ns#' term='black box testing'/><category scheme='http://www.blogger.com/atom/ns#' term='quality software'/><category scheme='http://www.blogger.com/atom/ns#' term='software testing'/><category scheme='http://www.blogger.com/atom/ns#' term='white box testing'/><category scheme='http://www.blogger.com/atom/ns#' term='glass box testing'/><title type='text'>Robust coding ("Welcome! You've got bugs!")</title><content type='html'>&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;"Raise your hand if you love &lt;strong&gt;coding&lt;/strong&gt;!"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Lots of hands, waving enthusiastically.&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;"Raise your hand if you love &lt;strong&gt;debugging&lt;/strong&gt;!"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Fewer hands, a little less glee.&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;"Raise your hand if you love &lt;strong&gt;testing&lt;/strong&gt;!"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A few, limp-wristed hands.&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;"Raise your hand if you love &lt;strong&gt;regression testing&lt;/strong&gt;!"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Crickets chirping, quiet coughs.&amp;nbsp; Some guy in the back&amp;nbsp;gnawing&amp;nbsp;his hand off at the wrist.&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;I by no means stand alone&amp;nbsp;in my passion for&amp;nbsp;the production of high quality software.&amp;nbsp; I&amp;nbsp;also by no means stand alone in finding&amp;nbsp;large portions of software testing, well, &lt;em&gt;boring&lt;/em&gt; and &lt;em&gt;tedious&lt;/em&gt;.&amp;nbsp; For six long years, I worked full time as a software tester.&amp;nbsp; I spent most of that time wishing I were writing the code instead of testing it.&amp;nbsp; In my experiences within the industry, until recently there were &lt;em&gt;testers&lt;/em&gt; and there were &lt;em&gt;devs&lt;/em&gt;, and seldom was one successful in moving from one of these camps to the other.&amp;nbsp; The industry as a whole, however, is changing, and even large companies are moving away from placing rigid walls between development and testing efforts.&amp;nbsp; It's finally becoming accepted that to write good code, you&lt;em&gt;&amp;nbsp;must&lt;/em&gt; understand how to test it and execute on that need.&amp;nbsp; It's also finally becoming accepted that to thoroughly test code, you &lt;em&gt;must&lt;/em&gt; understand the code you're testing.&amp;nbsp; This is certainly not what I encountered when I entered the industry twelve years ago.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;"But I thought this blog was going to be about &lt;em&gt;coding&lt;/em&gt;!" someone mutters.&amp;nbsp; "What's all this rot about testing?"&amp;nbsp; It's a fair question.&amp;nbsp; Software testing is a complex and deep discipline, and huge swaths of it don't involve writing a single line of code.&amp;nbsp; I have to stand by my earlier assertion that you can't write quality code without understanding testing, though.&amp;nbsp; What is a blogger to do?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Define&amp;nbsp;terms, of course!&amp;nbsp; Within this blog, we're going to concentrate primarily on &lt;em&gt;white&lt;/em&gt; box (which sometimes goes by my perferred term &lt;em&gt;glass&lt;/em&gt; box) testing and relegate discussions of &lt;em&gt;black&lt;/em&gt; box testing to the background.&amp;nbsp; Consequently, we're going to look at methods for driving the code we write with &lt;em&gt;yet more code.&lt;/em&gt;&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; To do this, we must be able to see, understand, and access our &lt;em&gt;production&lt;/em&gt; code with our &lt;em&gt;test&lt;/em&gt; code, hence the glassiness of our box of interest.&amp;nbsp; The contrasting black box approach is driven around the idea of exercising production code with no understanding of its implementation whatsoever.&amp;nbsp; Someone new to development might wonder which is the superior approach.&amp;nbsp; The answer is that neither is better or worse, and both are essential.&amp;nbsp; Each complements the other, providing knowledge about&amp;nbsp;the code we're writing the other can't provide.&amp;nbsp; In this blog, we're going to talk mostly about glass box testing, but I want to be clear that this focus is by no means meant to diminish the importance of the alternate side of the testing coin.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;In the next few posts, we're going to write a small application that will import and export XML from a web service, using C# and the .NET Framework, version 3.5.&amp;nbsp; So, we'll be using managed code and concentrating in part on the problems solved and the problems created through its use.&amp;nbsp; More importantly, we'll write robust code, and we'll have a much improved understanding of the code's quality because of the test code we'll write as we go.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;One day, producing quality code may be as simple as loading a web page and waiting to hear "Welcome!&amp;nbsp; You've got bugs!"&amp;nbsp; But it is not this day.&amp;nbsp; This day we FIGHT!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9049149725661044069-4487401062884008095?l=code-or-death.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-or-death.blogspot.com/feeds/4487401062884008095/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-or-death.blogspot.com/2009/11/robust-coding-welcome-youve-got-bugs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9049149725661044069/posts/default/4487401062884008095'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9049149725661044069/posts/default/4487401062884008095'/><link rel='alternate' type='text/html' href='http://code-or-death.blogspot.com/2009/11/robust-coding-welcome-youve-got-bugs.html' title='Robust coding (&quot;Welcome! You&apos;ve got bugs!&quot;)'/><author><name>Gene</name><uri>http://www.blogger.com/profile/04152944243952914371</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://4.bp.blogspot.com/_w7AJvLJXRXA/Sp1xrtUO2pI/AAAAAAAAAAc/Z8dDwZdHbl4/S220/6360_112586117913_617002913_2386493_4407578_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9049149725661044069.post-8587158418692034690</id><published>2009-09-01T12:07:00.000-07:00</published><updated>2009-11-03T10:35:39.153-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='computers'/><category scheme='http://www.blogger.com/atom/ns#' term='Eddie Izzard'/><category scheme='http://www.blogger.com/atom/ns#' term='death'/><category scheme='http://www.blogger.com/atom/ns#' term='software'/><category scheme='http://www.blogger.com/atom/ns#' term='code'/><category scheme='http://www.blogger.com/atom/ns#' term='cake'/><category scheme='http://www.blogger.com/atom/ns#' term='Star Trek'/><title type='text'>"You: code or death?"</title><content type='html'>&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;I was doomed to geekdom at a very young age.&amp;nbsp; One of my earliest memories is watching Star Trek with my dad, every Sunday at 4:30 on Channel 12.&amp;nbsp; More so even than the&amp;nbsp;sometimes positively educational&amp;nbsp;costumes and weird aliens, the library computer absolutely fascinated me.&amp;nbsp; Here was a marvel: a machine that would answer your questions, drawing on a repository of facts beyond those accessible to any one person anywhere.&amp;nbsp; Being, as I was, a toddler with "why" and "how" on my mind more than anything else, this &lt;em&gt;computer&lt;/em&gt; thing seemed a godsend.&amp;nbsp; But even at that young an age, I knew what the word "fiction" meant, and I'd certainly never seen anything like that anywhere in the real world.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: inherit;"&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Fast forward to 1985,&amp;nbsp;when I was in the fifth grade.&amp;nbsp; After yet another lesson in square roots, decimals, rounding, or some other mundane thing like that, my teacher wheeled&amp;nbsp;a cart into the classroom.&amp;nbsp;&amp;nbsp;On this cart was a real-life, honest to God, working, living, breathing (okay I made those last two up),&lt;em&gt; freakin' computer&lt;/em&gt;!&amp;nbsp; I couldn't even hear the choir of angels singing in the background over the blood rushing through my veins at the sight of the thing.&amp;nbsp; A Commodore PET.&amp;nbsp; With integrated cassette storage.&amp;nbsp; And I got to ask it questions.&amp;nbsp; I will never forget that moment.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;Okay, sure, this wasn't the Enterprise, and the Commodore PET sure wasn't a library computer.&amp;nbsp; Even by today's standards it was really just a toy.&amp;nbsp; In truth, its software was so limited you couldn't ask it for much information, really.&amp;nbsp; It taught me the state capitals and the countries in Latin America.&amp;nbsp; I soon learned, though, that not only could the computer answer my questions, but I could &lt;em&gt;tell it what to do &lt;/em&gt;and &lt;em&gt;it would do it&lt;/em&gt;!&amp;nbsp; That machine sparked a lifelong passion within me.&amp;nbsp; I now tell machines what to do for a living, and I learn more from them every day than I ever really thought would be possible.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;This blog isn't about my story, really.&amp;nbsp; I'll write more about that over time, sure, but what I really want to write about is code.&amp;nbsp; Being able to tell computers what to do is, well, neat!&amp;nbsp; But the problem is that they'll do &lt;em&gt;exactly&lt;/em&gt;&amp;nbsp;what you tell them to do, even spectacularly stupid things.&amp;nbsp; This complete obedience, while damn cool, comes at a price.&amp;nbsp; The role computers play in people's lives is growing in magnitude at a startling rate.&amp;nbsp; When computers do exactly what we tell them and we tell them to do something stupid, it's now disrupting&amp;nbsp;people's lives.&amp;nbsp; Depending on&amp;nbsp;what the software does, it may even cost people their lives.&amp;nbsp; It is critical for the software industry to&amp;nbsp;begin to ask (and answer) fundamental questions about how we can&amp;nbsp;be sure what we're asking these machines to do is what we actually intend them to do.&amp;nbsp; Questions like&amp;nbsp;"what separates 'good' code from 'bad' code?" are a start.&amp;nbsp;&amp;nbsp;"What should we be looking at to&amp;nbsp;figure out what our code is actually doing?" may be a better question.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;What this all comes down to is a combination of technologies and best practices, both of which are changing every day and will continue to change at a profound rate.&amp;nbsp; Remember that&amp;nbsp;humans have only been developing computer software for about 65 years.&amp;nbsp; How good were we, really, as a species at building bridges 65 years after the first ever bridge was&amp;nbsp;built?&amp;nbsp;&amp;nbsp;Would you drive your car across that bridge?&amp;nbsp; I sure as heck wouldn't.&amp;nbsp; While the methods of sharing information and therefore pushing the state of the technology forward are unquestionably more advanced today than they were back when bridges were still a pretty neat idea, this still means that &lt;em&gt;no one really knows&amp;nbsp;&lt;/em&gt;how to write software you could drive a car over.&amp;nbsp; I sure as heck don't.&amp;nbsp; But I endeavor to improve the quality of the code I write relative to the quality of code I've written in the past every time I sit at the keyboard.&amp;nbsp; I've learned some useful stuff over the years that I can share.&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: Arial;"&gt;Many people will disagree with much of what I write in this blog.&amp;nbsp; I wouldn't have it any other way.&amp;nbsp; Only by questioning what we're doing can we get better at it.&amp;nbsp; I hope this blog is helpful in that process.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;If you've read this far, you deserve the answer to a question: What the heck is up with the title of this blog?&amp;nbsp; Eddie Izzard, a British, cross-dressing standup comedian, once did a routine in which inquisitors went around asking their victims if they wanted cake... or death.&amp;nbsp; Surprisingly, everyone wanted cake, and they ran out.&amp;nbsp; So their remaining victims were given the option&amp;nbsp;"or death."&amp;nbsp; Don't worry-- there's still plenty of code to go around. :)&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9049149725661044069-8587158418692034690?l=code-or-death.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-or-death.blogspot.com/feeds/8587158418692034690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-or-death.blogspot.com/2009/09/you-code-or-death.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9049149725661044069/posts/default/8587158418692034690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9049149725661044069/posts/default/8587158418692034690'/><link rel='alternate' type='text/html' href='http://code-or-death.blogspot.com/2009/09/you-code-or-death.html' title='&quot;You: code or death?&quot;'/><author><name>Gene</name><uri>http://www.blogger.com/profile/04152944243952914371</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://4.bp.blogspot.com/_w7AJvLJXRXA/Sp1xrtUO2pI/AAAAAAAAAAc/Z8dDwZdHbl4/S220/6360_112586117913_617002913_2386493_4407578_n.jpg'/></author><thr:total>0</thr:total></entry></feed>
