<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://bloggingabout.net/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>Jan Schreuder on .Net : Code inspections</title><link>http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx</link><description>Tags: Code inspections</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>What the f**k..</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/10/30/what-the-f-k.aspx</link><pubDate>Thu, 30 Oct 2008 12:10:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:476354</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=476354</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2008/10/30/what-the-f-k.aspx#comments</comments><description>&lt;p&gt;I see a lot of code from other developers and every now and then you see some real gems. Today I was looking at a query to see if and&amp;nbsp;how it could be optimised. One of the things I did was look at the query plan to see if indexes were used for various joins.&amp;nbsp;One of the items in the plan made me look at a table definition, to&amp;nbsp;check on it&amp;#39;s indexes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I then discovered that one of the tables joined into the query contained an index on every column?!?!?! I checked other queries that used the same table and discovered that all joins on that table were made on the column that made up the primary key. That primary key was a clustered index, so barely impossible to try and optimize that. &lt;/p&gt;
&lt;p&gt;The F**K factor in this is of course what in heavens name posessed the developer that designed that table was actually thinking. The table contains 10 columns and 10 indexes. I removed&amp;nbsp;all but the primary key and the query still performed as it was. Inserts and updates on the table are flying now, obviously. &lt;/p&gt;
&lt;p&gt;Motto: Think before you index a column!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=476354" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/General/default.aspx">General</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>How to - Create a missing designer.cs file</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/10/17/how-to-create-a-missing-designer-cs-file.aspx</link><pubDate>Fri, 17 Oct 2008 09:49:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:475653</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=475653</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2008/10/17/how-to-create-a-missing-designer-cs-file.aspx#comments</comments><description>&lt;p&gt;I was running into this just now and found a quick way to solve it, so I just posted it for future reference.&lt;/p&gt;
&lt;p&gt;I have an ASP.Net web application project in .Net 2.0 which was migrated from .Net 1.1 some time ago. I noticed that a few aspx pages did not have a designer.cs file. All controls on those pages were listed as protected variable in the main code behind page, like this example:&lt;/p&gt;
&lt;div style="font-size:9pt;background:#f5f5f5;overflow:auto;width:100%;color:black;font-family:Courier New;border:#cccccc 1pt solid;padding:1pt;"&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; An example label&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; System.Web.UI.WebControls.&lt;span style="color:#2b91af;"&gt;Label&lt;/span&gt; Label2;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And it annoyed me. It was not consistent with the new pages in the application, and most other aspx pages that were also there during migration did have the designer.cs file. So how to solve this, in order to get a more consistent use of ASP.Net. I followed the following steps to do this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First step - Make sure the latest version of the project is on your machine.&lt;/li&gt;
&lt;li&gt;Second step is to remove the protected variables for the controls from the normal code behind cs file.&lt;/li&gt;
&lt;li&gt;Now right-Click on the project and select &amp;#39;Convert to Web Application&amp;#39;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The missing designer.cs is now created and added to the project. The protected variables, which were removed from the main code behind class are now in the partial class in the newly created designer.cs. The class in the original code behind class is also changed to a partial class.&lt;/p&gt;
&lt;p&gt;If you forget step 2 and still want to remove the protected variables from your code behind class, then follow the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Remove the protected variables for the controls from the normal code behind cs file.&lt;/li&gt;
&lt;li&gt;Open the ASPX file and make sure you view it in Source (HTML) mode &lt;/li&gt;
&lt;li&gt;Select the entire HTML mark up using CTRL-A&lt;/li&gt;
&lt;li&gt;Now press CTRL-K followed by CTRL-F&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The HTML mark-up will be re-aligned and the designer.cs file will be recreated, including all the protected variables.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=475653" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+Samples/default.aspx">Code Samples</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/.Net+Do_2700_s+_2600_amp_3B00_+Don_2700_ts/default.aspx">.Net Do's &amp;amp; Don'ts</category></item><item><title>Syntax error? Really?!?!</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/09/25/syntax-error-really.aspx</link><pubDate>Thu, 25 Sep 2008 09:44:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:474818</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=474818</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2008/09/25/syntax-error-really.aspx#comments</comments><description>&lt;p&gt;In my current project, we have adopted &lt;a target="_blank" href="http://blogs.msdn.com/sourceanalysis/"&gt;Microsoft StyleCop&lt;/a&gt; as a tool to make sure everyone sticks to the same style of coding. One of the things we currently incorporate in our daily work is making sure our existing code conforms to the rules we agreed on. Today however, StyleCop refused to check a class because of a syntax error in the following line of code:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;
&lt;pre style="MARGIN:0px;"&gt;&lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; fraction = totalStaff &amp;gt; 0 &lt;/pre&gt;
&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ? fraction = (&lt;span style="color:#0000ff;"&gt;double&lt;/span&gt;)completed / (&lt;span style="color:#0000ff;"&gt;double&lt;/span&gt;)totalStaff &lt;/pre&gt;
&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; : fraction = 0;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The code you see here is part of a calculation to get the percentage of users that have completed a certain training module. The compiler sees no problem, and the result is as you would expect. But looking at the code, you do see something really weird. The variable &lt;span style="color:#0000ff;font-family:courier new,courier;"&gt;&lt;strong&gt;fraction&lt;/strong&gt;&lt;/span&gt; is always assigned twice. Maybe not a syntax problem, but strange and not necessary. &lt;/p&gt;
&lt;p&gt;The following code does the same and only assigns the value once.&lt;/p&gt;
&lt;div style="font-size:9pt;background:#f5f5f5;overflow:auto;width:100%;color:black;font-family:Courier New;border:#cccccc 1pt solid;padding:1pt;"&gt;
&lt;pre style="margin:0px;"&gt;&lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; fraction = totalStaff &amp;gt; 0 &lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ? (&lt;span style="color:#0000ff;"&gt;double&lt;/span&gt;)completed / (&lt;span style="color:#0000ff;"&gt;double&lt;/span&gt;)totalStaff &lt;/pre&gt;
&lt;pre style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;So why would someone do it twice? &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=474818" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Tools/default.aspx">Tools</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/General/default.aspx">General</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/.Net+Do_2700_s+_2600_amp_3B00_+Don_2700_ts/default.aspx">.Net Do's &amp;amp; Don'ts</category></item><item><title>Thank you, Lutz Roeder</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/08/26/thank-you-lutz-roeder.aspx</link><pubDate>Tue, 26 Aug 2008 21:47:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:473366</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=473366</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2008/08/26/thank-you-lutz-roeder.aspx#comments</comments><description>&lt;p&gt;I just received an email from Lutz Roeder informing the users of Reflector that he decided to explore new opportunities. He has reached an agreement with RedGate software to continue work on Reflector. From his email:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;I have reached an agreement to have &lt;a target="_blank" href="http://www.red-gate.com/"&gt;Red Gate Software&lt;/a&gt; continue the development of .NET Reflector. Red Gate has a lot of experience creating development tools for both .NET and SQL Server. They have the resources necessary to work on new features, and Reflector fits nicely with other .NET tools the company offers.&lt;br /&gt;&lt;/em&gt;&lt;em&gt;&lt;br /&gt;Red Gate will continue to provide the free community version and is looking for your feedback and ideas for future versions.&lt;br /&gt;&lt;br /&gt;For news and updates on Reflector, sign up for the &lt;a target="_blank" href="http://reflector.red-gate.com/subscribe.aspx"&gt;.NET Developer&amp;rsquo;s Newsletter&lt;/a&gt; from Red Gate. To find out more about the agreement, see the interview on &lt;a target="_blank" href="http://www.simple-talk.com/the_future_of_reflector"&gt;Simple Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I really want to thank Lutz for all the great work he&amp;#39;s done with Reflector, allowing us to explore the code inside .Net assemblies. He brought an excellent tool to our community and literally opened up .Net code for all to see&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=473366" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Tools/default.aspx">Tools</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Articles/default.aspx">Articles</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>StyleCop - QuickStart tips</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/08/21/stylecop-some-quickstart-pointers.aspx</link><pubDate>Thu, 21 Aug 2008 07:15:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:472229</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=472229</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2008/08/21/stylecop-some-quickstart-pointers.aspx#comments</comments><description>&lt;p&gt;After using StyleCop for some weeks, there are some things I think that might be useful to others when they want to start using the tool. So here are some tips.&lt;/p&gt;
&lt;h3&gt;Tip 1 -&amp;nbsp;Also download the documentation&lt;/h3&gt;
&lt;p&gt;The documentation for StyleCop is available as a separate download. It explains why the rules are introduced and how you can fix violations. Without this documentation, you may think some of the rules are useless or annoying.&lt;/p&gt;
&lt;h3&gt;Tip 2 - Do not run the tool on an entire solution&lt;/h3&gt;
&lt;p&gt;At least, not untill you&amp;#39;re satisfied that your code complies with the rules. You get so many warnings in a project or solution where the tool hasn&amp;#39;t been used before, that you may think to stop using it immediately. &lt;/p&gt;
&lt;h3&gt;Tip 3 - Running the tool on one class file&lt;/h3&gt;
&lt;p&gt;Could have been in tip 2 as well, but I wanted to make a distinction here. When you right-click in the code, you will see the item &lt;strong&gt;Run StyleCop&lt;/strong&gt;. Select this, and the tool will only check that particular class file. The number of warnings is signicantly less than when you run the tool on an entire project or solution, so the results are more obvious and motivate you more to keep using the tool.&lt;/p&gt;
&lt;h3&gt;Tip 4 - Disable rules you really disagree to&lt;/h3&gt;
&lt;p&gt;Rules you really don&amp;#39;t want to check can be disabled using the StyleCopSettingsEditor. How this can be done is explained in &lt;a target="_blank" href="http://bloggingabout.net/blogs/jschreuder/archive/2008/07/29/have-your-c-coding-style-analysed-by-microsoft-part-2.aspx"&gt;this blog post&lt;/a&gt;. I disabled a number of them. I also included a number of overrides to the check for hungarian notation. For example, I have boolean variable names&amp;nbsp;like isValid and isCompliant. StyleCop used to warn me about using hungarian notation in these cases, whereas I&amp;#39;m not. You can add the &amp;#39;&lt;strong&gt;is&amp;#39;&lt;/strong&gt; part in the Hungarian tab of the StyleCopSettingsEditor and it will no longer warn you about this.&lt;/p&gt;
&lt;h3&gt;Tip 5 - Re-Align the source before you start&lt;/h3&gt;
&lt;p&gt;Select all the code using Ctrl-A, then press Ctrl-K followed by F. Visual Studio will re-align much of the code. This automatically eliminates a number of errors found by StyleCop.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=472229" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/.Net+Do_2700_s+_2600_amp_3B00_+Don_2700_ts/default.aspx">.Net Do's &amp;amp; Don'ts</category></item><item><title>Version 4.3 of Microsoft StyleCop available</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/08/21/new-version-of-microsoft-stylecop-available.aspx</link><pubDate>Thu, 21 Aug 2008 06:45:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:472227</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=472227</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2008/08/21/new-version-of-microsoft-stylecop-available.aspx#comments</comments><description>&lt;p&gt;A new version of &lt;a target="_blank" href="http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sourceanalysis&amp;amp;ReleaseId=1425"&gt;StyleCop&lt;/a&gt;&amp;nbsp;was made available only a few days ago, so I downloaded it and installed it. One thing I had to correct after installation was the Settings.SourceAnalysis file. Because of the name change to StyleCop, the extension of the settings file was also changed. But after that, I was back in business. One of the first things you notice is that the results are now shown as warnings in the standard errors and warnings list. And there are more changes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A separate help file is available that explains the rules and shows how violations can be solved&lt;/li&gt;
&lt;li&gt;A number of bug have been fixed&lt;/li&gt;
&lt;li&gt;New rules, including a rule to check if Using directives are sorted, in line with the Visual Studio 2008 Organize Usings functionality&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Another announcement on the &lt;a target="_blank" href="http://blogs.msdn.com/sourceanalysis/"&gt;StyleCop Teamblog&lt;/a&gt; suggested that they will be releasing SDK documentation to allow you to add your own rules to the tool. This is of course interesting if you have additional rules on top of the ones already available.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been using the tool for some weeks now and I really like the consistency in code style which is now slowly emerging in my projects. Where I thought I was using a consistent style in my own code, I was pointed out by StyleCop that in fact I wasn&amp;#39;t. But that&amp;#39;s all changing now.&lt;/p&gt;
&lt;p&gt;You can &lt;a target="_blank" href="http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sourceanalysis&amp;amp;ReleaseId=1425"&gt;download the new version of StyleCop here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=472227" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Tools/default.aspx">Tools</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/.Net+Do_2700_s+_2600_amp_3B00_+Don_2700_ts/default.aspx">.Net Do's &amp;amp; Don'ts</category></item><item><title>Have your C# coding style analysed by Microsoft, part 2</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/07/29/have-your-c-coding-style-analysed-by-microsoft-part-2.aspx</link><pubDate>Tue, 29 Jul 2008 13:21:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:469818</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=469818</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2008/07/29/have-your-c-coding-style-analysed-by-microsoft-part-2.aspx#comments</comments><description>&lt;p&gt;Just as a small update on the use of &lt;a target="_blank" href="http://blogs.msdn.com/sourceanalysis"&gt;&lt;span style="color:#006ff7;"&gt;StyleCop&lt;/span&gt;&lt;/a&gt;. I disagreed with some of the rules, like having to use spaces rather than tabs. It&amp;#39;s not really an annoying rule, the only thing about it is that you have to agree on using spaces or tabs and then stick to it.&lt;/p&gt;
&lt;p&gt;But still, I found out you can tune StyleCop to your needs. When you go the folder where the application is installed (on my machine C:\Program Files\Microsoft StyleCop 4.3) you will see a small application named StyleCopSettingsEditor.exe. Using that tool you can switch the rules supplied by the tool on or off. From a command prompt simply run the following command line:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div style="font-size:9pt;background:#f5f5f5;overflow:auto;width:100%;color:black;font-family:Courier New;border:#cccccc 1pt solid;padding:1pt;"&gt;
&lt;pre style="margin:0px;"&gt;StyleCopSettingsEditor.exe Settings.StyleCop&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You will then see the following user interface:&lt;/p&gt;
&lt;p&gt;&lt;img width="555" src="http://bloggingabout.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/jschreuder/StyleCop.jpg" height="575" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Using this interface, you can simply select which rules are appropriate in your projects.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=469818" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Tools/default.aspx">Tools</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/General/default.aspx">General</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Coding standards, Coding rules, Coding guidelines, etc...</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/07/25/coding-standards-coding-rules-coding-guidelines-etc.aspx</link><pubDate>Fri, 25 Jul 2008 20:11:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:469610</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=469610</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2008/07/25/coding-standards-coding-rules-coding-guidelines-etc.aspx#comments</comments><description>&lt;p&gt;If there&amp;#39;s one thing that developers usually just cannot (or will not) agree to, then it&amp;#39;s Coding standards/rules/guidelines or whatever name you want to give it. I posted a &lt;a target="_blank" href="http://bloggingabout.net/blogs/jschreuder/archive/2008/07/25/have-your-c-coding-style-analysed-by-microsoft.aspx"&gt;short item about a new tool from Microsoft&lt;/a&gt; that checks if your code matches the Microsoft guidelines and sure enough, I&amp;#39;m already getting mails on the subject explaining that Microsoft&amp;#39;s rules suck and that they use one that&amp;#39;s better. I thought it might just be a great subject for a discussion. But let me share my views on the subject first.&lt;/p&gt;
&lt;h3&gt;Coding standards, my view&lt;/h3&gt;
&lt;p&gt;I&amp;#39;ve been working as a developer in various roles and projects now for over 20 years. Yes, I&amp;#39;m that old, but it&amp;#39;s to show that I speak from experience on this subject. Each project I worked on has had one or another form of coding guidelines or standards. In one project, they even called it a coding convention in an attempt to make it more important. My reaction in most occasions was: &amp;quot;What ever...&amp;quot;&lt;/p&gt;
&lt;p&gt;The thing with this subject is, that developers simply cannot agree to one single guideline. Every developer thinks he/she is the best in his/her area and therefor the expert to tell others how to write their code. Well, they&amp;#39;re wrong.&lt;/p&gt;
&lt;p&gt;A coding standard is as good as the method to enforce it. If it&amp;#39;s not enforced, then it&amp;#39;s useless. And in 99% of all projects you will see that coding standards are not enforced. In my view, the only standard that works is the standard that you can enforce using tools. The guidelines checked by Microsoft&amp;#39;s FxCop are a good example. It always uses the same rules for all code and always warns in the same way. There are other tools that do that as well, like DevPartner from Compuware. You can agree to those rules or not, but at least it leaves little room for discussion and I see FxCop being more and more accepted.&lt;/p&gt;
&lt;p&gt;And now there&amp;#39;s StyleCop. It checks your code against the coding rules as used at Microsoft development centers. Again, you can discuss if these rules are correct, but you get a tool that validates the code and tells you were you have strayed from the narrow path. My feeling is that although I don&amp;#39;t entire agree to all rules, at least I can force my team to stick to these rules. Simply by breaking the build if they don&amp;#39;t comply to the coding rules.&lt;/p&gt;
&lt;p&gt;There are tools that allow you to write your own custom rules, like ReSharper and DevPartner. Useful as this can be, what do you do with code generated by Microsoft code generators. Think only of generated code for DataSet objects and WinForms. It&amp;#39;s highly unlikely that this code will adhere to your guidelines. But will the use the Microsoft guidelines? It&amp;#39;s a better bet then with your custom rules.&lt;/p&gt;
&lt;p&gt;Another misconception is that these rules improve the quality. But to be frank, this is mostly bullshit. The rules checked by FxCop (and similar tools) check for code quality with respect to the use of the .Net framework. StyleCop (and similar tools) check for style issues. But that does not improve code quality. That can only be achieved by testing your work and using defense programming techniques. But I digress.&lt;/p&gt;
&lt;p&gt;So whatever suits you, I guess. I&amp;#39;ll stick to using the Microsoft Guidelines and use their tools to check if I&amp;#39;ve done it right. But whatever coding standard you choose, make sure your entire team sticks to those rules, otherwise they&amp;#39;re completely useless. Unless it&amp;#39;s to satisfy management that you thought about code quality.&lt;/p&gt;
&lt;p&gt;But please, feel free to comment. I will approve them as soon as possible, but with the weekend starting in the Netherlands it might take some time. But I&amp;#39;d love to hear how the community feels about coding standards, the new Microsoft tool, and other things regarding this subject.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=469610" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Tools/default.aspx">Tools</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Have your C# coding style analysed by Microsoft!</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2008/07/25/have-your-c-coding-style-analysed-by-microsoft.aspx</link><pubDate>Fri, 25 Jul 2008 07:58:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:469572</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=469572</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2008/07/25/have-your-c-coding-style-analysed-by-microsoft.aspx#comments</comments><description>&lt;p&gt;Or to be more specific, by Microsoft &lt;a target="_blank" href="http://blogs.msdn.com/sourceanalysis"&gt;StyleCop&lt;/a&gt;. Now this may not be new to you, and that&amp;#39;s very likely since StyleCop was announced in May of this year, but it was new to me. &lt;/p&gt;
&lt;p&gt;The tool checks your code for coding style and more specific, the Microsoft coding style. It was developed outside the VSTS team and has absolutely no connections to &lt;a target="_blank" href="http://www.codeproject.com/KB/cs/CrystalHelper.aspx"&gt;FxCop&lt;/a&gt;. FxCop focusses on .Net Framework standards and correct use, StyleCop focuss on the way your code looks. Among others, it checks your code for the following items:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Layout of elements, statements, expressions, and query clauses &lt;/li&gt;
&lt;li&gt;Placement of curly brackets, parenthesis, square brackets, etc &lt;/li&gt;
&lt;li&gt;Spacing around keywords and operator symbols &lt;/li&gt;
&lt;li&gt;Line spacing &lt;/li&gt;
&lt;li&gt;Placement of method parameters within method declarations or method calls &lt;/li&gt;
&lt;li&gt;Standard ordering of elements within a class &lt;/li&gt;
&lt;li&gt;Formatting of documentation within element headers and file headers &lt;/li&gt;
&lt;li&gt;Naming of elements, fields and variables &lt;/li&gt;
&lt;li&gt;Use of the built-in types &lt;/li&gt;
&lt;li&gt;Use of access modifiers &lt;/li&gt;
&lt;li&gt;Allowed contents of files &lt;/li&gt;
&lt;li&gt;Debugging text&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The idea behind StyleCop, as can be read on their teamblog: &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The ultimate goal of StyleCop is to allow you to produce elegant, consistent code that your team members and others who view your code will find highly readable. In order to accomplish this, StyleCop does not allow its rules to be very configurable. StyleCop takes a one-size-fits-all approach to code style, layout, and readability rules. It is highly likely that you will not agree with all of the rules and may even find some of the rules annoying at first!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I downloaded the tool (&lt;a target="_blank" href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sourceanalysis"&gt;click here&lt;/a&gt;) and installed it to test drive it on &lt;a target="_blank" href="http://www.codeproject.com/KB/cs/CrystalHelper.aspx"&gt;my CrystalHelper class&lt;/a&gt;, and boy are they right. Some of those rules are annoying. I previously checked that class with FxCop and got little to comments there. From people that used the code, I always received comments that is was readable, easy to comprehend, etc. Then again, those differences make sense. FxCop looks at usage of the .Net Framework and does so by analyzing the compiled binaries. StyleCop uses the actual code. But let me give you some examples of what StyleCop has to say about my code. &lt;/p&gt;
&lt;h3&gt;Running StyleCop&lt;/h3&gt;
&lt;p&gt;The first thing I noticed when I ran StyleCop (or Source Analysis as it&amp;#39;s called in the menu) is the enormous amount of comments. My first reaction was to remove the tool and forget about it. Actually, I had the same reaction when I first ran FxCop. I was curious enough to continue though, so let&amp;#39;s look at what the tool had to say about the following code segment.&lt;/p&gt;
&lt;div style="border-right:#cccccc 1pt solid;padding-right:1pt;border-top:#cccccc 1pt solid;padding-left:1pt;font-size:9pt;background:#f5f5f5;padding-bottom:1pt;overflow:auto;border-left:#cccccc 1pt solid;width:100%;color:black;padding-top:1pt;border-bottom:#cccccc 1pt solid;font-family:Courier New;"&gt;







&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 489&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#808080;"&gt; &amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 490&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; Gets or sets the data source.&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 491&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#808080;"&gt; &amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 492&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#808080;"&gt; &amp;lt;value&amp;gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;The data source.&lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 493&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;DataSet&lt;/span&gt; DataSource&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 494&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 495&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 496&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 497&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _reportDataSource;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 498&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 499&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 500&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 501&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_reportDataSource != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;) &lt;span style="color:#2b91af;"&gt;&lt;/span&gt;_reportDataSource.Dispose();&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 502&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 503&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _reportDataSource = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 504&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 505&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &lt;/div&gt;
&lt;p&gt;Here we have 16 lines of code which most C# developers will accept as properly styled. StyleCop however gave me remarks about almost every line of code code:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tabs are not allowed. Uses spaces instead. On almost every line.&lt;/li&gt;
&lt;li&gt;The call to _reportData must begin with the &amp;#39;this.&amp;#39; prefix to indicate that the item is a member of the class. On lines 497, 501, 502 and 504.&lt;/li&gt;
&lt;li&gt;Statements or elements wrapped in curly brackets must be followed by a blank line. On line 498.&lt;/li&gt;
&lt;li&gt;The body of the if statement must be wrapped in opening and closing curly brackets. On line 501.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In addition to this, it also mentioned that the fieldname should not start with an underscore. This was a remark abou the _dataSource class variable I use in this property code. For this section of code, I received a total of 23 comments!&lt;/p&gt;
&lt;h3&gt;Changing the code to satisfy the tool&lt;/h3&gt;
&lt;p&gt;As I said, most C# developers will not really have a problem with the coding style used in the above segment. But apparently, this is totally unacceptable for Microsoft developers. My next step was to change the above code so that the tool would not complain about this code. And this is what it looks like after those changes: &lt;/p&gt;
&lt;div style="border-right:#cccccc 1pt solid;padding-right:1pt;border-top:#cccccc 1pt solid;padding-left:1pt;font-size:9pt;background:#f5f5f5;padding-bottom:1pt;overflow:auto;border-left:#cccccc 1pt solid;width:100%;color:black;padding-top:1pt;border-bottom:#cccccc 1pt solid;font-family:Courier New;"&gt;







&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 489&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#808080;"&gt; &amp;lt;summary&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 490&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; Gets or sets the data source.&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 491&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#808080;"&gt; &amp;lt;/summary&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 492&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#808080;"&gt; &amp;lt;value&amp;gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;The data source.&lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 493&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;DataSet&lt;/span&gt; DataSource&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 494&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 495&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 496&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 497&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.ReportDataSource;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 498&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 499&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 500&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 501&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 502&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.ReportDataSource != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 503&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 504&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.ReportDataSource.Dispose();&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 505&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 506&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 507&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.ReportDataSource = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;;&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 508&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;&amp;nbsp; 509&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &lt;/div&gt;
&lt;p&gt;All tabs are now replaced with spaces. The body if the if statement is now enclosed in brackets. There&amp;#39;s an empty line after the closing brackets for the get body and the if body. All class members are now preceded by &amp;#39;this.&amp;#39;. And yes, I removed the underscore from the class member. Not that much different, but some of the changes make sense, I guess.&lt;/p&gt;
&lt;h3&gt;Other comments found by the tool&lt;/h3&gt;
&lt;p&gt;The tool does find other things as well. Here&amp;#39;s a short list of some other comments the tool made about my CrystalHelper class:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Invalid spacing around the comma. All comma&amp;#39;s should be followed by a single space&lt;/li&gt;
&lt;li&gt;Invalid spacing around the opening parenthesis. There should not be a single space after an opening parenthesis&lt;/li&gt;
&lt;li&gt;Invalid spacing around the closing parenthesis. There should not be a single space before a closing parenthesis&lt;/li&gt;
&lt;li&gt;The spacing around the symbol &amp;#39;=&amp;#39; is invalid. You need to add a single space before and after the &amp;#39;=&amp;#39;symbol&lt;/li&gt;
&lt;li&gt;All using directives must be placed inside of the namespace&lt;/li&gt;
&lt;li&gt;All methods must be placed after all constructors&lt;/li&gt;
&lt;li&gt;All methods must be placed after all properties&lt;/li&gt;
&lt;li&gt;All private methods must be placed after all protected methods&lt;/li&gt;
&lt;li&gt;All private methods must be placed after all public methods&lt;/li&gt;
&lt;li&gt;All protected constructors must be placed after all public constructors&lt;/li&gt;
&lt;li&gt;The method must have a documentation header&lt;/li&gt;
&lt;li&gt;The summary section in the documentation header must not be empty&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Should you use it?&lt;/h3&gt;
&lt;p&gt;A difficult question. My first reaction, as I said before, was to remove the tool and forget about it. But that was the same reaction I had when I first started using FxCop. And yet, that is now a tool I use on a daily basis. &lt;/p&gt;
&lt;p&gt;I also have a problem with non-enforceable coding standards. Put 10 developers in a room to talk about coding standards and you end up with either 10 slightly different versions, or one that none of them will adhere to. My experience over the last 20 years is that, if you can&amp;#39;t enforce coding standards, you can forget about introducing them and hope that it will all go well.&lt;/p&gt;
&lt;p&gt;And that&amp;#39;s exactly where this tool comes in. You can now enforce a number of rules to make code more readable and understandable. You might want to disagree to some of them (I don&amp;#39;t agree to using spaces instead of tabs) but you can run the tool and check if your coding style matches that of the tool. And when all developers in your team use the tool and change their code accordingly, then all your code looks quite similar. Making it easier for your teammembers to work on code by other developers. And that&amp;#39;s the main objective for any development team to create a coding standard. &lt;/p&gt;
&lt;p&gt;The tool can also be included in MS-Build scripts, so you can easily make sure the build is broken when a developer ignores the coding standard. &lt;strong&gt;So yes, use it!&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;Some tips when using StyleCop&lt;/h3&gt;
&lt;p&gt;Once you have installed the tool and are ready to check your code using the tool, you might want to consider doing the following first:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Go to the C# section in Tools -&amp;gt; Options -&amp;gt; TextEditor and change the properties for the tabs so that it inserts spaces and click the OK button&lt;/li&gt;
&lt;li&gt;Open the class file and select all code using CTRL-A&lt;/li&gt;
&lt;li&gt;Now hold the CTRL key and press K, followed by F. This automatically re-aligns the entire class and replaces any tabs in your code with spaces. Do this for all class files in your project.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When you do this, the following will happen in your code.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tabs are converted into spaces&lt;/li&gt;
&lt;li&gt;Spacing before and after open and closing parenthesis is adjusted&lt;/li&gt;
&lt;li&gt;Spacing around symbols is adjusted&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;StyleCop will not give yo any comments about those items. Which leaves the more interesting items to fix.&lt;/p&gt;
&lt;h3&gt;What&amp;#39;s next for StyleCop?&lt;/h3&gt;
&lt;p&gt;Like all Microsoft tools, this is a work in progress. New features and options will be added and bugs will be fixed. But for the near future, the following has already been announced:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The tool is still called Source Analysis when you look for it in the Tools menu. It will be renamed to StyleCop&lt;/li&gt;
&lt;li&gt;A small SDK will be made available to allow you to extend the tool with your own rules&lt;/li&gt;
&lt;li&gt;Documentation about the currently available rules (which in fact opens up the Microsoft C# coding standards to the community)&lt;/li&gt;
&lt;li&gt;Automatically change your code to enforce some of the rules&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So keep an eye on the &lt;a target="_blank" href="http://blogs.msdn.com/sourceanalysis/"&gt;StyleCop blog&lt;/a&gt; for future releases of this tool. I will be discussing the tool with my team as soon as possible and start using it. Finally a way to have our code look similar!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=469572" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Tools/default.aspx">Tools</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/General/default.aspx">General</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Articles/default.aspx">Articles</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>What FxCop rules do Microsoft have turned on internally?</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/12/what-fxcop-rules-do-microsoft-have-turned-on-internally.aspx</link><pubDate>Fri, 12 Oct 2007 07:06:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:393413</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=393413</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/12/what-fxcop-rules-do-microsoft-have-turned-on-internally.aspx#comments</comments><description>&lt;p&gt;Ever wondered if Microsoft use FxCop themselves, and which rules they have turned on? Well, the Visual Studio Code Analysis Team Blog gives you the answer. If you &lt;a class="" href="http://blogs.msdn.com/fxcop/archive/2007/08/09/what-rules-do-microsoft-have-turned-on-internally.aspx" target="_blank"&gt;click this link&lt;/a&gt;, you will find a complete list of rules Microsoft use when analysing their code with FxCop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=393413" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Tools/default.aspx">Tools</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category></item><item><title>FxCop 1.36 Beta available for download</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/11/fxcop-1-36-beta-available-for-download.aspx</link><pubDate>Thu, 11 Oct 2007 14:22:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:392656</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=392656</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/11/fxcop-1-36-beta-available-for-download.aspx#comments</comments><description>&lt;p&gt;The &lt;a class="" href="http://blogs.msdn.com/fxcop" target="_blank"&gt;Visual Studio Code Analysis Team Blog&lt;/a&gt;&amp;nbsp;announces the release of FxCop 1.36 Beta.This new version contains the following (taken from the original &lt;a class="" href="http://blogs.msdn.com/fxcop/archive/2007/10/10/fxcop-1-36-beta-released.aspx" target="_blank"&gt;post&lt;/a&gt;):&lt;/p&gt;
&lt;blockquote&gt;
&lt;li&gt;200+ bug fixes that reduce noise, missing analysis and rule crashes 
&lt;li&gt;Support for &lt;a class="" href="http://blogs.msdn.com/fxcop/archive/2007/09/21/new-for-visual-studio-2008-support-for-anonymous-methods-and-lambda-expressions.aspx" target="_blank"&gt;analyzing anonymous methods and lambda expressions&lt;/a&gt; 
&lt;li&gt;New option for skipping analysis over tool generated code 
&lt;li&gt;Better support for C++/CLI and the Compact Framework 
&lt;li&gt;Language &amp;#39;friendly&amp;#39; API names in the UI and resolutions (ie Visual Basic syntax if running over a Visual Basic binary) 
&lt;li&gt;New globalization, design and usage rules 
&lt;li&gt;Performance improvements that cut analysis by 2x and use half as much memory 
&lt;li&gt;Documentation that is &lt;a class="" href="http://msdn2.microsoft.com/en-us/library/bb429476(VS.80).aspx" target="_blank"&gt;now available on MSDN&lt;/a&gt; &lt;/li&gt;&lt;/blockquote&gt;
&lt;p&gt;You can &lt;a class="" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=3389f7e4-0e55-4a4d-bc74-4aeabb17997b&amp;amp;displaylang=en" target="_blank"&gt;download it&lt;/a&gt;&amp;nbsp;here!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=392656" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Tools/default.aspx">Tools</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category></item><item><title>Another "What the F**K" moment</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/02/another-quot-what-the-f-k-quot-moment.aspx</link><pubDate>Tue, 02 Oct 2007 09:40:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:382658</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=382658</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/02/another-quot-what-the-f-k-quot-moment.aspx#comments</comments><description>&lt;p&gt;I tried compiling my application just now and got this error message from the compiler:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;Preparing resources...&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;Updating references...&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;Performing main compilation...&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;error CS0583: Internal Compiler Error (0xc0000005 at address 77FCD43E): likely culprit is &amp;#39;PARSE&amp;#39;.&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;An internal error has occurred in the compiler. To work around this problem, try simplifying or &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;changing the program near the locations listed below. Locations at the top of the list are closer &lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;to the point at which the internal error occurred.&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;c:\inetpub\wwwroot\Intra\Hierarchy.aspx.cs: error CS0586: Internal Compiler Error: stage &amp;#39;PARSE&amp;#39;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;error CS0587: Internal Compiler Error: stage &amp;#39;PARSE&amp;#39;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;error CS0587: Internal Compiler Error: stage &amp;#39;BEGIN&amp;#39;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Excuse me?!?!?! The last time I ever received errors like this was in 1996, while building applications for good-old MS-Dos. The Microsoft C compiler in some cases could not parse the code and presented you with a &amp;quot;Too complex&amp;quot; error. The only way around this was to re-order the code. But in the .Net age I never came across this error. Until now that is.&lt;/p&gt;
&lt;p&gt;And what&amp;#39;s even stranger is that a rebuild of the app solved the problem. I&amp;#39;m lost. Any one out there has any experience with this error?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=382658" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+Samples/default.aspx">Code Samples</category></item><item><title>What the F**K is the 'Grady' operator</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/01/what-the-f-k-is-the-grady-operator.aspx</link><pubDate>Mon, 01 Oct 2007 13:31:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:382015</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=382015</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2007/10/01/what-the-f-k-is-the-grady-operator.aspx#comments</comments><description>&lt;p&gt;The web application I&amp;#39;m working on logs errors in a log file using Log4Net. Nothing new, loads of applications do that. But I was surprised when I found the following error message:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;System.Data.SyntaxErrorException: Syntax error: Missing operand after &amp;#39;grady&amp;#39; operator.&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now what in heavens name is a &amp;#39;Grady&amp;#39; operator. I had no clue. Google only knows Grady from the book &amp;quot;&lt;em&gt;&lt;a class="" title="http://www.amazon.com/Object-Oriented-Analysis-Design-Applications-3rd/dp/020189551X/ref=pd_bbs_sr_1/002-7242484-6456822?ie=UTF8&amp;amp;s=books&amp;amp;qid=1191245720&amp;amp;sr=8-1" target="_blank"&gt;Object-Oriented Analysis And Design With Applications&lt;/a&gt;&lt;/em&gt;&amp;quot; and other OO related work. So no solution to be found there. So what could it be?&lt;/p&gt;
&lt;p&gt;I looked into the log file again and checked if the exception was raised more than once. I found more interesting &amp;#39;operators&amp;#39;: &amp;#39;Toole&amp;#39;, &amp;#39;Amore&amp;#39;,&amp;#39;Sullivan&amp;#39;. Wait a minute there all names. I checked the stack traces for these exceptions and then it dawned on me. The error was raised when the user clicked a filter button. The web page where the error was raised showed a user list. Apparently, the user was looking for someone named O&amp;#39;Toole or O&amp;#39;Sullivan. I checked the code and found this:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (txtUserFilter.Text != String.Empty)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataTable.DefaultView.RowFilter = &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;.Format(&amp;quot;NAME like &amp;#39;%{0}%&amp;#39;&amp;quot;, txtUserFilter.Text);&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will work fine of course, provided the text string does not contain any single quotes. The following solved my problem:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#cccccc 1pt solid;PADDING-RIGHT:1pt;BORDER-TOP:#cccccc 1pt solid;PADDING-LEFT:1pt;FONT-SIZE:9pt;BACKGROUND:#f5f5f5;PADDING-BOTTOM:1pt;OVERFLOW:auto;BORDER-LEFT:#cccccc 1pt solid;WIDTH:100%;COLOR:black;PADDING-TOP:1pt;BORDER-BOTTOM:#cccccc 1pt solid;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;if&lt;/span&gt;(txtUserFilter.Text != String.Empty)&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataTable.DefaultView.RowFilter = &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;.Format(&amp;quot;NAME like &amp;#39;%{0}%&amp;#39;&amp;quot;, txtUserFilter.Text.Replace(&amp;quot;&amp;#39;&amp;quot;, &amp;quot;&amp;#39;&amp;#39;&amp;quot;));&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=382015" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+Samples/default.aspx">Code Samples</category></item><item><title>Code inspections - Why and how to conduct them</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2006/10/10/Code-inspection-_2D00_-Why-and-how-to-conduct-them.aspx</link><pubDate>Tue, 10 Oct 2006 12:00:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:28985</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=28985</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2006/10/10/Code-inspection-_2D00_-Why-and-how-to-conduct-them.aspx#comments</comments><description>Triggered by a request from one of my colleagues, I decided to blog about why I think code inspections are useful and how they might be conducted. ...(&lt;a href="http://bloggingabout.net/blogs/jschreuder/archive/2006/10/10/Code-inspection-_2D00_-Why-and-how-to-conduct-them.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=28985" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Articles/default.aspx">Articles</category></item><item><title>Running FxCop on VB.net can be very annoying</title><link>http://bloggingabout.net/blogs/jschreuder/archive/2006/08/31/Running-FxCop-on-VB.net-can-be-very-annoying.aspx</link><pubDate>Thu, 31 Aug 2006 03:35:45 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:17982</guid><dc:creator>Jan Schreuder</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/jschreuder/rsscomments.aspx?PostID=17982</wfw:commentRss><comments>http://bloggingabout.net/blogs/jschreuder/archive/2006/08/31/Running-FxCop-on-VB.net-can-be-very-annoying.aspx#comments</comments><description>&lt;p&gt;I built a very small application which only shows information from a table in a standard DataGrid. Nothing special, other than I had to do it in VB.Net 1.1. I have just finished testing it, and am now running FxCop on the code to see what problems I still have to fix before checking it into source safe.&lt;/p&gt; &lt;p&gt;The code contains a DataGridTextBoxColumn class which inherits from &lt;a href="http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridtextboxcolumn.aspx" target="_blank"&gt;System.Windows.Forms.DataGridTextBoxColumn&lt;/a&gt;. Again, nothing particularly special. I override the Edit method to make sure no one gets to edit the line like this:&lt;/p&gt; &lt;div style="border-right:#cccccc 1pt solid;padding-right:1pt;border-top:#cccccc 1pt solid;padding-left:1pt;font-size:9pt;background:#f5f5f5;padding-bottom:1pt;overflow:auto;border-left:#cccccc 1pt solid;width:100%;color:black;padding-top:1pt;border-bottom:#cccccc 1pt solid;font-family:courier new;height:76px;"&gt;&lt;pre style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;Protected&lt;/span&gt; &lt;span style="color:blue;"&gt;Overloads&lt;/span&gt; &lt;span style="color:blue;"&gt;Overrides&lt;/span&gt; &lt;span style="color:blue;"&gt;Sub&lt;/span&gt; Edit(&lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; source &lt;span style="color:blue;"&gt;As&lt;/span&gt; System.Windows.Forms.CurrencyManager, &lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; rowNum &lt;span style="color:blue;"&gt;As&lt;/span&gt; &lt;span style="color:blue;"&gt;Integer&lt;/span&gt;, &lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; bounds &lt;span style="color:blue;"&gt;As&lt;/span&gt; System.Drawing.Rectangle, _&lt;/pre&gt;&lt;pre style="margin:0px;"&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 style="color:blue;"&gt;ByVal&lt;/span&gt; isReadOnly &lt;span style="color:blue;"&gt;As&lt;/span&gt; &lt;span style="color:blue;"&gt;Boolean&lt;/span&gt;, &lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; instantText &lt;span style="color:blue;"&gt;As&lt;/span&gt; &lt;span style="color:blue;"&gt;String&lt;/span&gt;, &lt;span style="color:blue;"&gt;ByVal&lt;/span&gt; cellIsVisible &lt;span style="color:blue;"&gt;As&lt;/span&gt; &lt;span style="color:blue;"&gt;Boolean&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; isReadOnly = &lt;span style="color:blue;"&gt;True&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;End&lt;/span&gt; &lt;span style="color:blue;"&gt;Sub&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;FxCop tells me the following about this method:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"Change parameter name 'isReadOnly' of method DataGridTextBoxColumn.Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean):Void to 'readOnly' in order to match the identifier as it has been declared in DataGridColumnStyle.Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean):Void."&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Now I'm used to doing that in C#. No problem there. But when you do that in VB.Net, guess what:&lt;/p&gt;
&lt;div style="border-right:#cccccc 1pt solid;padding-right:1pt;border-top:#cccccc 1pt solid;padding-left:1pt;font-size:9pt;background:#f5f5f5;padding-bottom:1pt;overflow:auto;border-left:#cccccc 1pt solid;width:100%;color:black;padding-top:1pt;border-bottom:#cccccc 1pt solid;font-family:courier new;"&gt;&lt;pre style="margin:0px;"&gt;C:\Projects\LogViewer\1.0\Helpers\DataGridTextBoxColumn.vb(22) : &lt;/pre&gt;&lt;pre style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  error &lt;font color="#000000"&gt;BC30284: sub 'Edit' cannot be declared 'Overrides' because it does not override a sub in a base class.&lt;/font&gt;&lt;/pre&gt;&lt;pre style="margin:0px;"&gt;C:\Projects\LogViewer\1.0\Helpers\DataGridTextBoxColumn.vb(23) : &lt;/pre&gt;&lt;pre style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  error &lt;font color="#000000"&gt;BC30181: Specifiers valid only at the beginning of a declaration.&lt;/font&gt;&lt;/pre&gt;&lt;pre style="margin:0px;"&gt;C:\Projects\LogViewer\1.0\Helpers\DataGridTextBoxColumn.vb(24) : &lt;/pre&gt;&lt;pre style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  error &lt;font color="#000000"&gt;BC30203: Identifier expected.&lt;/font&gt;&lt;/pre&gt;&lt;pre style="margin:0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Great huh, three compiler errors for the price of one! Makes sense of course, as ReadOnly is a VB.Net keyword to indicate a property is read-only and VB.Net is case insensitive.&amp;nbsp;But it's behavior like this that can stop people from using FxCop. And that's a pity, because on other issues the remarks made by FxCop are valid.&lt;/p&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=17982" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Tools/default.aspx">Tools</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/General/default.aspx">General</category><category domain="http://bloggingabout.net/blogs/jschreuder/archive/tags/Code+inspections/default.aspx">Code inspections</category></item></channel></rss>