<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Custom Control Development: Simple code guidelines</title>
	<atom:link href="http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/</link>
	<description>Silverlight, rich client apps and web development</description>
	<lastBuildDate>Fri, 30 Jul 2010 19:17:58 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Jeff Wilcox</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1693</link>
		<dc:creator>Jeff Wilcox</dc:creator>
		<pubDate>Thu, 24 Sep 2009 19:50:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1693</guid>
		<description>@Morten,
It&#039;s there - it just isn&#039;t visible in IntelliSense, thanks to the EditorBrowsable attribute with the Never state applied.</description>
		<content:encoded><![CDATA[<p>@Morten,<br />
It&#8217;s there &#8211; it just isn&#8217;t visible in IntelliSense, thanks to the EditorBrowsable attribute with the Never state applied.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morten</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1692</link>
		<dc:creator>Morten</dc:creator>
		<pubDate>Thu, 24 Sep 2009 19:39:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1692</guid>
		<description>Maybe it&#039;s just me, but I don&#039;t see a CheckAccess method in Silverlight. As far as I can tell, this is a WPF thing:
See:
http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher_members(VS.95).aspx
vs:
http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher_members.aspx</description>
		<content:encoded><![CDATA[<p>Maybe it&#8217;s just me, but I don&#8217;t see a CheckAccess method in Silverlight. As far as I can tell, this is a WPF thing:<br />
See:<br />
<a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher_members(VS.95).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher_members(VS.95).aspx</a><br />
vs:<br />
<a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher_members.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher_members.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexey Zakharov</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1577</link>
		<dc:creator>Alexey Zakharov</dc:creator>
		<pubDate>Fri, 28 Aug 2009 05:55:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1577</guid>
		<description>Hi,

Nice post. But I think that the most critical is control flexibility, customization and easy to use. So there should be some sort of guidelines declare rules to make control flexible, customizable and easy to use.

Let&#039;s take a look at DataForm control as an example:

1. Why dataform holds buttons (add,delete,next,prev) inside it? It is much more simpler to declare that buttons in view and have full control under them. Dataform take collection of items instead of single item. It is very easy to implement next and prev feature without build in support. All this make the control very complex. It has thousands of codelines. Is it easy to use? NOT!
2. Dataform hardcodes generated controls for displaying fields by their data type. What if I want to display datetime with TelerikCalendar? What if want to display int with Slider for propertyX and with textBox for propertyY? As a result form autogeneration is useless in most of cases.

Thanks,
Alexey Zakharov.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Nice post. But I think that the most critical is control flexibility, customization and easy to use. So there should be some sort of guidelines declare rules to make control flexible, customizable and easy to use.</p>
<p>Let&#8217;s take a look at DataForm control as an example:</p>
<p>1. Why dataform holds buttons (add,delete,next,prev) inside it? It is much more simpler to declare that buttons in view and have full control under them. Dataform take collection of items instead of single item. It is very easy to implement next and prev feature without build in support. All this make the control very complex. It has thousands of codelines. Is it easy to use? NOT!<br />
2. Dataform hardcodes generated controls for displaying fields by their data type. What if I want to display datetime with TelerikCalendar? What if want to display int with Slider for propertyX and with textBox for propertyY? As a result form autogeneration is useless in most of cases.</p>
<p>Thanks,<br />
Alexey Zakharov.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Roh</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1573</link>
		<dc:creator>David Roh</dc:creator>
		<pubDate>Thu, 27 Aug 2009 13:59:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1573</guid>
		<description>Thanks for the guidelines Jeff - I will certainly start using some of the ones that I have not been using.

I am all for any guideline that helps me to write more reliable and easier to maintain code.

One of the things that I do which I don&#039;t see many other developers doing is using prefixes to help identify a variables scope.  I love Intellisense; however, one simply does not mouse over ever variable while developing - it can be very easy to assume a variable has one scope when it actually has another which can be disastrous.

The specific method for indicating scope is a question of taste but I do think it is important to do - for example, some of the scope prefixes that I use are: m_ - fields, p_ - passed in parameters, s_ - statics, etc.

To me when I look at a variable I want to instantly be able to tell it&#039;s scope, it&#039;s type, and a clear description of it&#039;s purpose - yea, I know Intellisense will tell me a lot but like I said, we simply do not mouse over every variable and it is very easy to assume the wrong thing.

Anyway, it&#039;s just my style.

Thanks for the guidelines,
David</description>
		<content:encoded><![CDATA[<p>Thanks for the guidelines Jeff &#8211; I will certainly start using some of the ones that I have not been using.</p>
<p>I am all for any guideline that helps me to write more reliable and easier to maintain code.</p>
<p>One of the things that I do which I don&#8217;t see many other developers doing is using prefixes to help identify a variables scope.  I love Intellisense; however, one simply does not mouse over ever variable while developing &#8211; it can be very easy to assume a variable has one scope when it actually has another which can be disastrous.</p>
<p>The specific method for indicating scope is a question of taste but I do think it is important to do &#8211; for example, some of the scope prefixes that I use are: m_ &#8211; fields, p_ &#8211; passed in parameters, s_ &#8211; statics, etc.</p>
<p>To me when I look at a variable I want to instantly be able to tell it&#8217;s scope, it&#8217;s type, and a clear description of it&#8217;s purpose &#8211; yea, I know Intellisense will tell me a lot but like I said, we simply do not mouse over every variable and it is very easy to assume the wrong thing.</p>
<p>Anyway, it&#8217;s just my style.</p>
<p>Thanks for the guidelines,<br />
David</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Bugnion</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1572</link>
		<dc:creator>Laurent Bugnion</dc:creator>
		<pubDate>Thu, 27 Aug 2009 07:17:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1572</guid>
		<description>Hey Jeff,

Like I told you on Twitter, I cannot remember why I deactivated some of the rules, but left the &quot;this.&quot; rule. I am reconsidering this.

For the ordering, I do like to order my methods (I use Resharper&#039;s functionality to do this) however I wish I could enforce ordering for all members except those belonging to a DP (accessors, private attribute, etc...). Failing to do so, I decided to just avoid using regions altogether.

Cheers,
Laurent</description>
		<content:encoded><![CDATA[<p>Hey Jeff,</p>
<p>Like I told you on Twitter, I cannot remember why I deactivated some of the rules, but left the &#8220;this.&#8221; rule. I am reconsidering this.</p>
<p>For the ordering, I do like to order my methods (I use Resharper&#8217;s functionality to do this) however I wish I could enforce ordering for all members except those belonging to a DP (accessors, private attribute, etc&#8230;). Failing to do so, I decided to just avoid using regions altogether.</p>
<p>Cheers,<br />
Laurent</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Wilcox</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1571</link>
		<dc:creator>Jeff Wilcox</dc:creator>
		<pubDate>Thu, 27 Aug 2009 05:58:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1571</guid>
		<description>@Laurent,
StyleCop isn&#039;t as customizable as FxCop is (no custom rules), but you can turn off some StyleCop rules as you find necessary. Our settings file disables the ordering and &quot;this&quot; requirement for instance.

More details here: http://blogs.msdn.com/sourceanalysis/pages/sharing-source-analysis-settings-across-projects.aspx

I&#039;ll send or publish the settings file we use on the Silverlight Toolkit if you like, btw.</description>
		<content:encoded><![CDATA[<p>@Laurent,<br />
StyleCop isn&#8217;t as customizable as FxCop is (no custom rules), but you can turn off some StyleCop rules as you find necessary. Our settings file disables the ordering and &#8220;this&#8221; requirement for instance.</p>
<p>More details here: <a href="http://blogs.msdn.com/sourceanalysis/pages/sharing-source-analysis-settings-across-projects.aspx" rel="nofollow">http://blogs.msdn.com/sourceanalysis/pages/sharing-source-analysis-settings-across-projects.aspx</a></p>
<p>I&#8217;ll send or publish the settings file we use on the Silverlight Toolkit if you like, btw.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Bugnion</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1570</link>
		<dc:creator>Laurent Bugnion</dc:creator>
		<pubDate>Thu, 27 Aug 2009 05:43:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1570</guid>
		<description>Nice list. There are however at least two points that will cause StyleCop to choke:

- Grouping DPs in regions will cause it to protest because you don&#039;t follow the rule of ordering methods and properties. 

- Stylecop requires the use of &quot;this&quot;. I am not a big fan of using this in front of local params/methods/properties, but started doing it because I am tired of the Stylecop warning. I use Resharper to format my code, so it&#039;s not a big deal.

I went back and forth on the use of Stylecop. The best solution would be to be able to ceate our own rules (like FxCop allows) or at least to switch some rules off. Unfortunately it is not possible.

Cheers,
Laurent</description>
		<content:encoded><![CDATA[<p>Nice list. There are however at least two points that will cause StyleCop to choke:</p>
<p>- Grouping DPs in regions will cause it to protest because you don&#8217;t follow the rule of ordering methods and properties. </p>
<p>- Stylecop requires the use of &#8220;this&#8221;. I am not a big fan of using this in front of local params/methods/properties, but started doing it because I am tired of the Stylecop warning. I use Resharper to format my code, so it&#8217;s not a big deal.</p>
<p>I went back and forth on the use of Stylecop. The best solution would be to be able to ceate our own rules (like FxCop allows) or at least to switch some rules off. Unfortunately it is not possible.</p>
<p>Cheers,<br />
Laurent</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Wilcox</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1569</link>
		<dc:creator>Jeff Wilcox</dc:creator>
		<pubDate>Thu, 27 Aug 2009 05:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1569</guid>
		<description>@Chris,
On regions and grouping: specifically as it relates to control design, there&#039;s often a few thousand lines of misc. control &quot;goo&quot;: dependency properties and their change handlers, events, and general template code that is going to be difficult to refactor as you describe. As a result I&#039;d rather have control split into logical groupings - give me my dependency property declaration plus change handler, and even backing field, in a region, instead of splitting them into &quot;Fields&quot;, &quot;Dependency properties&quot;, and &quot;Private static method&quot; regions, for instance.

Good advice on the rest though - esp. naming. I guess I&#039;m just sharing my perspective here, coding style and guidelines are a holy war for some, so &quot;When in Rome&quot; is probably the best advice - follow peers and the team&#039;s practices and not some dude&#039;s blog :-)

For the IList vs array: Perhaps this isn&#039;t the best example, since an IList indicates need for dynamic Add/Remove capabilities, something an array won&#039;t have. I suppose the better advice is to return an IEnumerable&lt;t&gt; before an array, if possible.&lt;/t&gt;</description>
		<content:encoded><![CDATA[<p>@Chris,<br />
On regions and grouping: specifically as it relates to control design, there&#8217;s often a few thousand lines of misc. control &#8220;goo&#8221;: dependency properties and their change handlers, events, and general template code that is going to be difficult to refactor as you describe. As a result I&#8217;d rather have control split into logical groupings &#8211; give me my dependency property declaration plus change handler, and even backing field, in a region, instead of splitting them into &#8220;Fields&#8221;, &#8220;Dependency properties&#8221;, and &#8220;Private static method&#8221; regions, for instance.</p>
<p>Good advice on the rest though &#8211; esp. naming. I guess I&#8217;m just sharing my perspective here, coding style and guidelines are a holy war for some, so &#8220;When in Rome&#8221; is probably the best advice &#8211; follow peers and the team&#8217;s practices and not some dude&#8217;s blog <img src='http://www.jeff.wilcox.name/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>For the IList vs array: Perhaps this isn&#8217;t the best example, since an IList indicates need for dynamic Add/Remove capabilities, something an array won&#8217;t have. I suppose the better advice is to return an IEnumerable<t> before an array, if possible.</t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Wilcox</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1568</link>
		<dc:creator>Jeff Wilcox</dc:creator>
		<pubDate>Thu, 27 Aug 2009 05:18:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1568</guid>
		<description>@Shawn,
1: To minimize pressure on the dispatcher, only using it to invoke when necessary.
2: I was always taught the importance of this to avoid race conditions/another thread from nulling out the event handler, though most folks don&#039;t seem to worry about it much. Covered on StackOverflow here more or less: http://stackoverflow.com/questions/786383/c-events-and-thread-safety</description>
		<content:encoded><![CDATA[<p>@Shawn,<br />
1: To minimize pressure on the dispatcher, only using it to invoke when necessary.<br />
2: I was always taught the importance of this to avoid race conditions/another thread from nulling out the event handler, though most folks don&#8217;t seem to worry about it much. Covered on StackOverflow here more or less: <a href="http://stackoverflow.com/questions/786383/c-events-and-thread-safety" rel="nofollow">http://stackoverflow.com/questions/786383/c-events-and-thread-safety</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Anderson</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1567</link>
		<dc:creator>Chris Anderson</dc:creator>
		<pubDate>Thu, 27 Aug 2009 04:51:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1567</guid>
		<description>Nice post Jeff.  I agree with most of your points.  On the topic of regions, I tend to flip flop on that issue.  I think what you say is absolutely correct in that regions should be used to group related concepts, though in much of my code I tend to group public methods / private methods / etc as I find it more useful that way.  When classes get too big and contain different concepts to me that&#039;s a sign that refactoring is in order (though that&#039;s not always a possibility I know).  With prefixing private variables with an underscore there seems to be varying opinions on that.  While I had left hungarian notation back in VB 6 years ago, I did prefix my private fields with m_ until pressured otherwise.  So I simply use camel case names for private variables with no prefix, but I miss the prefix (which often means when there is a local variable of the same name I have to use this. to access it - yuk).  I see little difference between m_ and simply _ as the prefix, but anyway.  Such a small thing such as a prefix can create a big debate.  I&#039;m a little confused though with your examples for Remain CLS Compliant.  I&#039;m pretty sure I know what you mean from your description - but I don&#039;t get the examples you&#039;ve provided, especially the IList part being &#039;good&#039;.  Am I missing something?

Chris Anderson</description>
		<content:encoded><![CDATA[<p>Nice post Jeff.  I agree with most of your points.  On the topic of regions, I tend to flip flop on that issue.  I think what you say is absolutely correct in that regions should be used to group related concepts, though in much of my code I tend to group public methods / private methods / etc as I find it more useful that way.  When classes get too big and contain different concepts to me that&#8217;s a sign that refactoring is in order (though that&#8217;s not always a possibility I know).  With prefixing private variables with an underscore there seems to be varying opinions on that.  While I had left hungarian notation back in VB 6 years ago, I did prefix my private fields with m_ until pressured otherwise.  So I simply use camel case names for private variables with no prefix, but I miss the prefix (which often means when there is a local variable of the same name I have to use this. to access it &#8211; yuk).  I see little difference between m_ and simply _ as the prefix, but anyway.  Such a small thing such as a prefix can create a big debate.  I&#8217;m a little confused though with your examples for Remain CLS Compliant.  I&#8217;m pretty sure I know what you mean from your description &#8211; but I don&#8217;t get the examples you&#8217;ve provided, especially the IList part being &#8216;good&#8217;.  Am I missing something?</p>
<p>Chris Anderson</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shawn Wildermuth</title>
		<link>http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/comment-page-1/#comment-1566</link>
		<dc:creator>Shawn Wildermuth</dc:creator>
		<pubDate>Thu, 27 Aug 2009 04:24:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/custom-controls-simple-code-guidelines/#comment-1566</guid>
		<description>Great post, but I am confused by your event firing.  Here&#039;s your code:

public event RoutedEventHandler DownloadProgressChanged;  
  
private void OnDownloadProgressChanged(object sender, RoutedEventArgs args)  
{  
    if (!Dispatcher.CheckAccess())  
    {  
        Dispatcher.BeginInvoke(() =&gt; OnDownloadProgressChanged(sender, args));  
        return;  
    }  
  
    var handler = DownloadProgressChanged;  
    if (handler != null)  
    {  
        handler(this, args);  
    }  
}  

Two questions:

- Why not just fire the event in Dispatcher instead of calling yourself?

- Why do you get a local copy of the handler to check for null?  Why not just check the handler directly?</description>
		<content:encoded><![CDATA[<p>Great post, but I am confused by your event firing.  Here&#8217;s your code:</p>
<p>public event RoutedEventHandler DownloadProgressChanged;  </p>
<p>private void OnDownloadProgressChanged(object sender, RoutedEventArgs args)<br />
{<br />
    if (!Dispatcher.CheckAccess())<br />
    {<br />
        Dispatcher.BeginInvoke(() =&gt; OnDownloadProgressChanged(sender, args));<br />
        return;<br />
    }  </p>
<p>    var handler = DownloadProgressChanged;<br />
    if (handler != null)<br />
    {<br />
        handler(this, args);<br />
    }<br />
}  </p>
<p>Two questions:</p>
<p>- Why not just fire the event in Dispatcher instead of calling yourself?</p>
<p>- Why do you get a local copy of the handler to check for null?  Why not just check the handler directly?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
