<?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>Fabulous Adventures In Coding : Aargh!</title><link>http://blogs.msdn.com/ericlippert/archive/tags/Aargh_2100_/default.aspx</link><description>Tags: Aargh!</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Aargh! Part Eight, plus Boring Metablogging</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/23/aargh-part-eight-plus-boring-metablogging.aspx</link><pubDate>Fri, 23 Jul 2004 21:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:193305</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/193305.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=193305</wfw:commentRss><description>&lt;DIV class=mine&gt;
&lt;P&gt;Q: What's a pirate's &lt;STRONG&gt;second favourite&lt;/STRONG&gt; mode of transportation?&lt;/P&gt;
&lt;P&gt;A: A caaaaargh! Preferably a Jaguaaaaargh, but&amp;nbsp;an early Oldsmobile Cutlass will do.&lt;/P&gt;
&lt;P&gt;Q: Very amusing --&amp;nbsp;but what's a pirate's &lt;STRONG&gt;favourite&lt;/STRONG&gt; mode of transportation?&lt;/P&gt;
&lt;P&gt;A: A pirate ship, silly.&lt;/P&gt;
&lt;P&gt;Gripe #10: Don't use _alloca&lt;/P&gt;
&lt;P&gt;_alloca allocates memory off the stack instead of the heap. It's very convenient to use when you need a temporary buffer and don't want to worry about freeing it, but I try to avoid it whenever possible for two reasons: &lt;/P&gt;
&lt;P&gt;(1) it wrecks the ability for the compiler to make optimizations based on how much stack a function uses, and &lt;/P&gt;
&lt;P&gt;(2) when combined with the previous point, it leads to terrible, terrible crashes. If the user asks the machine for lots and lots of heap then the program churns away trying to allocate lots of memory before finally throwing an exception or returning null. The worst that can happen is not too bad. The worst that can happen if the stack is overallocated is that the stack guard page is hit for the second time and the process is terminated. (The exact behaviour of the win32 stack under low-stack conditions is interesting, and I will blog about it at some point; the script engines do some fancy footwork in this department to keep the stack from blowing.)&lt;/P&gt;
&lt;P&gt;Here's the thing -- if you have an upper bound on the amount of stack you're going to use, you might as well just ask for it. If you don't have an upper bound -- if the upper bound is determined by something at runtime and it could be arbitrarily big -- then use the heap, because really big stack allocations are too risky. &lt;/P&gt;
&lt;P&gt;For example, I'll often see code where _alloca is used to hold a temporary copy of a string when it is being converted from eight bit ASCII to UTF-16. Bad idea, particularly if the string can come from an untrusted internet script. The string could be a million bytes long, and blow the stack! Aaargh! It's drivin' me nuts!&lt;/P&gt;
&lt;P&gt;The thing is, stack allocation is incredibly fast, and in many situations the &lt;EM&gt;common&lt;/EM&gt; scenario is for the allocation to be small even if that's not guaranteed. Therefore I often use a "best of both worlds" strategy if I have data that is usually small but might be huge. First, I declare a stack buffer twice the size I expect to use. Then detect if more than that is required and allocate it off the heap if it is. (Of course, you have to remember to clean up the heap buffer if you do that.)&lt;/P&gt;
&lt;P&gt;*********************************&lt;/P&gt;
&lt;P&gt;You'll note how few new hit television series are called "Extreme Television Editing", or "New Issues In Satellite Uplink Futures Contract Law" -- though come to think of it, either of those would be more likely to catch my interest than the vast majority of the inaptly named "reality" television. Therefore I try to avoid talking about the blog in the blog -- I personally find blogs about blogging boring. I'll keep this short then.&lt;/P&gt;A number of people have asked me questions like "can I quote your blog in my blog?", "can I post your article in my wiki?", "can I use this information in my MSDN Magazine article?" etc. 
&lt;P&gt;I'm putting this information on the web because I want it to reach the people who can use it, so by all means, disseminate the information widely. I ask only four things: &lt;/P&gt;
&lt;P&gt;1) Please give me a heads-up before you do. &lt;BR&gt;2) Please attribute the source, preferably with a link back to the original. &lt;BR&gt;3) Please don't quote me out of context. &lt;BR&gt;4) Please understand that by doing so, you remove my ability to correct mistakes in your copy. &lt;/P&gt;
&lt;P&gt;UPDATE:&lt;A class="" href="http://blogs.msdn.com/ericlippert/archive/2008/10/07/boring-metablogging-part-two.aspx" mce_href="http://blogs.msdn.com/ericlippert/archive/2008/10/07/boring-metablogging-part-two.aspx"&gt; I have posted a follow-up to these guidelines.&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=193305" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/COM+Programming/default.aspx">COM Programming</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Aargh_2100_/default.aspx">Aargh!</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Metablogging/default.aspx">Metablogging</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/bad+jokes/default.aspx">bad jokes</category></item><item><title>Aargh! Part Seven</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/04/aargh-part-seven.aspx</link><pubDate>Fri, 04 Jun 2004 17:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:148620</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>23</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/148620.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=148620</wfw:commentRss><description>&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;
&lt;P&gt;Q: How do pirates keep their socks from falling down?&lt;/P&gt;
&lt;P&gt;A: Thumbtacks.&lt;/P&gt;
&lt;P&gt;I am insanely busy with bug fixing and performance testing today, so once more I'll dip into my endless archive of rants about irksome coding practices I've seen one time too many.&lt;/P&gt;&lt;FONT face="Lucida Sans Unicode" color=#000080 size=3&gt;
&lt;P&gt;Gripe #8: Assert the truth, the whole truth, and nothing but the truth&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;
&lt;P&gt;Debug assertions should always describe &lt;B&gt;invariants&lt;/B&gt; -- conditions that should &lt;I&gt;always&lt;/I&gt; happen &lt;I&gt;no matter what&lt;/I&gt;. They both help document your program, by making your invariants clear, and help catch bugs by alerting you when those invariants are violated. But assertions must describe what you believe to be &lt;B&gt;always&lt;/B&gt; true about your algorithm, not what you &lt;B&gt;hope&lt;/B&gt; is true:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;
&lt;P&gt;pv = malloc(10);&lt;BR&gt;Assert(NULL != pv);&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;Aargh! That's drivin' me nuts!&lt;/P&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;
&lt;P&gt;NULL&lt;/FONT&gt; is a legal return value of &lt;FONT face="Lucida Console" color=#000080 size=2&gt;malloc&lt;/FONT&gt; and you therefore can't assert that &lt;FONT face="Lucida Console" color=#000080 size=2&gt;malloc&lt;/FONT&gt; didn't return it. That condition, rare though it might be, has to be tested like any other. You can't simply declare that the world is going to turn out the way you'd like it.&lt;/P&gt;
&lt;P&gt;Sometimes you want to pop up warnings in your debug build when incredibly rare things happen. That's a great idea -- but create a little function called &lt;FONT face="Lucida Console" color=#000080 size=2&gt;CreateDebugWarning&lt;/FONT&gt; or some such thing, so that it does not get confused with &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;Assert&lt;/FONT&gt; &lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;.&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=#000080 size=3&gt;
&lt;P&gt;Gripe #9: Don't be so darn friendly&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;
&lt;P&gt;In C++ you can hide implementation details with the &lt;FONT face="Lucida Console" color=#000080 size=2&gt;private&lt;/FONT&gt; keyword, but sometimes you want to have two classes which have the ability to party on each other's internals. For example, you might have a collection class and an enumerator class that need to have a private way to communicate with each other. Such classes are called "friendly classes". One day I grepped the headers of an unnamed Microsoft application for the word &lt;FONT face="Lucida Console" color=#000080 size=2&gt;friend&lt;/FONT&gt;. It appeared over 600 times! Aargh!&lt;/P&gt;
&lt;P&gt;This is a bad sign. One class had &lt;I&gt;eleven&lt;/I&gt; different friend classes. When you have that many friends, there really is no difference between the private interface and the public interface. Visibility modifiers exist in the first place so that you can do information hiding and clean polymorphism. If you have to allow &lt;FONT face="Lucida Console" color=#000080 size=2&gt;friend&lt;/FONT&gt; access to so many different classes then your public interfaces are not clean. You have a bunch of classes depending on each other's implementation details in order to work properly. The information hiding afforded by classes and interfaces is a feature of C++ specifically designed to reduce the complexity inherant in large software projects -- &lt;FONT face="Lucida Console" color=#000080 size=2&gt;friend&lt;/FONT&gt; is a way to work around that limitation &lt;I&gt;when necessary&lt;/I&gt;. And there certainly are times when it is necessary, but overuse makes code more and more complex, intertwined, buggy and unmaintainable.&lt;/P&gt;
&lt;P&gt;Use friends very sparingly in C++ -- enumerators should be friends of collections, yes, but if documents are friends of views, you might have a problem on your hands. &lt;/P&gt;
&lt;P&gt;In C#, JScript .NET and VB.NET there are no friendly classes. Rather, there is &lt;FONT face="Lucida Console" color=#000080 size=2&gt;private&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt;, &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;public&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt; and &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;internal&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt; -- in C#, &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;private&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt; &lt;B&gt;really is private&lt;/B&gt;, but any class &lt;B&gt;in the same assembly&lt;/B&gt; can party on &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;internal&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt; data. This gives you a lot of the benefits of friendly classes while still being able to restrict access to stuff that is truly private.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=148620" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/COM+Programming/default.aspx">COM Programming</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rants/default.aspx">Rants</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Aargh_2100_/default.aspx">Aargh!</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/bad+jokes/default.aspx">bad jokes</category></item><item><title>Aaargh, Part Six: One More Thing About Comments</title><link>http://blogs.msdn.com/ericlippert/archive/2004/05/05/126739.aspx</link><pubDate>Wed, 05 May 2004 22:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:126739</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>14</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/126739.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=126739</wfw:commentRss><description>&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;
&lt;P&gt;&lt;FONT color=#000080&gt;Gripe #7: Use The Right Struct For The Job&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I meant to include this one in yesterday's gripe about comments, as this illustrates a time when I found a comment that should never have been there.&amp;nbsp; The person who wrote the comment should have realized that the very fact that they needed to put a comment in indicated that the code needed to be rewritten.&amp;nbsp; It slipped my mind at the time though, so here it is today.&lt;/P&gt;
&lt;P&gt;Here's a fragment of code I found in an unnamed Microsoft product once. The code is part of a fairly complicated routine for clipping a rectangle -- the details are unimportant for the purposes of this discussion. The code is &lt;STRONG&gt;correct&lt;/STRONG&gt;&amp;nbsp;-- it&amp;nbsp;performs the correct calculation and spits out the right answer --&amp;nbsp;but boy, is it hard to read:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;
&lt;P&gt;if (client.x &amp;gt; rect.right)&lt;BR&gt;&amp;nbsp; default.x += ((client.x - rect.right) / 2 - rect.left); &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#008000 size=2&gt;// right == width&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;if (client.y &amp;gt; rect.bottom)&lt;BR&gt;&amp;nbsp; default.y += ((client.y - rect.bottom) / 2 - rect.top); &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#008000 size=2&gt;// bottom == height&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;
&lt;P&gt;Holy cow, was that ever a bug waiting to happen. The data member that holds the width was named &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;right&lt;/FONT&gt; &lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;and the data member that holds the height was named &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;bottom&lt;/FONT&gt; &lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;! I needed to change this code and spent a good thirty solid minutes looking at the routine (which was much longer than shown here), running it in my head before I concluded that the comment and the code were in fact correct. &lt;/P&gt;
&lt;P&gt;Someone got lazy -- they already had a struct defined for a &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;{right, left, bottom, top}&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt; rectangle but they had the information &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;{left, width, top, height}&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;, so they just stuffed the information they were manipulating into the struct they had handy. Aaargh! It's drivin' me nuts!&lt;/P&gt;
&lt;P&gt;Worse, the comment is cryptic in the extreme.&amp;nbsp; It took me quite a while to figure out whether the equality operator in the comment was documenting a &lt;STRONG&gt;logical invariant&lt;/STRONG&gt; (that is, the comment means &amp;#8220;we know that the right coordinate is equal to the width because the left coordinate is always zero in this case&amp;#8220;) or whether they were just using the equality operator to mean &amp;#8220;has the semantics of&amp;#8220;.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Please don't put cryptic comments in the code explaining &lt;STRONG&gt;why code is misleading&lt;/STRONG&gt; -- fix the code so that it isn't misleading anymore! In this particular case, the rectangle in question was entirely local so there was no need to have it in a struct at all. I needed to modify this code anyway, so I got rid of the struct altogether and just declared four local variables for the left, width, top and height, appropriately named.&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=126739" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/COM+Programming/default.aspx">COM Programming</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rants/default.aspx">Rants</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Aargh_2100_/default.aspx">Aargh!</category></item><item><title>Aargh, Part Five: Comment Rot</title><link>http://blogs.msdn.com/ericlippert/archive/2004/05/04/125893.aspx</link><pubDate>Tue, 04 May 2004 19:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:125893</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>24</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/125893.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=125893</wfw:commentRss><description>&lt;DIV&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=navy size=2&gt;&lt;SPAN&gt;Gripe #6: Comment Rot
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;If you've been reading my &lt;A title=http://blogs.msdn.com/ericlippert/category/4518.aspx HREF="/ericlippert/category/4518.aspx"&gt;SimpleScript&lt;/A&gt; code you might have noticed that there are very few comments in my code.&amp;nbsp; That's deliberate.&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;Why do we have comments in the first place?&amp;nbsp; We have comments because sometimes the &lt;A title=http://blogs.msdn.com/ericlippert/archive/2004/03/01/82168.aspx HREF="/ericlippert/archive/2004/03/01/82168.aspx"&gt;semantics of the code are not clear from the syntax&lt;/A&gt;.&amp;nbsp; Remember, the syntax tells you what the code does, the semantics tell you why the developer wrote that code, what the &lt;I&gt;&lt;SPAN&gt;purpose&lt;/SPAN&gt;&lt;/I&gt; is.&amp;nbsp; 
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;I try to write code so that the semantics are clear just by reading the code, no comments required.&amp;nbsp; Code with one comment for every line &lt;A title=http://blogs.msdn.com/ericlippert/archive/2004/03/10/87384.aspx HREF="/ericlippert/archive/2004/03/10/87384.aspx"&gt;drives me nuts&lt;/A&gt;!&amp;nbsp; Imagine if people wrote books that way -- that their English was so unclear, so hard to understand that they needed to have a footnote on every sentence and paragraph explaining &lt;EM&gt;in some other language&lt;/EM&gt; what the intended meaning was!&amp;nbsp; It would be awful.
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;Worse, excessive comments cause "comment rot".&amp;nbsp; I don't know how many times I've been reading a piece of code, read a comment that said "there is such and such a problem with this code, I'll come back and fix it later", and sure enough, there is no problem anymore.&amp;nbsp; Or there is a problem, but it&amp;#8217;s a different problem.&amp;nbsp; People change the code, compile it, test it, and never fix the comments.&amp;nbsp; The more comments there are, the more likely it is that this will happen.&amp;nbsp; &lt;STRONG&gt;Wrong comments are usually&amp;nbsp;much worse than no comments at all.&lt;/STRONG&gt;
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;Slightly&amp;nbsp;less&amp;nbsp;horrid&amp;nbsp;than wrong comments are useless comments -- comments that do not explain the semantics, but restate the syntax.&amp;nbsp; How many times have you seen this:
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;j = j + 1&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=green size=2&gt;&lt;SPAN&gt;'&amp;nbsp; Increment j
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;Thank you so much, developer, for letting me know what &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;j = j + 1&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt; does!&amp;nbsp; In my advanced old age I was beginning to forget the first thing I ever learned about programming!&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;Why do people do this?&amp;nbsp; This would be better, as it explains the semantics:&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;j = j + 1&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=green size=2&gt;&lt;SPAN&gt;'&amp;nbsp; Go to the next line
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;but surely this is an opportunity to eliminate the comment entirely:
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;currentLine = currentLine + 1 &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=green size=2&gt;&lt;SPAN&gt;
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;When I write a piece of code with comments I want those comments to stand out, not get lost in a sea of triviality!&amp;nbsp; If I write a comment, you'd better believe that it's usually because the implementation of the intentions simply cannot be clearly expressed by the code, or because something really bizarre and important is going on.&amp;nbsp; (Like the weird garbage collection protection I mentioned earlier today.)&amp;nbsp; Comments should be signposts, your eye should be drawn to them because they're important.&amp;nbsp; Commenting style should train people to &lt;I&gt;&lt;SPAN&gt;read&lt;/SPAN&gt;&lt;/I&gt; the comments as they come across them in the code.&amp;nbsp; Writing lots of irrelevant comments trains people to &lt;I&gt;&lt;SPAN&gt;ignore&lt;/SPAN&gt;&lt;/I&gt; the comments!
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;A title=http://blogs.msdn.com/ericlippert/archive/2004/05/04/125837.aspx HREF="/ericlippert/archive/2004/05/04/125837.aspx"&gt;Earlier today&lt;/A&gt; I was talking about the default property semantics of &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;IDispatch&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;, and &lt;A title=http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx#122390 HREF="/ericlippert/archive/2004/04/28/122259.aspx#122390"&gt;earlier I commented&lt;/A&gt; that I'd blog about a conversation Matt Curland and I once had about the differences between VBScript's and VB's default property resolution in their respective Intellisense engines.&amp;nbsp; Now's a good chance to kill a few birds with one stone; one of my favourite comments I've ever written, and certainly one of the longest, is found in the VBScript Intellisense code that I wrote for Visual Interdev:
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // [Eric Lippert 1998-03-27] -- see Scripting bug 847&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // We now have the following problem.&amp;nbsp; We have "foo.bar(".&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // What if bar returns an object that has a default property?&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Suppose bar is a collection, for instance, with a default&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // property "item".&amp;nbsp; Then this should show statement completion&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // information for the "item" method, not for "bar" -- provided&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // that bar takes no arguments.&amp;nbsp; If bar takes arguments, then&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // we should show statement completion for bar.&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This generalizes to chains of defaults -- if bar is the default&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // property of foo, and bar takes no arguments, and bar&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // returns an object that has default property baz that takes&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // an argument blah, then&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // foo(&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // foo.bar(&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // foo.bar.baz(&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // should all return statement completion information for baz(blah).&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // So here's what we'll do:&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // First we determine if "bar" returns an object.&amp;nbsp; If it does,&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // we check and see if it has a default property chain.&amp;nbsp; If so, we&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // get type info for the final available function on the default&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // property chain.&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Second, if bar is a function that takes arguments, we return&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // function information for bar.&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // If bar does not take arguments and bar returns an object with&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // a default property, then we return info on the default property.&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Otherwise, we return information on bar.&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This is not actually what Visual Basic does.&amp;nbsp; VB does the&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // following: (from email by Matt Curland, 1998-03-27)&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=red size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // "If no parameters are supplied never call the default unless&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=red size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // you're in an assignment statement without a Set. If you're&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=red size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // in a non-ending statement of a call chain then only do&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=red size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // the default resolution if the specified function doesn't have&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=red size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // its own parameters and a parameter is actually specified."&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // That is not exactly what we're doing here, but it's close enough&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // as far as I'm concerned.&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Sans Unicode" color=purple&gt;&lt;SPAN&gt;Gross, gross, gross.&amp;nbsp; And actually I've cut it short -- the comment then goes on to describe even more weirdnesses with the case where &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=navy&gt;&lt;SPAN&gt;foo.bar(blah)(&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=purple&gt;&lt;SPAN&gt;&lt;FONT size=2&gt; gets Intellisense on a method that returns a collection.&amp;nbsp; This is very complicated code; I wanted anyone who was about to change it to understand fully what the meaning behind it was.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;The other thing that amuses me greatly about this comment is that apparently there were only 847 bugs in the scripting database at the time!&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=125893" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rants/default.aspx">Rants</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Aargh_2100_/default.aspx">Aargh!</category></item><item><title>Aargh, Part Four: There is no part four</title><link>http://blogs.msdn.com/ericlippert/archive/2004/03/29/101251.aspx</link><pubDate>Mon, 29 Mar 2004 17:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:101251</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/101251.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=101251</wfw:commentRss><description>&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;I've got all these little rants queued up for days when I'm too busy to post.&amp;nbsp; And Raymond has all these little articles queued up while he's on vacation.&amp;nbsp; And in one of those weird Brouwer Fixed Point Theorem moments of synchronicity, Raymond just beat me to it.&amp;nbsp; His post on how people write incorrect implementations of QueryInterface is different than the one I was going to post only insofar as his is more complete and has fewer pirate jokes.&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;In short: I've come across plenty of code where the QueryInterface responds to IPersistBlahBlahBlah but not IPersist.&amp;nbsp; Drives me nuts!&amp;nbsp; Argh!&amp;nbsp; Read Raymond's post for more details.
&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;&lt;SPAN&gt;&lt;A title=http://weblogs.asp.net/oldnewthing/archive/2004/03/26/96777.aspx HREF="/oldnewthing/archive/2004/03/26/96777.aspx"&gt;http://weblogs.asp.net/oldnewthing/archive/2004/03/26/96777.aspx&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=101251" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/COM+Programming/default.aspx">COM Programming</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rants/default.aspx">Rants</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Aargh_2100_/default.aspx">Aargh!</category></item><item><title>Aaargh! Part Three</title><link>http://blogs.msdn.com/ericlippert/archive/2004/03/25/aaargh-part-three.aspx</link><pubDate>Thu, 25 Mar 2004 21:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:96373</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/96373.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=96373</wfw:commentRss><description>&lt;DIV id=idOWAReplyText18632 dir=ltr&gt;
&lt;DIV dir=ltr&gt;&lt;FONT face=Arial color=#000000 size=2&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080&gt;I'm still at VSLive.&amp;nbsp; Both my talks are done, so its just booth duty from here on in.&amp;nbsp; The talks went... OK.&amp;nbsp;Running VSTO on top of Virtual PC on a laptop was&amp;nbsp;too slow; we'll have to&amp;nbsp;devirtualize that for the next time.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080&gt;Unfortunately they put me in the keynote room, which seats over a thousand.&amp;nbsp; Now, when 200 people show up for a talk, that's great --&amp;nbsp;but in such an enormous room, it's really, really hard to get the audience enthusiam up when they're spread out over what seemed like a couple of acres.&amp;nbsp; But I got a lot of good questions afterwards, so hopefully a few people were awake and learned something.&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080&gt;No time to&amp;nbsp;write, so another canned gripe about&amp;nbsp;C++ idioms that&amp;nbsp;are drivin'&amp;nbsp;me nuts&amp;nbsp;today -- but first, an excerpt from &lt;A href="http://www.mcsweeneys.net/2000/06/14pirates.html "&gt;Pirate Riddles For Sophisticates&lt;/A&gt;.&amp;nbsp;&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080&gt;Q: Whom did the pirate vote for in the first Haitian election? &lt;BR&gt;A: ARRRistide. &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080&gt;Q: Wait. Why did they let a pirate vote in the Haitian election? &lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080&gt;A: Remember, the nation was taking its first halting steps toward democracy, and balloting procedures were rather chaotic. The pirate just slipped in somehow. Arrr.&lt;/FONT&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#000080&gt;Gripe #5: Exception Handling and operator new&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;In C++ you can easily change the&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;new&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt; operator to throw an exception when it runs out of memory instead of returning&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;NULL&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;.&amp;nbsp; Cool idea, but it can be very dangerous because this causes a global change in the behaviour of a commonly used operator.&amp;nbsp; What happens when you do that in a program that contains libraries that do not have that assumption?&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;try&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;{&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;&amp;nbsp; m_pbar = m_pfoo-&amp;gt;bar();&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;} catch //&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#800080 size=2&gt;...&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;where you grabbed the source code for that class and just kind of compiled it in:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;Bar * CFoo::bar(void)&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;{&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;&amp;nbsp; HANDLE h = NULL;&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;&amp;nbsp; h = GoGetMeAFileHandle();&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;&amp;nbsp; m_pBlah = new CBlah;&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;&amp;nbsp; if (NULL == m_pBlah){&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FreeFileHandle(h);&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return NULL;&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;&amp;nbsp; }&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;&amp;nbsp;// ...&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;You didn't write&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;CFoo::bar&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;, but you've just broken its error handling if you redefined&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;new&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt; to throw an error instead of returning&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;NULL&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;.&amp;nbsp; Now if the allocation of&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;CBlah&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt; fails, you've leaked a kernel object.&amp;nbsp;This is another example where idioms like smart pointers need to be &lt;STRONG&gt;consistently applied across an application&lt;/STRONG&gt; in order to reap their benefits.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;I have debugged leaks in IIS where these kinds of things happen and they are absolutely no fun for our customers.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;I once debugged some code where the&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;new&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt; operator had been redefined to throw an exception, and the authors did something very clever.&amp;nbsp; (Aside: clever is bad -- clever is hard to figure out!&amp;nbsp; If the code is clever, rewrite it until it is brain-dead obvious.)&amp;nbsp; In the debug build, they wrote some magic into the operator so that it detected if it was being called without an exception handler and raised an assertion.&amp;nbsp; Sounds cool, right?&amp;nbsp; Any possible negative consequences of that?&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;Well, how about the fact that static objects which have constructors that call&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;new&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt; cannot be linked in to the application without the program asserting on startup?&amp;nbsp; The standard&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;map&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;vector&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;, etc, objects are such objects.&amp;nbsp; Their constructors call&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;new&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;, and therefore you can't have a static&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;map&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;. Statics have no context to&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;catch&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt; the possible&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;throw&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;, and therefore will assert when the debug application starts up.&amp;nbsp; (Guess how I found that bug?)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;That said, I can see how it is useful to have a&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;new&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt; operator that throws an exception.&amp;nbsp; You know what I'd do if I wanted that?&amp;nbsp; I'd define an operator overload that took an argument, create a dummy identifier called "throws", and then say&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;pBar = new(throws) CBar&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;&amp;nbsp; -- now it is perfectly clear what the semantics of that thing are.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;Redefining the global&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt; &lt;FONT face="Lucida Console" color=#000080 size=2&gt;new&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;/SPAN&gt;&lt;SPAN lang=en-us&gt;&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt; operator works great if you have 100% control over all contexts where the operator is used.&amp;nbsp; Unfortunately, that's frequently not a realistic assumption!&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=96373" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/COM+Programming/default.aspx">COM Programming</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rants/default.aspx">Rants</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Aargh_2100_/default.aspx">Aargh!</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/bad+jokes/default.aspx">bad jokes</category></item><item><title>Aaargh!  Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/03/23/aaargh-part-two.aspx</link><pubDate>Tue, 23 Mar 2004 17:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:94651</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/94651.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=94651</wfw:commentRss><description>&lt;FONT face="Lucida Sans Unicode" color=#800080 size=2&gt;
&lt;P&gt;I'm insanely busy prepping for VSLive! today, so, once more, I complain about coding practice that are &lt;A href="http://blogs.msdn.com/ericlippert/archive/2004/03/10/87384.aspx"&gt;&lt;U&gt;drivin' me nuts&lt;/U&gt;&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;But first: why do pirates dislike Johnny Depp's Oscar-nominated performance in "Pirates of the Caribbean"?&lt;/P&gt;
&lt;P&gt;Because it wasn't AAAAAARRRR-rated.&lt;/P&gt;&lt;FONT color=#000080 size=3&gt;
&lt;P&gt;Gripe #3: More Complaining About Bad Macros&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;&lt;FONT size=2&gt;One day I was debugging a bunch of macro-ridden code that I didn't write. I wanted to know what the method signature of &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#000080&gt;CForm::GetMouseIcon&lt;/FONT&gt;&lt;FONT color=#800080&gt; was. So, silly me, I grepped the source code for &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;CForm::GetMouseIcon&lt;/FONT&gt;&lt;FONT color=#800080&gt;. Nothing. Must be defined in the class header itself! So I grepped for &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;GetMouseIcon&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;&lt;FONT size=2&gt;. Nothing. Aaargh! It was drivin' me nuts!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Inspiration hit -- I grepped for &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#000080&gt;MouseIcon&lt;/FONT&gt;&lt;FONT color=#800080&gt; and found in some header somewhere&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;
&lt;P&gt;DEFINE_DERIVED_GETSET_METHODS(CForm, CServer, MouseIcon, IID_IPicture)&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;&lt;FONT size=2&gt;Aaargh! I &lt;I&gt;still&lt;/I&gt; didn't know what the signature was until I managed to find that macro definition and decode it! Why do people write code like this? You can't easily debug into &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#000080&gt;CForm::GetMouseIcon&lt;/FONT&gt;&lt;FONT color=#800080&gt;, you can't find it easily using grep, etc. Why define this stuff in macros? Does it really make anyone's life easier?&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000080 size=3&gt;
&lt;P&gt;Gripe #4: Exception Handling, Return Values and Smart Pointers&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;You probably knew I couldn't actually &lt;I&gt;not&lt;/I&gt; complain about smart pointers, &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/ericlippert/archive/2003/09/16/53016.aspx"&gt;&lt;U&gt;&lt;FONT color=#0000ff&gt;the bane of my existence&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;FONT color=#800080&gt;. I'm so predictable.&lt;/P&gt;
&lt;P&gt;Before I start complaining about exception handling, please, I don't want to have a replay of that &lt;I&gt;Joel On Software&lt;/I&gt; debate about the merits of structured exception handling. I think exception handling is super. I love writing code in C# that uses exception handling. &lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#000080&gt;catch&lt;/FONT&gt;&lt;FONT color=#800080&gt; allows you to isolate your error handling code into strictly scoped blocks, and &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;finally&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;&lt;FONT size=2&gt; allows you to isolate your cleanup code, and that's all good.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;The problem I have with structured exception handling is that programs that mix libraries that use SEH and libraries that return error codes, (like, say, &lt;I&gt;every single COM API&lt;/I&gt;) often turn into a godawful mess. You end up with the worst of both worlds: exceptions potentially going off all over the place acting as non-local gotos, and still having to pay careful attention to error return codes, thereby de-localizing the error handling code. C# and the .NET Framework were designed to use exception handling from day one, so it makes a lot of sense. COM was not!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;As we saw &lt;/FONT&gt;&lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/ericlippert/archive/2004/03/10/87384.aspx"&gt;&lt;U&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;last time&lt;/FONT&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=2&gt;&lt;FONT color=#800080&gt;, the tempting thing to do is to wrap every error-returning function with a macro that turns it into a &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;throw&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;&lt;FONT size=2&gt;, and wrap every must-be-released handle with a smart object that will clean up when it goes out of scope. But the resulting complexity means that often the cure is worse than the disease. We've already seen the havoc that macros wreak. What about smart pointers?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Case in point -- one of my coworkers and I were debugging a weird problem in some of our code just last week. We called into a particular API which was setting the &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#000080&gt;GetLastError&lt;/FONT&gt;&lt;FONT color=#800080&gt; value. Something in our code was blowing it away, so we wrote some code to preserve it. It didn't work; when our function returned, &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;GetLastError&lt;/FONT&gt;&lt;FONT color=#800080&gt; was still reporting that there had been no error. How could that be? What's wrong with this picture?&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;
&lt;P&gt;&amp;nbsp; // Ensure that we've preserved the error state we captured earlier&lt;BR&gt;&amp;nbsp; SetLastError(blah); &lt;BR&gt;&amp;nbsp; return hr; &lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;&lt;FONT size=2&gt;The caller of this method calls&amp;nbsp; &lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#000080&gt;GetLastError&lt;/FONT&gt;&lt;FONT color=#800080&gt; &lt;/FONT&gt;&lt;/FONT&gt;, but the state we just set has been blown away. OK, smart people, where does that happen?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Turned out that a smart pointer in the current scope was holding on to a proxy for an out-of-process COM object, and when the smart pointer went away, the out-of-proc object was released, which resulted in a whole slew of calls behind the scenes, which resulted in the &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#000080&gt;GetLastError&lt;/FONT&gt;&lt;FONT color=#800080&gt; value being overwritten. Of course, since this was a smart pointer destructor doing all this, the source code for the call site looked like this:&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;
&lt;P&gt;} &amp;lt;-- calls destructor&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt;
&lt;P&gt;Aargh! It's drivin' me nuts! Call me crazy, but I want operations bearing complex semantics and causing side effects that break my error handling to look &lt;B&gt;a little more like function calls and a little less like punctuation&lt;/B&gt;. Had the code been written using dumb pointers, no problem&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;
&lt;P&gt;&amp;nbsp; // Ensure that we've preserved the error state we captured earlier&lt;BR&gt;&amp;nbsp; SetLastError(blah); &lt;BR&gt;&amp;nbsp; pProxy-&amp;gt;Release(); &lt;BR&gt;&amp;nbsp; return hr;&lt;BR&gt;} &amp;lt;-- no op&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;&lt;FONT size=2&gt;Now it's obvious where the mistake is.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;COM programming demands discipline and a keen understanding of how to write correct error-path code &lt;B&gt;whether you also use exception handling or not&lt;/B&gt;. Therefore, I say don't use exception handling if you're going to be doing a whole lot of COM-style error handling too! I like to think that I'm a fairly bright guy, but &lt;B&gt;I have great difficulty analyzing the semantics of code that has macros, template classes, smart pointers, exception raisers, error return values and cross-process COM calls all &lt;I&gt;in the same routine&lt;/I&gt;. I'm not that smart!&lt;/P&gt;&lt;/B&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT size=2&gt;I've developed a coding style that works very well with COM -- it is verbose, it is rigid, and it is very, very clear to even novice programmers exactly what the lifetime of all pointers in the code are -- and my code rarely has reference leaks because of it, even in error cases. And when it does, they are a snap to track down because every time a pointer is addrefed there is a call to &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#000080&gt;AddRef&lt;/FONT&gt;&lt;FONT color=#800080&gt; and every time it is released there is a call to &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;Release&lt;/FONT&gt;&lt;FONT color=#800080&gt; right there in the code, not tucked away in some template library. It's not hard to develop a good coding standard.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#800080&gt;Next time: even more on bad interactions between exception handling and memory management&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=94651" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/COM+Programming/default.aspx">COM Programming</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rants/default.aspx">Rants</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Aargh_2100_/default.aspx">Aargh!</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/bad+jokes/default.aspx">bad jokes</category></item><item><title>Aargh, Part One: A Pirate Walks Into A Bar…</title><link>http://blogs.msdn.com/ericlippert/archive/2004/03/10/aargh-part-one-a-pirate-walks-into-a-bar.aspx</link><pubDate>Wed, 10 Mar 2004 18:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:87384</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>15</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/87384.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=87384</wfw:commentRss><description>&lt;FONT face="Lucida Sans Unicode" color=#800080&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;&lt;FONT size=2&gt;One of my former housemates was fond of pirate jokes, &lt;/FONT&gt;&lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/ericlippert/archive/2003/09/19/53054.aspx"&gt;&lt;U&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;as am I&lt;/FONT&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;FONT color=#800080&gt;&lt;FONT size=2&gt;. My personal favourite of his was:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT color=#000080 size=2&gt;A pirate walks into a bar, and the barkeep says "&lt;I&gt;Excuse me, cap'n, but did you know that you've got your ship's wheel stuck in your pantaloons&lt;/I&gt;?" &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000080 size=2&gt;"&lt;I&gt;Aye&lt;/I&gt;," says the pirate, "&lt;I&gt;that thing be drivin' me nuts!&amp;nbsp; Aaargh!&lt;/I&gt;" &lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size=2&gt;Today: stuff that drives me nuts, part one of an ongoing series which I will continue whenever I'm too busy to write.&amp;nbsp; (Complaining is easy.)&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT color=#800080 size=2&gt;
&lt;P&gt;I've reviews a lot of code over the years, most of which was very high quality.&amp;nbsp; But no code is perfect.&amp;nbsp;There are some&amp;nbsp;bad patterns&amp;nbsp;I see over and over again that are easy to fall into but suboptimal in subtle ways.&amp;nbsp; M&lt;/FONT&gt;ost of this series will apply specifically to COM programming, but I may throw in a few scripting peeves as well.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;I have already griped about &lt;/FONT&gt;&lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/ericlippert/archive/2003/09/16/53016.aspx"&gt;&lt;U&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;smart pointers&lt;/FONT&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;FONT color=#800080 size=2&gt; and &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/ericlippert/archive/2003/09/16/53015.aspx"&gt;&lt;U&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;bad Hungarian&lt;/FONT&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;FONT color=#800080&gt;&lt;FONT size=2&gt;, so I'll give them a miss.&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#000080 size=3&gt;
&lt;P&gt;Gripe #1: Too Many Comments&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt;&lt;/P&gt;
&lt;P&gt;Comments should explain places where the semantics is not obvious from the syntax. Here's some code I found deep in the persistence code of an unnamed Microsoft product:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#008000 size=2&gt;
&lt;P&gt;// Read cItems&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;CheckHresult( pStm-&amp;gt;Read( &amp;amp;cItems, sizeof(LONG), NULL), pStm, IID_IStream );&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#008000 size=2&gt;// Allocate a block which can hold cItems&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;pItems = new DWORD[cItems];&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#008000 size=2&gt;// Read the block of items &lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;CheckHresult( pStm-&amp;gt;Read(pItems, cItems * sizeof(LONG), NULL), pStm, IID_IStream);&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;&lt;FONT size=2&gt;Aargh! It's drivin' me nuts! &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;(Aside: Why no error checking on the &lt;FONT face="Lucida Console" color=#000080&gt;new&lt;/FONT&gt;? More on that next time.&amp;nbsp; Also, this reminds me that I want to do a blog on security aspects of serialization code some time.)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Having one comment per line which simply restates the following line in English instead of C++ doesn't help anyone &lt;I&gt;understand&lt;/I&gt; the code, it just makes the code &lt;I&gt;longer&lt;/I&gt;. &lt;/FONT&gt;&lt;/P&gt;&lt;I&gt;&lt;/I&gt;
&lt;P&gt;&lt;FONT size=2&gt;It's worse than that. It &lt;I&gt;dilutes&lt;/I&gt; the value of comments -- you should be able to look through a piece of code and find all the really interesting bits by looking for the comments. If there are comments everywhere, 90% of which explain nothing that couldn't be gleaned from reading the code itself then the 10% of the useful comments -- the ones that explain the semantics -- will never be noticed.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Furthermore, comments "go bad" -- when you do this habitually, it is really easy to change the code and forget to change the comments. Then the comments no longer accurately describe how the code &lt;I&gt;is&lt;/I&gt;, but rather how it &lt;I&gt;was&lt;/I&gt;. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Comments should also be of appropriate size. Here is a fragment of a script I recently code reviewed.&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#008000&gt;
&lt;P&gt;&lt;FONT size=2&gt;''''''''''''''''''''''''''''''''''''''''''''''''''''''''&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;''&amp;nbsp;&amp;nbsp; DISABLE SCREEN SAVER&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;''''''''''''''''''''''''''''''''''''''''''''''''''''''''&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;&lt;FONT size=2&gt;WScript.Echo "Disabling Screen Saver"&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;[ then code here that disabled the screen saver ]&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt;
&lt;P&gt;OK, I'm reading the code, and I see the line&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;
&lt;P&gt;WScript.Echo "Disabling Screen Saver"&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt;
&lt;P&gt;and I can probably guess what the next line of code does without having the &lt;B&gt;five lines&lt;/B&gt; above it consumed by comments and whitespace! I want these huge block comments to be catching my eye for really incredibly important stuff. Otherwise, it's just consuming valuable screen real estate, preventing me from getting more semantics-bearing code onto one screen.&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#000080 size=3&gt;
&lt;P&gt;Gripe #2: Bad Macros&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;&lt;FONT size=2&gt;The sharp-eyed among you will have wondered about the &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;CheckHresult&lt;/FONT&gt;&lt;FONT color=#800080&gt;&lt;FONT size=2&gt; call above. What the heck is that thing doing? It's turning &lt;FONT face="Lucida Console" color=#000080&gt;HRESULT&lt;/FONT&gt;s into exceptions.&amp;nbsp; (More on why that's a bad idea later.)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Unfortunately, it's a macro. Here's some code that I once wrote using this macro, from the aforementioned persistence code. I was adding the ability to save the state in a new format. Does there appear to be anything wrong with it? (&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#000080&gt;LoadOldFileFormat&lt;/FONT&gt;&lt;FONT color=#800080&gt; doesn't return an error, it throws exceptions. &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;LoadNewFileFormat&lt;/FONT&gt;&lt;FONT color=#800080&gt; returns an &lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;HRESULT&lt;/FONT&gt;&lt;FONT color=#800080&gt;.) &lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;
&lt;P&gt;&lt;FONT size=2&gt;if (fOldFileFormat)&lt;BR&gt;&amp;nbsp; LoadOldFileFormat(pStorage);&lt;BR&gt;else if (NULL != pNewStream)&lt;BR&gt;&amp;nbsp; CheckHresult(LoadNewFileFormat(pNewStream), (IPersistStream*)this, IID_IPersistStream);&lt;BR&gt;else&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Console" color=#008000&gt;&amp;nbsp; // This file is not in any of our formats.&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080&gt;&amp;nbsp; Throw(E_FAIL);&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;&lt;FONT size=2&gt;Imagine my surprise to see that the compiler produces a &lt;B&gt;syntax error&lt;/B&gt; when attempting to compile this code.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;I didn't write that macro, so I had no idea what it did -- I was &lt;/FONT&gt;&lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/ericlippert/archive/2004/03/01/82168.aspx"&gt;&lt;U&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;cargo-cult programming&lt;/FONT&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;FONT color=#800080&gt;&lt;FONT size=2&gt;! All the other code that returned&amp;nbsp;error codes&amp;nbsp;called this macro, so I figured I should do so as well. Bad developer! No biscuit!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;I ran that through the C preprocessor, and take a look at what popped out: (I've added whitespace and removed some cruft for clarity.)&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#000080 size=2&gt;
&lt;P&gt;if (fOldFileFormat)&lt;BR&gt;&amp;nbsp; LoadOldFileFormat(pStorage);&lt;BR&gt;else if (0 != pStream)&lt;BR&gt;{ &lt;BR&gt;&amp;nbsp; HRESULT _hr;&amp;nbsp;&lt;BR&gt;&amp;nbsp; if ((_hr=LoadNewFileFormat(pXMLStream)) &amp;lt; 0)&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Throw(_hr);&amp;nbsp;&lt;BR&gt;} ; &lt;BR&gt;else&lt;BR&gt;&amp;nbsp; Throw(0x80004005L);&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080&gt;
&lt;P&gt;&lt;FONT size=2&gt;The trailing semi effectively terminates the &lt;FONT color=#000080&gt;if &lt;/FONT&gt;and the compiler then balks on the &lt;FONT color=#000080&gt;else&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Aaaaaargh! It's drivin' me nuts!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;If you're going to have macros, don't write them so that they break C++'s lexical semantics in weird, hard-to-track-down ways. Obviously this wasn't &lt;I&gt;intentional&lt;/I&gt;, which just makes my point even stronger -- &lt;B&gt;it is very hard to write correct macros, so don't even try.&lt;/B&gt; Don't write macros that look like functions, write &lt;B&gt;actual inline functions&lt;/B&gt; and let the compiler take care of optimizing them. Inline functions are guaranteed to not have weird lexical side effects that are not apparent from the text.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;In this particular case, we have a macro which represents a &lt;B&gt;statement block&lt;/B&gt; but&amp;nbsp;can be used like a &lt;B&gt;statement&lt;/B&gt;. The correct thing to do given the definition of this macro is to never terminate it with a semicolon, which looks weird -- no one will be able to remember to do the correct thing!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Next time, more on &lt;B&gt;how mixing C++ exception handling and COM programming drives me nuts.&lt;/P&gt;&lt;/B&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=87384" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/COM+Programming/default.aspx">COM Programming</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rants/default.aspx">Rants</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Aargh_2100_/default.aspx">Aargh!</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/bad+jokes/default.aspx">bad jokes</category></item></channel></rss>