<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/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>Derik Whittaker : Development, Featured, Opinion</title><link>http://devlicio.us/blogs/derik_whittaker/archive/tags/Development/Featured/Opinion/default.aspx</link><description>Tags: Development, Featured, Opinion</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Simple extension methods to help with Asserting values</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2008/04/10/simple-extension-methods-to-help-with-asserting-values.aspx</link><pubDate>Thu, 10 Apr 2008 12:49:43 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:40019</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=40019</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=40019</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2008/04/10/simple-extension-methods-to-help-with-asserting-values.aspx#comments</comments><description>&lt;p&gt;In the past I have written about the &lt;a href="http://devlicio.us/blogs/derik_whittaker/archive/2007/06/08/fail-fast-principle.aspx"&gt;Fail Fast&lt;/a&gt; principle.&amp;#160; This is a principle I try to live my development life by.&amp;#160; I would rather explicitly check for possible failure points then have a runtime error crop up.&amp;#160; In the past when writing these failure check we have had to resort to a few &amp;#39;cavemanish&amp;#39; techniques.&amp;#160; But with the inception of Extension Methods (&lt;a href="http://msdn2.microsoft.com/en-us/library/bb383977.aspx"&gt;here&lt;/a&gt; or &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx"&gt;here&lt;/a&gt;) we can actually create something that is pretty simple as well as elegant.&lt;/p&gt;  &lt;p&gt;Lets take a look at a few examples where we are NOT using extension methods to accomplish our failure checking.&lt;/p&gt;  &lt;pre class="c-sharp" name="code"&gt;public bool SomeMethod( string key )  
{  
	// In this case the key cannot be null or empty  
	if ( key.length == 0 ) { throw new ArgumentOutOfRangeException( &amp;quot;key&amp;quot;, &amp;quot;Some Message Goes here&amp;quot; ); }
} &lt;/pre&gt;

&lt;p&gt;The code above works, it is pretty simple and will get the job done.&amp;#160; But to be honest, having this sprinkled all over your code is kinda ugly.&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;public bool SomeMethod( SomeObject obj, Int32 someInt )  
{  
	// In this case the object cannot be null  
     	Assert.IsNotNull( obj, &amp;quot;Some Object&amp;quot; );  
  
	// In this case the int must be greater then 1  
     	Assert.IsTrue( someInt &amp;gt; 1, &amp;quot;Some Int not correct&amp;quot; );  
} &lt;/pre&gt;

&lt;p&gt;This code works as well and is more concise the the previous example.&amp;#160; However, this code is still less readable then the example below.&lt;/p&gt;

&lt;p&gt;Now, lets take a look at the same thing, but using Extension Methods&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;public bool SomeMethod( SomeObject obj, strnig someString )  
{  
	// In this case the object cannot be null  
	obj.AssertNonNull(); 
  
	// In this case the cannot be null or empty
	someString.AssertNotNullOrEmpty();	
} &lt;/pre&gt;

&lt;p&gt;Here is the code for the actual extension methods assert&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;public static void AssertNonNull( this T value )
{
	// Do our null check here.
	if ( value == null ) 
	{ 
		// Could even use reflection to gather info such as calling method, method exception was
		//	found in, etc.
		throw new ArgumentNullException( &amp;quot;Some message here&amp;quot; );
	}
}&lt;/pre&gt;

&lt;p&gt;The assert above using the extension method to me is the most elegant.&amp;#160; It is easy to read (very important) and very concise.&amp;#160; &lt;/p&gt;

&lt;p&gt;Keep in mind, all the examples above do the exact same thing, but they do in varying levels of elegance.&amp;#160; I would argue that the usage of extension methods here makes the code cleaner and easier to read.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=40019" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/.Net/default.aspx">.Net</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Opinion/default.aspx">Opinion</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Featured/default.aspx">Featured</category></item><item><title>Subclassing for Success</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2007/11/02/subclassing-for-success.aspx</link><pubDate>Fri, 02 Nov 2007 12:36:58 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:38781</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=38781</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=38781</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2007/11/02/subclassing-for-success.aspx#comments</comments><description>&lt;p&gt;As someone how has been designing and developing WinForms based applications for the past 7+ years, I have learned that subclassing UI controls is a must.&amp;nbsp; You may be thinking, why would I want to subclass a text box?&amp;nbsp; Or a combo box?&amp;nbsp; The answer is simple, the better future proof your app.&amp;nbsp; &lt;/p&gt; &lt;p&gt;How many times have you been into the development cycle of your application and you found out that you needed/wanted to extend the text box that is being used.&amp;nbsp; By extend I am not necessary talking about adding functionality to it, but do something like having the control highlight the entire contents of the control&amp;nbsp;when the&amp;nbsp;it receives focus.&lt;/p&gt; &lt;p&gt;If you don&amp;#39;t have your controls subclassed, extending your control will be a pain in your ass.&amp;nbsp; Sure you could find EVERY use of the control and add the needed&amp;nbsp;code.&amp;nbsp; Or you could find and replace your control later with the subclassed control, but both of these suck.&lt;/p&gt; &lt;p&gt;When I start a new WinForms (same concept should work for Browser based as well) application, I will immediately add a Controls namespace and simply add my subclassed controls.&amp;nbsp; In many cases I never extend the control, but knowing that I can do so allows me to make better decisions later on.&amp;nbsp; &lt;/p&gt; &lt;p&gt;One example of where this has helped me in the past was on a project where about 6 months into development, the business owners decided that would like the UI controls (text box, check box, combo box, etc) to change background color when the control receives focus and then change back when it loses focus.&amp;nbsp; Because I had everything subclassed i was able to implement this request in a very short time frame and did not even have to open up a single form.&amp;nbsp; Had I not subclasses the controls I would have either pushed back heavily or it would have taken me much longer to implement this change.&lt;/p&gt; &lt;p&gt;Another good use is for things like data grids.&amp;nbsp; Whether you are using the out of the box data grid, or some third party grid like Infragistics or Janus, subclassing can save you a ton.&amp;nbsp; How many times have you developed an application where you wanted a standard look and feel for your grids.&amp;nbsp; Say every other line is gray, and there are no selection column.&amp;nbsp; If the control is not subclassed you are asking each developer to remember to make the look and feel customizations.&amp;nbsp; But, if it is subclassed, simply add the control to the form and you are done.&lt;/p&gt; &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=38781" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Methodology/default.aspx">Methodology</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/WinForms/default.aspx">WinForms</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Opinion/default.aspx">Opinion</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Featured/default.aspx">Featured</category></item><item><title>Why I believe IN and WRITE unit tests</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2007/10/01/why-i-believe-in-and-write-unit-tests.aspx</link><pubDate>Tue, 02 Oct 2007 00:27:25 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:38554</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>12</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=38554</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=38554</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2007/10/01/why-i-believe-in-and-write-unit-tests.aspx#comments</comments><description>&lt;p&gt;In my last post I think I struck a cord with some people in my post &amp;#39;Unit tests taking too much time&amp;#39;.&amp;nbsp; My intent was NOT to sound like an elitist Agilist or any else of that nature.&amp;nbsp; My intent was simply to put a post out there about the misperception (in my opinion) about how writing unit tests take too much time.&lt;/p&gt; &lt;p&gt;I thought I would put my &amp;#39;retort&amp;#39; on why I believe in&amp;nbsp;and write unit tests.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Allows&amp;nbsp;ME to write better code&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;I believe that when&amp;nbsp;I truly follow TDD practices&amp;nbsp;my code comes out simpler.&amp;nbsp; I have also found, that my code tends to follow&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/YAGNI" target="_blank"&gt;YAGNI&lt;/a&gt;&amp;nbsp;more so then when I don&amp;#39;t follow TDD practices.&lt;/p&gt; &lt;p&gt;Here is an example from my past experience.&amp;nbsp; On a prior project I needed to build a &amp;#39;search engine&amp;#39; into our app (this was not an actual search engine, more like a hunt path engine).&amp;nbsp; When I first started out writing code I started out by creating all these classes and logic that I thought I would need.&amp;nbsp; After about 3-4 hours of coding I was dead in the water.&amp;nbsp; I was not able to solve my problem in a simple manner and I was frustrated.&amp;nbsp; I decided to take a step back and start over.&amp;nbsp; &lt;/p&gt; &lt;p&gt;This time though I&amp;nbsp;started out by writing test to mimic what I actually needed.&amp;nbsp; I continued to follow the principles of &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank"&gt;TDD&lt;/a&gt; (btw, TDD is more then just about writing tests), within an hour or so I had my solution pretty much good to go.&amp;nbsp; All those classes and methods I THOUGHT I would need I did NOT.&amp;nbsp; I was able to scrap about 50% of the code/classes that I thought I needed.&amp;nbsp; And guess what, now I have a test suit to test my new code.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Allows ME to find more bugs during the development process&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;It has been my experience that I find more bugs while writing tests.&amp;nbsp; This is due to the fact that I not only follow TDD, but I also do my best to implement the &lt;a href="http://en.wikipedia.org/wiki/Fail-fast" target="_blank"&gt;Fail Fast Principle&lt;/a&gt;.&amp;nbsp; When I am writing my tests I have the ability to create tests that easily walk though the different pathways of my code (I attempt to hit 100% code coverage as well).&amp;nbsp; If I were not writing tests I would have to do this via the application, and&amp;nbsp;this is much more painful and it less likely that I would actually do it.&lt;/p&gt; &lt;p&gt;By writing my tests and testing my code during the development process I know that I have reduced my bug count significantly.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Makes ME feel more comfortable making changes&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;This is the beauty of TDD, I am not afraid to make any critical changes to my code because I KNOW that I have tests to verify if I screwed anything up.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Have you ever run across some code that &amp;#39;you were scared&amp;#39; to change?&amp;nbsp; If you had tests for that code I bet you would a WHOLE LOT LESS scared to make any changes.&amp;nbsp; I know that I am.&lt;/p&gt; &lt;p&gt;A case in point for this is as follows.&amp;nbsp; On a prior project a consultant I was working with needed to make changes to some &amp;#39;smelly&amp;#39; logic.&amp;nbsp; This just happened to be a week or so before a scheduled release.&amp;nbsp; Beacuse he had NO confidence that the changes he would make would NOT break the application, he convinced the business to NOT make the changes. &amp;nbsp;I bet you a dollar that had there been unit tests he would have been much more willing to make the changes.&amp;nbsp; In this case the fact of NOT having tests may have caused the business to lose out on features it needed.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Improves MY code&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Because following TDD practices&amp;nbsp;forces you to write your failing code before your passing code,&amp;nbsp;I tend to implement my intent much cleaner and simpler.&amp;nbsp; I also know that because I am writing tests along the way my code is solid.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Allows ME to better convey intent&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;I know that tests are not a&amp;nbsp;substitution for&amp;nbsp;quality comments that convey intent, but they sure are the next best thing.&amp;nbsp; It is really nice to be able to point someone towards a suite of tests to &amp;#39;demo&amp;#39; how to use a component.&lt;/p&gt; &lt;p&gt;A case in point for this is as follows.&amp;nbsp; A few weeks ago at work I wrote an API to allow the querying of some data via our imaging system at work.&amp;nbsp; Turns out that an outside party needed to use this API for integration into on of our 3rd party applications.&amp;nbsp; When he came to me asking for &amp;#39;how do I use this&amp;#39;, I simply emailed him my suite of tests.&amp;nbsp; In this suite I had pretty much any conceivable use for the API.&amp;nbsp; To date the vendor has not asked me how to implement the API.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Allows MY tests to be automated and rerunable&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;This is a nice side effect of having tests.&amp;nbsp; Because we use&amp;nbsp;both NUnit and CruiseControl I can run my tests on every check in.&amp;nbsp; This is cool because now I (and the team) know if changes&amp;nbsp;I made&amp;nbsp;breaks some other part of the system.&amp;nbsp; I would rather know now then before QA hits it.&amp;nbsp; &lt;/p&gt; &lt;p&gt;The above are simply my opinion, if you don&amp;#39;t share the same opinions, let me know.&lt;/p&gt; &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=38554" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Methodology/default.aspx">Methodology</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Opinion/default.aspx">Opinion</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Featured/default.aspx">Featured</category></item><item><title>Logging Bugs: Do's and Don'ts</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2007/08/19/logging-bugs-the-do-s-and-don-ts.aspx</link><pubDate>Mon, 20 Aug 2007 00:40:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:38244</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=38244</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=38244</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2007/08/19/logging-bugs-the-do-s-and-don-ts.aspx#comments</comments><description>&lt;p&gt;All software that is being developed WILL have bugs, sorry, but this IS a fact.&amp;nbsp; Now I know some people and&amp;nbsp;companies don&amp;#39;t like to call them glitches&amp;nbsp;in software bugs.&amp;nbsp; They would rather call them issues or defects.&amp;nbsp; For all I care we can call them &amp;#39;WizBangs&amp;#39;, just call them something and LOG THEM.&lt;/p&gt;
&lt;p&gt;However, logging &amp;#39;WizBangs&amp;#39; (ok, I will call them bugs from here on) is not as simple as it may sound.&amp;nbsp; I would like to go over some of MY Do&amp;#39;s and Don&amp;#39;ts in this post.&amp;nbsp; If you don&amp;#39;t like my list, or would like to add to it, drop me a line.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;When to log Items:&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Do&lt;/b&gt; log everything.&amp;nbsp; Just because&amp;nbsp;the bug&amp;nbsp;may seem trivial or simple or only happen &amp;#39;every now and again&amp;#39; does not mean that it should be ignored.&amp;nbsp; Even it you are not sure it is an issue, LOG IT.&amp;nbsp; Better to have close off an non-issue then fail to report a major bug in hiding&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Don&amp;#39;t&lt;/b&gt; assume that someone else is going to fix the issue.&amp;nbsp; Also, don&amp;#39;t assume this issue is too trivial or minor to report.&amp;nbsp; Wouldn&amp;#39;t it suck to find out after the application went lived that &lt;b&gt;you&lt;/b&gt; failed to report a critical bug because you thought it was not a &amp;#39;big deal&amp;#39;?&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;Providing information on the log:&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Do&lt;i&gt; &lt;/i&gt;&lt;/b&gt;provide detailed information about the bug.&amp;nbsp; Save yourself the headache later and provide as much information as you possible can.&amp;nbsp; This should include, but not limited to items such as Build Version, Environment, Platform, Short Description of issue, Severity, Detailed steps to reproduce.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Don&amp;#39;t&lt;/b&gt; make provide a single sentence that says something like &amp;#39;Unable to perform XYZ in the ABC process&amp;#39;.&amp;nbsp; This type of information will provide nothing of real value to the next guy.&amp;nbsp; Sure, this would be a great line for the title of the bug.&amp;nbsp; But by no means is this enough information to fix the bug.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;What types of items to log:&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Do&lt;/b&gt; Log Everything.&amp;nbsp; Enough said&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Don&amp;#39;t&lt;/b&gt; make assumptions&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;When to log bugs:&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Do&lt;/b&gt; log them as soon as possible.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Don&amp;#39;t&lt;/b&gt; put it off.&amp;nbsp; If you dont log the bug as soon as you find it you WILL forget something about what you did to cause it.&amp;nbsp; For the sake of your fellow co-workers log it now before you forget.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The plain and simple truth about logging bugs is, it sucks!!!!&amp;nbsp; However, it is a necessary part of&amp;nbsp;most developers jobs.&amp;nbsp; If you take some time and put in a little effort, you will be rewarded with great riches.&amp;nbsp; Ok, maybe not great riches, but it will make fixing the bugs much easier.&lt;/p&gt;
&lt;p&gt;Till next time,&lt;/p&gt;&lt;br /&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://devlicio.us/blogs/derik_whittaker/archive/2007/08/19/logging-bugs-the-do-s-and-don-ts.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://devlicio.us/blogs/derik_whittaker/archive/2007/08/19/logging-bugs-the-do-s-and-don-ts.aspx" border="0" /&gt;&lt;/a&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=38244" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Methodology/default.aspx">Methodology</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Opinion/default.aspx">Opinion</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Featured/default.aspx">Featured</category></item></channel></rss>