<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JAPF &#187; practises</title>
	<atom:link href="http://www.japf.fr/tag/practises/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.japf.fr</link>
	<description>Jeremy Alles Presentation Foundation: WPF, .Net and modern software development</description>
	<lastBuildDate>Thu, 29 Jul 2010 07:29:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to measure rendering time in a WPF application ?</title>
		<link>http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/</link>
		<comments>http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 10:47:20 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[practises]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=325</guid>
		<description><![CDATA[Last week, a colleague of mine asked me an interesting question: &#8220;I&#8217;m filling a control with content and I&#8217;d like to measure the time needed to render my control. How can I do that ?&#8221; The first approach is to measure the elapsed time needed to instantiate and populate the control from C# code. We [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, a colleague of mine asked me an interesting question: &#8220;<em>I&#8217;m filling a control with content and I&#8217;d like to measure the time needed to render my control. How can I do that ?&#8221;</em></p>
<p>The first approach is to measure the elapsed time needed to instantiate and populate the control from C# code. We can use the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx">StopWatch</a> class to have a precise and easy to use measuring tool.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p325code3'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3253"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p325code3"><pre class="csharp" style="font-family:monospace;">Stopwatch sw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Stopwatch<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">5000</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// here is the operation that fills the control</span>
  <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">canvas</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Rectangle<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
MessageBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Show</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Took &quot;</span> <span style="color: #008000;">+</span> sw<span style="color: #008000;">.</span><span style="color: #0000FF;">ElapsedMilliseconds</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; ms&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>However this approach will not give good results because we&#8217;re not taking into account the time needed to render elements in the visual tree. This is because elements are not rendered when you call the Add methods (for example in a Canvas) but when the visual tree is fully loaded.</p>
<p>A much better approach is to use the Dispatcher and request it to process an action at a priority right bellow the Render priority which is the Loaded priority:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2009/10/dispatcherpriority.png" rel="lightbox[325]"><img class="alignnone size-full wp-image-326" title="dispatcherpriority" src="http://www.japf.fr/wp-content/uploads/2009/10/dispatcherpriority.png" alt="dispatcherpriority" width="705" height="188" /></a></p>
<p>Using this trick, we ensure that all rendering actions have been completed. We can use the following code to do that:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p325code4'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3254"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p325code4"><pre class="csharp" style="font-family:monospace;">Stopwatch sw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Stopwatch<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">5000</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// here is the operation that fills the control</span>
  <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">canvas</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Rectangle<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Dispatcher</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BeginInvoke</span><span style="color: #008000;">&#40;</span>
  DispatcherPriority<span style="color: #008000;">.</span><span style="color: #0000FF;">Loaded</span>,
  <span style="color: #008000;">new</span> Action<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
  <span style="color: #008000;">&#123;</span>
    sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    MessageBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Show</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Took &quot;</span> <span style="color: #008000;">+</span> sw<span style="color: #008000;">.</span><span style="color: #0000FF;">ElapsedMilliseconds</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; ms&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Hope this helps !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Analyzing events usage using a R# plugin</title>
		<link>http://www.japf.fr/2009/10/analyzing-events-usage-using-a-resharper-plugin/</link>
		<comments>http://www.japf.fr/2009/10/analyzing-events-usage-using-a-resharper-plugin/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 12:20:47 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[practises]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[resharper]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=286</guid>
		<description><![CDATA[As you might already know, even if the .Net framework has a garbage collector, you can easily create memory leaks in your application. The most common way to create a leak is to register to an event handler on a object that has a longer lifetime than the object where the handler is defined. The [...]]]></description>
			<content:encoded><![CDATA[<p>As you might already know, even if the .Net framework has a garbage collector, you can easily create memory leaks in your application.</p>
<p>The most common way to create a leak is to register to an event handler on a object that has a longer lifetime than the object where the handler is defined. The problem can also occurs by using static class such as EventManager (for more information see <a href="http://www.japf.fr/2009/08/wpf-memory-leak-with-eventmanager-registerclasshandler/">this blog post</a>). Some .Net developers have been working on a way to go round the problem using Reflection, Weak Reference and other cool stuff. You can check out for example <a href="http://www.codeproject.com/KB/cs/WeakEvents.aspx">this excellent article</a> on Code Project.</p>
<p>However, if you cannot change the way your declare events (because of internal policies in the company or because you don&#8217;t have the source code), you must be very carefull about the way you manage your events.</p>
<p>I&#8217;ve been working lately on a <a href="http://www.jetbrains.com/resharper/index.html">Resharper</a> plugin that helps detecting events that are never unsubscribed. Basically, what is does is the following:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2009/10/resharper_plugin.png" rel="lightbox[286]"><img class="size-full wp-image-287 alignnone" title="resharper_plugin" src="http://www.japf.fr/wp-content/uploads/2009/10/resharper_plugin.png" alt="resharper_plugin" width="528" height="213" /></a></p>
<p><strong>I&#8217;d like to have feedback from you .Net developpers, about whether you find such a plugin useful or not. </strong></p>
<ul>
<li>How do you deal with the event memory leak problem ?</li>
<li>Would you like to use my plugin ?</li>
<li>Would you like me to release it on a open source platform ?</li>
<li>What other kind of possible leaks are you thinking about to enhance the plugin ?</li>
</ul>
<p>Please write a comment to let my know what you think. Thank you for your feedback !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/10/analyzing-events-usage-using-a-resharper-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>French article about MVVM posted !</title>
		<link>http://www.japf.fr/2009/03/french-article-about-mvvm-posted/</link>
		<comments>http://www.japf.fr/2009/03/french-article-about-mvvm-posted/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 06:45:16 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[model-view-viewmodel]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[practises]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=149</guid>
		<description><![CDATA[It&#8217;s finally online after a long work.I hope my french readers will enjoy it:  http://japf.developpez.com/tutoriels/dotnet/mvvm-pour-des-applications-wpf-bien-architecturees-et-testables/ Here is the abstract translated to english: &#8220;Inch by inch, the WPF technology is being adopted by .Net developers as a development platform for next generation user interfaces. This changeover is taking time and complicated because WPF changes principles that [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s finally online after a long work.I hope my french readers will enjoy it:  <a href="http://japf.developpez.com/tutoriels/dotnet/mvvm-pour-des-applications-wpf-bien-architecturees-et-testables/">http://japf.developpez.com/tutoriels/dotnet/mvvm-pour-des-applications-wpf-bien-architecturees-et-testables/</a></p>
<p>Here is the abstract translated to english:</p>
<p><em>&#8220;Inch by inch, the WPF technology is being adopted by .Net developers as a development platform for next generation user interfaces. This changeover is taking time and complicated because WPF changes principles that are well known until now in the process of designing a user interface. The Model-View-ViewModel methodology helps formalize WPF developement by giving guidance that leads to apps cleary architectured, testable, and by optimizing the workflow between developer and designer.&#8221;</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/03/french-article-about-mvvm-posted/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XAML guidelines: interviews of WPF masters</title>
		<link>http://www.japf.fr/2009/01/xaml-guidelines-interviews-from-wpf-masters/</link>
		<comments>http://www.japf.fr/2009/01/xaml-guidelines-interviews-from-wpf-masters/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 12:16:42 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[blend]]></category>
		<category><![CDATA[practises]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=101</guid>
		<description><![CDATA[Getting back to work this morning, I opened my Google Reader to have a look at the RSS feeds I’m reading. I found a nice video on Channel9: “XAML Guidelines, Part 2”. The first episode, where Jaime Rodriguez interviews 3 people from Identity Mines is also available on Channel9 (unfortunately, the sound is rather poor [...]]]></description>
			<content:encoded><![CDATA[<p>Getting back to work this morning, I opened my Google Reader to have a look at the RSS feeds I’m reading.</p>
<p>I found a nice video on Channel9: <a href="http://channel9.msdn.com/shows/Continuum/XAML-Guidelines-Part-2/">“XAML Guidelines, Part 2”</a>. <a href="http://channel9.msdn.com/shows/Continuum/XAML-Guidelines-Part-1/">The first episode</a>, where Jaime Rodriguez interviews 3 people from Identity Mines is also available on Channel9 (unfortunately, the sound is rather poor on this episode…).</p>
<p>This time, Jaime meets up with Unni Ravindranathan from the Expression Blend team. During the shot, they open the Blend source code project inside Blend (sounds nice isn’t it :p). Unni explains the structure of the project, their conventions, how resources are used, etc.</p>
<p>I think Blend is an application we can learn a lot from. If you’re also interested to understand what architecture Blend uses, you can check out <a href="http://www.paulstovell.com/blog/expression-framework-versus-composite-wpf">this post</a> from Paul Stovell.</p>
<p>Here are some notes I took while watching the video:</p>
<ul>
<li>Blend is shipped with 2 themes: Expression Light &amp; Expression Dark</li>
<li>Blend resources are stored in (only !) 3 resources dictionaries</li>
<li>Resources are categorized into Colors, Brushes and Styles</li>
<li>Blend defines a set of margins and thicknesses that are used in the entire application to ensure a consistency across the different layouts</li>
<li>By convention, Name and Key properties are always defined first in the XAML</li>
<li>Properties might be spitted over several lines, if this is the case; properties are grouped together by types (style, size, appearance…)</li>
<li>Blend 3 will add extensibility and improve XAML code generation:
<ul>- Name will always be the first property</ul>
<ul>- Better control over how the XAML is formatted</ul>
</li>
<li>Name everything versus name nothing? Blend names almost everything, it helps UI automation</li>
<li>Static resources versus dynamic resources? No big performance impact, Blend mostly uses dynamic resources</li>
<li>When design time doesn’t work fine in Blend
<ul>- An exception can occur when Blend is creating the control because the running process is Blend itself and not the application we are creating</ul>
<ul>- Add tests to check if code is running in design mode (you can use System.ComponentModel.DesignerProperties.GetIsInDesignMode(DependencyObject) method)</ul>
<ul>- Debug Blend process by attaching an instance of Visual Studio to Blend</ul>
</li>
<li>Blend is a big application:
<ul>- 300 000 lines of XAML</ul>
<ul>- 500 000 lines of C#</ul>
</li>
</ul>
<p>If you want more information about fixing error that we can have in Blend (while the application works properly at run time), you can check out <a href="http://blogs.msdn.com/jaimer/archive/2007/01/21/tweaking-your-wpf-code-to-run-in-expression-blend.aspx">this post</a> of Jaime.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/01/xaml-guidelines-interviews-from-wpf-masters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>StyleCop + Resharper = StyleCop for Resharper addin</title>
		<link>http://www.japf.fr/2008/11/stylecop-resharper-stylecop-for-resharper-addin/</link>
		<comments>http://www.japf.fr/2008/11/stylecop-resharper-stylecop-for-resharper-addin/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 09:22:30 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[practises]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[resharper]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=55</guid>
		<description><![CDATA[If you&#8217;re a .Net developper then you MUST use ReSharper. I you don&#8217;t, I suggest you to have a look at this very nice video demonstrating some of the feature of this Visual Studio addin. If you also like having a clean C# code, then you might also use Microsoft StyleCop tool. I just found [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a .Net developper then you <strong>MUST </strong>use ReSharper. I you don&#8217;t, I suggest you to have a look at <a href="http://www.dimecasts.net/Casts/CastDetails/61">this very nice video</a> demonstrating some of the feature of this Visual Studio addin. If you also like having a clean C# code, then you might also use <a href="http://code.msdn.microsoft.com/sourceanalysis">Microsoft StyleCop tool</a>.</p>
<p>I just found this a <a href="http://www.codeplex.com/StyleCopForReSharper">very cool Resharper</a> plugin that<span id="ctl00_ctl00_MasterContent_TabContentPanel_Content_wikiSourceLabel"> allows Microsoft StyleCop to be run as you type, generating real-time syntax highlighting of violations:</span></p>
<p><a href="http://www.japf.fr/wp-content/uploads/2008/11/stylecopresharper.png" rel="lightbox[55]"><img class="alignnone size-medium wp-image-56" title="stylecopresharper" src="http://www.japf.fr/wp-content/uploads/2008/11/stylecopresharper-300x231.png" alt="" width="397" height="305" /></a></p>
<p>The <a href="http://www.codeplex.com/StyleCopForReSharper">StyleCop for Resharper plugin</a> is hosted on <a href="http://www.codeplex.com">CodePlex</a> and is free. I think it&#8217;s a must have for any .Net developer. Its author really did a good work <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.japf.fr%2f%3fp%3d55"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.japf.fr%2f%3fp%3d55" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2008/11/stylecop-resharper-stylecop-for-resharper-addin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft StyleCop vs Agility</title>
		<link>http://www.japf.fr/2008/11/microsoft-stylecop-vs-agility/</link>
		<comments>http://www.japf.fr/2008/11/microsoft-stylecop-vs-agility/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 21:53:00 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[agility]]></category>
		<category><![CDATA[practises]]></category>
		<category><![CDATA[stylecop]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=53</guid>
		<description><![CDATA[When I write code, I try to keep it as clean as possible by following rules that I define and use in all my project. Those rules can be the ordering of elements within a class, or the way I choose name for my properties and methods&#8230; Microsoft created a tool that analyzes C# source [...]]]></description>
			<content:encoded><![CDATA[<p>When I write code, I try to keep it as clean as possible by following <em>rules </em>that I define and use in all my project. Those <em>rules</em> can be the ordering of elements within a class, or the way I choose name for my properties and methods&#8230;</p>
<p>Microsoft created a tool that <span id="ctl00_ctl00_Content_TabContentPanel_Content_wikiSourceLabel">analyzes C# source code in order to enforce a set of style and consistency rules : it&#8217;s <a href="http://code.msdn.microsoft.com/sourceanalysis">StyleCop</a> (available for free to download). StyleCop defines a lot of rules, for example:</span></p>
<ul>
<li>Element must begin with an upper case letter</li>
<li>Field name must begin with a lower case letter</li>
<li>Prefix local calls with the &#8220;this&#8221; prefix</li>
</ul>
<p>It is possible to enable or disable each rules separately, and this is what most users will do. Running StyleCop on one of your project can lead to thousands of warning. You can then choose which rules you want to keep enabled.</p>
<p>I started to use StyleCop the project I&#8217;m working on at job about one week ago. After disabling some of the rules I didn&#8217;t wanted to fix yet, I found a rules that was giving me a lot of warnings:</p>
<ul>
<li>ALL elements must be documented</li>
</ul>
<p>Hmm&#8230; This means that each single method or properties in my project must have a documentation&#8230; Well, if documentation is good lets start writing documentation everywhere. I though I will take a couple of classes per day, and write the entire documentation. I started with opening one of my class, and found this method:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p53code7'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p537"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p53code7"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OpenDocument<span style="color: #008000;">&#40;</span>IDocument document<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #008080; font-style: italic;">// ...</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>StyleCop wasn&#8217;t happy because there wasn&#8217;t any documentation, so I wrote one:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p53code8'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p538"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p53code8"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Open a document</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;document&quot;&gt;IDocument to open&lt;param&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OpenDocument<span style="color: #008000;">&#40;</span>IDocument document<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #008080; font-style: italic;">// ...</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Then, I don&#8217;t know why but I asked myself &#8220;what the hell this documentation is going to help the user of the class ???&#8221;. Because one month earlier I went to the <a href="http://www.agiletour.com/">AgileTour</a> (a french event about Agile methods), I remembered the <em>Agile Manifesto</em>:</p>
<ul>
<li>Individuals and interactions <em>over </em>processes and tools</li>
<li>Working software <em>over </em><strong>comprehensive documentation</strong></li>
<li>Customer collaboration <em>over </em>contract negotiation</li>
<li>Responding to change <em>over </em>following a plan</li>
</ul>
<p>I was thinking a couple of minutes, and then I decided to remove the StyleCop rules about documenting EVERYTHING in my code. I think that would be a waste of time and that would preventing me to put good comments where it&#8217;s really needed such explaning an algorithm or why I choose this way over this other way to do the job.</p>
<p>I&#8217;m still using StyleCop to have a set of rules about the style of my code. But for now, that&#8217;s it ! I think it is very important to make the differenciation between documentation and comments. If documentation is needed because it will generate a document outside the application then it might be usefull. But if the documentation is written just to have it, I prefer forget about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2008/11/microsoft-stylecop-vs-agility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
