<?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>JohnnyCoder &#187; Best Practices</title>
	<atom:link href="http://johnnycoder.com/blog/category/best-practices/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnnycoder.com/blog</link>
	<description></description>
	<lastBuildDate>Tue, 10 Apr 2012 00:14:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Managing .NET External Dependencies</title>
		<link>http://johnnycoder.com/blog/2010/03/22/managing-net-external-dependencies/</link>
		<comments>http://johnnycoder.com/blog/2010/03/22/managing-net-external-dependencies/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 21:19:01 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/03/22/managing-net-external-dependencies/</guid>
		<description><![CDATA[Noah and I continue our screencast series by sharing our approach to managing external dependencies referenced within a .NET solution.&#160; This is another introductory episode but you might find a hidden gem in the short 4-minute clip.&#160; ELMAH (Error Logging Modules and Handlers) is the external dependencies we are focusing on in the presentation.&#160; If [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.fairwaytech.com/blog/NoahH/Default.aspx">Noah</a> and I continue our screencast series by sharing our approach to managing external dependencies referenced within a .NET solution.&#160; This is another introductory episode but you might find a hidden gem in the short 4-minute clip.&#160; </p>
<p><a href="http://code.google.com/p/elmah/">ELMAH</a> (Error Logging Modules and Handlers) is the external dependencies we are focusing on in the presentation.&#160; If you are not familiar with ELMAH, this episode may be worth your time.</p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:53357c8b-5919-4e32-8c25-305d27c17a37:cfc775d4-5cde-4377-8960-20c85c428c3b" class="wlWriterEditableSmartContent"><embed src="http://www.youtube.com/v/mkDjzsqONxU&amp;rel=0" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed><br />
<br />
<a href="http://www.youtube.com/watch?v=mkDjzsqONxU">YouTube<br />
				- Managing .NET External Dependencies</a></div>
<p><em>     <br />This is one of our first screencasts.&#160; If you have feedback, I’d love to hear it.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/03/22/managing-net-external-dependencies/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2008 Solution Setup</title>
		<link>http://johnnycoder.com/blog/2010/03/15/visual-studio-2008-solution-setup/</link>
		<comments>http://johnnycoder.com/blog/2010/03/15/visual-studio-2008-solution-setup/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 15:23:09 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[Version Control]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/03/15/visual-studio-2008-solution-setup/</guid>
		<description><![CDATA[In this screencast, Noah and I demonstrate preferred practices around .NET solution setup, naming conventions and version control.&#160; I consider this an introductory video.&#160; If you’ve been around the block, you might want to skip this episode but if you’re a .NET/Visual Studio newbie, it may be worth a look.&#160; &#160; YouTube - Visual Studio [...]]]></description>
			<content:encoded><![CDATA[<p>In this screencast, <a href="http://www.fairwaytech.com/blog/NoahH/Default.aspx">Noah</a> and I demonstrate preferred practices around .NET solution setup, naming conventions and version control.&#160; I consider this an introductory video.&#160; If you’ve been around the block, you might want to skip this episode but if you’re a .NET/Visual Studio newbie, it may be worth a look.&#160; </p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:53357c8b-5919-4e32-8c25-305d27c17a37:efd36d54-3307-43f3-96a2-e287b3f052b2" class="wlWriterEditableSmartContent"><embed src="http://www.youtube.com/v/z8tbBypTG9g&amp;rel=0" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed><br />
<br />
<a href="http://www.youtube.com/watch?v=z8tbBypTG9g">YouTube<br />
				- Visual Studio 2008 Solution Setup</a></div>
<p>&#160;</p>
<p><em>This is one of our first screencasts.&#160; Actually it is the very first.&#160; If you have feedback, I’d love to hear it.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/03/15/visual-studio-2008-solution-setup/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>HTTPHandler with JSON Data</title>
		<link>http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/</link>
		<comments>http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 17:24:17 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Samples]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/</guid>
		<description><![CDATA[As javascript libraries, particularly jQuery, increase in popularity so do web techniques using AJAX and JSON. Have you ever seen this code?&#160; It is front and back of an ASPX file with the single responsibility to return JSON data per an AJAX request. GetDataPage.aspx &#60;%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetDataPage.aspx.cs" Inherits="GetDataPage" %&#62; &#60;%-- This minimal code [...]]]></description>
			<content:encoded><![CDATA[<p>As javascript libraries, particularly jQuery, increase in popularity so do web techniques using AJAX and JSON.</p>
<p>Have you ever seen this code?&nbsp; It is front and back of an ASPX file with the single responsibility to return JSON data per an AJAX request.</p>
<p><span style="text-decoration: underline">GetDataPage.aspx</span></p>
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Page </span><span style="color: red">Language</span><span style="color: blue">="C#" </span><span style="color: red">AutoEventWireup</span><span style="color: blue">="true"
    </span><span style="color: red">CodeFile</span><span style="color: blue">="GetDataPage.aspx.cs" </span><span style="color: red">Inherits</span><span style="color: blue">="GetDataPage" </span><span style="background: #ffee62">%&gt;
&lt;%</span><span style="color: green">--
    This minimal code is here to prevent the following error:
     "Using themed css files requires a header control on the page"
     Please see http://www.west-wind.com/WebLog/posts/4662.aspx
     for more information --</span><span style="background: #ffee62">%&gt;
</span><span style="color: blue">&lt;</span><span style="color: #a31515">head </span><span style="color: red">id</span><span style="color: blue">="Head1" </span><span style="color: red">runat</span><span style="color: blue">="server" </span><span style="color: red">visible</span><span style="color: blue">="false" /&gt;
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><span style="text-decoration: underline">GetDataPage.aspx.cs</span></p>
<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Web;
<span style="color: blue">using </span>System.Text;

<span style="color: blue">public partial class </span><span style="color: #2b91af">GetDataPage </span>: System.Web.UI.<span style="color: #2b91af">Page
</span>{
    <span style="color: blue">protected void </span>Page_Load(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)
    {
        <span style="color: green">// Clear out the buffer
        </span>Response.ClearHeaders();
        Response.ClearContent();
        Response.Clear();

        <span style="color: green">// Do not cache response
        </span>Response.Cache.SetCacheability(<span style="color: #2b91af">HttpCacheability</span>.NoCache);

        <span style="color: green">// Set the content type and encoding for JSON
        </span>Response.ContentType = <span style="color: #a31515">"application/json"</span>;
        Response.ContentEncoding = <span style="color: #2b91af">Encoding</span>.UTF8;

        <span style="color: blue">int </span>page = <span style="color: blue">int</span>.Parse(Request[<span style="color: #a31515">"p"</span>]);
        <span style="color: blue">string </span>results = <span style="color: #2b91af">DataAccess</span>.GetResults(page);

        Response.Write(results);

        <span style="color: green">// Flush the response buffer
        </span>Response.Flush();

        <span style="color: green">// Complete the request.  NOTE: Do not use Response.End() here,
        // because it throws a ThreadAbortException, which cannot be caught!
        </span><span style="color: #2b91af">HttpContext</span>.Current.ApplicationInstance.CompleteRequest();
    }
}
</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>You may have noticed there&#8217;s a comment for nearly every code block.&nbsp; At first, one may find the comments redundant and unnecessary, but really they are call for help.&nbsp; A code:comment ratio like this usually indicates you really need to focus on what&#8217;s happening with the code because if you aren&#8217;t paying attention, bad things might happen.</p>
<p>As you have undoubtedly concluded, there&#8217;s a lot of overhead associated with returning JSON data from an ASPX file.&nbsp; This statement is especially true if you consider the alternative, an HTTPHandler.&nbsp; Here&#8217;s a cleaner, best-practices approach which provides the same outcome with less code, comments and risk.</p>
<p><span style="text-decoration: underline">GetDataHandler.ashx</span></p>
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">WebHandler </span><span style="color: red">Language</span><span style="color: blue">="C#" </span><span style="color: red">Class</span><span style="color: blue">="GetDataHandler" </span><span style="background: #ffee62">%&gt;

</span><span style="color: blue">using </span>System.Text;
<span style="color: blue">using </span>System.Web;

<span style="color: blue">public class </span><span style="color: #2b91af">GetDataHandler </span>: <span style="color: #2b91af">IHttpHandler
</span>{
    <span style="color: blue">public bool </span>IsReusable
    {
        <span style="color: blue">get </span>{ <span style="color: blue">return false</span>; }
    }

    <span style="color: blue">public void </span>ProcessRequest (<span style="color: #2b91af">HttpContext </span>context)
    {
        context.Response.ContentType = <span style="color: #a31515">"application/json"</span>;
        context.Response.ContentEncoding = <span style="color: #2b91af">Encoding</span>.UTF8;

        <span style="color: blue">int </span>page = <span style="color: blue">int</span>.Parse(context.Request[<span style="color: #a31515">"p"</span>]);
        <span style="color: blue">string </span>results = <span style="color: #2b91af">DataAccess</span>.GetResults(page);

        context.Response.Write(results);
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>If you are already accustomed to using generic handlers to stream back images, XML, JSON data, etc, this post was probably a bore. But it&#8217;s sometimes easy to forget what&#8217;s available to <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/12/image2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="160" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2008/12/image-thumb2.png" width="244" align="right" border="0"></a>you in the vast .NET stack, so hopefully you appreciate the friendly reminder.&nbsp; In either case, it still surprises me how many examples use the ASPX approach.&nbsp; In fact, the practice is common enough that I sometimes wonder if there&#8217;s an HTTPHandler gotcha to which I&#8217;m not privy .&nbsp; If I am missing something, please let me know.</p>
<p>If you&#8217;re still interested, attached you&#8217;ll find code which populates two jQuery Flexbox controls using JSON data provided through an ASPX and ASHX files.&nbsp; This may be worthwhile download if you&#8217;re interest in the generic handler code or you want a further look at Flexbox in action after <a href="http://johnnycoder.com/blog/2008/12/13/flexbox-jquery-plugin/">last week&#8217;s post</a>.</p>
<div class="wlWriterSmartContent" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:c1d080fd-bc5d-4b7d-8d47-abe9f5cfbce0" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<div>Download JsonHandler Sample Project: <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/12/jsonhandler1.zip" target="_blank">JsonHandler.zip</a></div>
</p>
</div>
</p>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:36b47f1d-cc23-4bfb-aa40-0ace90b1e1c5" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Guarding Against Multiple Empty Strings</title>
		<link>http://johnnycoder.com/blog/2008/11/12/guarding-against-multiple-empty-strings/</link>
		<comments>http://johnnycoder.com/blog/2008/11/12/guarding-against-multiple-empty-strings/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 06:08:42 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Samples]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/11/12/guarding-against-multiple-empty-strings/</guid>
		<description><![CDATA[Many of my C# methods include what is referred to as a guard clause.&#160; It isn&#8217;t a complicated concept.&#160; Simply the first few statements of a routine validates passed-in parameters and/or state of the object and immediately returns an error or gracefully exits to the function is constraints aren&#8217;t met.&#160; If I&#8217;m not mistaken, this [...]]]></description>
			<content:encoded><![CDATA[<p>Many of my C# methods include what is referred to as a <a href="http://c2.com/cgi/wiki?GuardClause">guard clause</a>.&nbsp; It isn&#8217;t a complicated concept.&nbsp; Simply the first few statements of a routine validates passed-in parameters and/or state of the object and immediately returns an error or gracefully exits to the function is constraints aren&#8217;t met.&nbsp; If I&#8217;m not mistaken, this plays nicely with the <a href="http://en.wikipedia.org/wiki/Design_by_contract">Design by Contract</a> approach to software design, but I no expect on the subject.&nbsp; The bottom line is, a guard clause can really tighten and clean up your code because it will undoubtedly eliminate any number of nested conditional statements.</p>
<p>Consider the following sample taken directly from <a href="http://c2.com/cgi/wiki?GuardClause">c2.com</a>:</p>
<pre class="code"><span style="color: blue">public </span>Foo merge(Foo a, Foo b)
{
    Foo result;
    <span style="color: blue">if </span>(a != <span style="color: blue">null</span>)
    {
        <span style="color: blue">if </span>(b != <span style="color: blue">null</span>)
        {
            <span style="color: green">// complicated merge code goes here.
        </span>}
        <span style="color: blue">else
        </span>{
            result = a;
        }
    }
    <span style="color: blue">else
    </span>{
        result = b;
    }
    <span style="color: blue">return </span>result;
}
</pre>
<p>Now with the guard clause&#8230;</p>
<pre class="code"><span style="color: blue">public </span>Foo merge(Foo a, Foo b)
{
    <span style="color: blue">if </span>(a == <span style="color: blue">null</span>) <span style="color: blue">return </span>b;
    <span style="color: blue">if </span>(b == <span style="color: blue">null</span>) <span style="color: blue">return </span>a;
    <span style="color: green">// complicated merge code goes here.
</span>}</pre>
<p>Much cleaner, eh? And that&#8217;s only two conditionals! Back to my point.&nbsp; Many of my method include guard clauses.&nbsp; Today I needed to validate that all three string parameters had a value.&nbsp; In other words, each string&#8217;s length was greater than 0. </p>
<p>I started with my faithful Is-Not-Null-Or-Empty check:</p>
<pre class="code"><span style="color: blue">string </span>a = <span style="color: #a31515">"a"</span>;
<span style="color: blue">string </span>b = <span style="color: #a31515">"b"</span>;
<span style="color: blue">string </span>c = <span style="color: #a31515">""</span>;

<span style="color: blue">if </span>(<span style="color: blue">string</span>.IsNullOrEmpty(a) ||
    <span style="color: blue">string</span>.IsNullOrEmpty(b) ||
    <span style="color: blue">string</span>.IsNullOrEmpty(c))
    <span style="color: blue">return</span>;</pre>
<p>But then I settled on this:</p>
<pre class="code"><span style="color: blue">string </span>a = <span style="color: #a31515">"a"</span>;
<span style="color: blue">string </span>b = <span style="color: #a31515">"b"</span>;
<span style="color: blue">string </span>c = <span style="color: #a31515">""</span>;

<span style="color: blue">if </span>(a.Length * b.Length * c.Length == 0) <span style="color: blue">return</span>;</pre>
<p><font color="#000000">What do you think?&nbsp; Pretty hokey, right?</font></p>
<p>&nbsp;</p>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:3f97a782-1b95-4fd7-a838-6c2c1c8ca986" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/11/12/guarding-against-multiple-empty-strings/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/11/12/guarding-against-multiple-empty-strings/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/11/12/guarding-against-multiple-empty-strings/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>I Am Not A Control Developer</title>
		<link>http://johnnycoder.com/blog/2008/10/14/i-am-not-a-control-developer/</link>
		<comments>http://johnnycoder.com/blog/2008/10/14/i-am-not-a-control-developer/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 04:50:20 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Controls]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/10/14/i-am-not-a-control-developer/</guid>
		<description><![CDATA[I&#8217;ve created a number of user and server controls for my C# web applications.  Recently, however, I&#8217;ve found myself working in Silverlight and, if you are of the same opinion as me, you believe Silverlight was missing a few core controls.  Specifically, Silverlight was missing a TextBox with password masking and a CombBox until Monday&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a number of user and server controls for my C# web applications.  Recently, however, I&#8217;ve found myself working in Silverlight and, if you are of the same opinion as me, you believe Silverlight was missing a few core controls.  Specifically, Silverlight was missing a TextBox with password masking and a CombBox until Monday&#8217;s <a href="http://www.microsoft.com/presspass/press/2008/oct08/10-13Silverlight2PR.mspx.">Silverlight 2 Release Announcement</a>. Prior to the <a href="http://weblogs.asp.net/scottgu/archive/2008/09/25/silverlight-2-release-candidate-now-available.aspx">release candidate becoming available</a> a couple of weeks ago, you had 3 options if you needed one of these controls in your Silverlight application; you could purchase a commercial control, find an open source implementation or hack your own control together. </p>
<p>I really didn&#8217;t know enough to put together my own solution so I downloaded a lot of code and clicked through numerous demos in an attempt to find something that already worked.  Luckily, I found <a href="http://pietschsoft.com/post/2008/03/PasswordTextBox-for-Silverlight-2-Beta-1.aspx">sample code available for a PasswordTextbox which needed little fine tuning on Chris Pietshcmann&#8217;s blog</a>.  Though I literally searched for hours and sampled many implementations, I didn&#8217;t find a satisfactory commercial or open source ComboBox control.  Ultimately, I settled on a AutoComplete TextBox / ComboBox hybrid which I pieced together with the help of <a href="http://weblogs.manas.com.ar/ary/2008/09/26/autocomplete-in-silverlight/">a couple of posts made by Ary Borenszweig</a>.  I was really encouraged but how much I learned through the process and even though my controls will have an exceptionally short life expectancy, I am pleased with how they turned out. </p>
<p>I found it interesting to discover that only a few of the controls I researched/tested really, really worked.  Yes, primary functionality was in place the majority of the time, but shortcomings became obvious once I dropped the controls into a &#8220;real&#8221; application.  So, here are a few thoughts I collected for those (including myself) interested in pursuing control development: </p>
<p><strong>Code for both the mouse and the keyboard user</strong>.  Think big strokes like navigation, data entry and value selection.  Whatever action is available via the mouse should be available via the keyboard and vice versa.  For example, don&#8217;t make users click on the ComboBox in order to have the dropdown list appear.  Instead, get familiar with standard ComboBox operations by playing with ComboBoxes found in other frameworks.  Comboboxes have been around for a long time.  Unless you mimic de facto standard functionality, your control will be full of holes. </p>
<p><strong>Don&#8217;t forget to test the edge cases.</strong>  Sure. Most of the time a user is going to simply enter a password from left to right, one character at a time, but what if the user copy and pastes in an entire password or, better yet, what if a password is entered and then the user selects and replaces the middle three characters without ever touching the mouse.  Here&#8217;s a good one: what happens if the PasswordTextBox mask, perhaps an asterisks, is entered as part of the password string?  Will your control break?  I am pretty sure mine will&#8230; Edge cases are tricky and endless.  The main point here is test, test, test anything a user might do.</p>
<p><strong>Test controls in a real world scenario. </strong>There&#8217;s a lot you can immediately learn about a control once you start using it with purpose.  Is your control easily populated?  Can you easily extract the value?  Can the control be validated?  If necessary, how does the invalid state present itself?   When it comes to look and feel, can your control use existing themes/styles?  Finally, does your control play nicely with others?  Can you tab in and out of your control smoothly?  Can you programmatically give focus to your control?  What happens when your control loses focus?  Until you drop your control into an application, some of those questions may not be considered or answerable.</p>
<p>Again, I am not a control developer, but I will keep the thoughts above in mind the next time I create a control.  Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/10/14/i-am-not-a-control-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VS2008 Test Project Tips</title>
		<link>http://johnnycoder.com/blog/2008/08/04/vs2008-test-project-tips/</link>
		<comments>http://johnnycoder.com/blog/2008/08/04/vs2008-test-project-tips/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 13:00:00 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Tip and Tricks]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/08/04/vs2008-test-project-tips/</guid>
		<description><![CDATA[As I mentioned last week, I am new to TDD.  For better or worse, all of my tests (and spikes) have been generated via Visual Studio Test Projects.  Working with VS Test Projects hasn&#8217;t been all that bad although I noticed a couple of annoyances right away.  Is anyone else bothered by the fact that, [...]]]></description>
			<content:encoded><![CDATA[<p>As <a href="http://johnnycoder.com/blog/2008/08/01/learning-test-driven-development/">I mentioned last week, I am new to TDD</a>.  For better or worse, all of my tests (and spikes) have been generated via Visual Studio Test Projects.  Working with VS Test Projects hasn&#8217;t been all that bad although I noticed a couple of annoyances right away. </p>
<p>Is anyone else bothered by the fact that, by default, an unlimited number of test results and binaries are &#8220;deployed?&#8221;  If you are testing first, this arguably makes for a lot of useless activity and waste disk space.  Since the default TestResults folder location is set to be side-by-side with your solution files, the extra folders, trx files and binaries can also really interfere with your otherwise easy source control check-ins. </p>
<p>Fortunately, there are ways to work around the excessive TestResults problem if you are running VS2008.  Some options are available through the IDE and other require an update to the .testrunconfig file directly:</p>
<p><span style="text-decoration: underline;">Limit the number of deployed tests:</span></p>
<p>Tools &gt; Options &gt; Test Tools &gt; Test Execution &gt; Test Results Management &gt; Limit number of old Test Results to the value of your choosing. </p>
<p>The screen shot below sets the number of tests to one.  Therefore all previous tests are purged and only the latest test is maintained.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2008/08/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/08/image-thumb.png" border="0" alt="image" width="244" height="119" /></a></p>
<p><span style="text-decoration: underline;">Disable Test Result deployment:</span></p>
<p>If you wish to disable the Test Result generation completely, double-click on your solution&#8217;s .testrunconfig file and uncheck the &#8220;Enable deployment&#8221; option.  No results will be generated thereafter.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2008/08/image1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/08/image-thumb1.png" border="0" alt="image" width="244" height="155" /></a> </p>
<p><span style="text-decoration: underline;">Change the Test Result folder location:</span></p>
<p>This option is hidden.  I don&#8217;t believe it is exposed in any of the VS 2008 dialogues and you have to edit the .testrunconfig file directly. </p>
<p>Right-click on the .testrunconfig file &gt; Open With&#8230; &gt; XML Editor &gt; Include the following within the <span style="color: #a31515;">TestRunConfiguration </span>node:</p>
<pre class="code"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Deployment </span><span style="color: #ff0000;">useDefaultDeploymentRoot</span><span style="color: #0000ff;">=</span>"<span style="color: #0000ff;">false</span>" <span style="color: #ff0000;">userDeploymentRoot</span><span style="color: #0000ff;">=</span>"<span style="color: #0000ff;">C:\TestResults</span>" <span style="color: #0000ff;">/&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>I hope it helps.</p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:9c6072a3-aa11-4796-9283-24a670b37930" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/08/04/vs2008-test-project-tips/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/08/04/vs2008-test-project-tips/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
<p>References:</p>
<ul>
<li><a title="http://arcware.net/archive/2007/12/09/Limit-the-Number-of-Old-Test-Results-with-VS2008.aspx" href="http://arcware.net/archive/2007/12/09/Limit-the-Number-of-Old-Test-Results-with-VS2008.aspx">http://arcware.net/archive/2007/12/09/Limit-the-Number-of-Old-Test-Results-with-VS2008.aspx</a></li>
<li><a title="http://blogs.msdn.com/nnaderi/archive/2007/05/11/new-unit-testing-features-in-orcas-part-1.aspx" href="http://blogs.msdn.com/nnaderi/archive/2007/05/11/new-unit-testing-features-in-orcas-part-1.aspx">http://blogs.msdn.com/nnaderi/archive/2007/05/11/new-unit-testing-features-in-orcas-part-1.aspx</a></li>
<li><a title="http://weblogs.asp.net/stephenwalther/archive/2008/03/19/tdd-test-driven-development-with-visual-studio-2008-unit-tests.aspx" href="http://weblogs.asp.net/stephenwalther/archive/2008/03/19/tdd-test-driven-development-with-visual-studio-2008-unit-tests.aspx">http://weblogs.asp.net/stephenwalther/archive/2008/03/19/tdd-test-driven-development-with-visual-studio-2008-unit-tests.aspx</a></li>
<li><a title="http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3026907&amp;SiteID=1" href="http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3026907&amp;SiteID=1">http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3026907&amp;SiteID=1</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/08/04/vs2008-test-project-tips/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Safe Cast for No Good Reason</title>
		<link>http://johnnycoder.com/blog/2008/06/10/safe-cast-for-no-good-reason/</link>
		<comments>http://johnnycoder.com/blog/2008/06/10/safe-cast-for-no-good-reason/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 03:17:15 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Samples]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/06/10/safe-cast-for-no-good-reason/</guid>
		<description><![CDATA[I&#8217;m not sure I can come up with a good argument to ever use Safe Casting.  Per my earlier post, I&#8217;m not able to convert the result of the following Predicate, List&#60;MachineProduct&#62;, to a MachineProductCollection even though MachineProductCollection inherits from List&#60;MachineProduct&#62;.   // Code complies and the invalid Cast results in // machineProducts being set to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure I can come up with a good argument to ever use Safe Casting.  Per my <a href="http://johnnycoder.com/blog/2008/06/10/invalidcastexception-though-same-base-class/">earlier post</a>, I&#8217;m not able to convert the result of the following Predicate, List&lt;MachineProduct&gt;, to a MachineProductCollection even though MachineProductCollection inherits from List&lt;MachineProduct&gt;.  </p>
<pre class="code"><span style="color: #008000;">// Code complies and the invalid Cast results in
// machineProducts being set to null instead of an
// exception being thrown.
</span><span style="color: #2b91af;">MachineProductCollection </span>machineProducts =
    MachineProductList.FindAll(c =&gt; c.MachineID == MachineID)
    <span style="color: #0000ff;">as </span><span style="color: #2b91af;">MachineProductCollection</span>;</pre>
<p>As statement in the above comment, the invalid cast is essentially masked due to the Safe Cast or the convert using the &#8220;as&#8221; operator.  Alternative implementations, I believe, are more appropriate as an implicit conversion causes a pre-runtime, compilation error and a &#8220;traditional&#8221; cast throws an InvalidCastException at runtime, respectively:</p>
<pre class="code"><span style="color: #008000;">// Compiler complains since it knows List&lt;MachineProduct&gt; can not
// be converted to MachineProductCollection
</span><span style="color: #2b91af;">MachineProductCollection </span>machineProducts =
        MachineProductList.FindAll(c =&gt; c.MachineID == MachineID);

<span style="color: #008000;">// Code compiles but a runtime InvalidCastException is thrown
// since List&lt;MachineProduct&gt; can not be converted to
// MachineProductCollection
</span><span style="color: #2b91af;">MachineProductCollection </span>machineProducts = (<span style="color: #2b91af;">MachineProductCollection</span>)
        MachineProductList.FindAll(c =&gt; c.MachineID == MachineID);</pre>
<p>I&#8217;m probably missing something but I can&#8217;t think of a scenario in which I would <span style="text-decoration: underline;">intentionally</span> want to assign a null value if my cast is invalid.  Why &#8220;swallow&#8221; the exception and work with bad data?  It doesn&#8217;t make sense to me.</p>
<p>I&#8217;ve read that one should use the &#8220;is&#8221; operator in conjunction with the &#8220;as&#8221; operator.  Basically, this ensures the conversion is valid before it is executed, but what is the point.  Do more work to get the same lousy, invalid result?</p>
<pre class="code"><span style="color: #008000;">// What is the point of this?
</span><span style="color: #2b91af;">MachineProductCollection </span>machineProducts = <span style="color: #0000ff;">null</span>;

<span style="color: #0000ff;">if </span>(MachineProductList.FindAll(c =&gt;
    c.MachineID == MachineID) <span style="color: #0000ff;">is </span><span style="color: #2b91af;">MachineProductCollection</span>)
{
    machineProducts = MachineProductList.FindAll(c =&gt; c.MachineID == MachineID)
        <span style="color: #0000ff;">as </span><span style="color: #2b91af;">MachineProductCollection</span>;
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Perhaps I should have taken more CS classes in college&#8230;</p>
<p><em>Additional References:</em></p>
<ul>
<li><a href="http://www.aspheute.com/english/20001019.asp"><em>Safe Conversion of Reference Types</em></a><em>
<p></em></li>
</ul>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:ac4ef825-870b-42b2-a8bc-774c061bced1" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/06/10/safe-cast-for-no-good-reason/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/06/10/safe-cast-for-no-good-reason/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/06/10/safe-cast-for-no-good-reason/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Tip: Uniquely Name Table Columns</title>
		<link>http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/</link>
		<comments>http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 23:43:58 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/</guid>
		<description><![CDATA[It is easy to see the subtle difference between the Product Tables below.  The table to the left adds the table name as a prefix to nearly all of the column names. The table on the right represents very simple column names with no redundancy.  Early in my career, I preferred the implementation to the [...]]]></description>
			<content:encoded><![CDATA[<p>It is easy to see the subtle difference between the Product Tables below.  The table to the left adds the table name as a prefix to nearly all of the column names. <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image10.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image-thumb6.png" border="0" alt="image" width="475" height="195" align="right" /></a> The table on the right represents very simple column names with no redundancy.  Early in my career, I preferred the implementation to the right as I felt this pattern best represented the object (table) itself.  After all, we all have a<em> name.  </em>We don&#8217;t have a <em>PersonName.</em> Well,<em> </em>it didn&#8217;t take me long to change my opinion.</p>
<p>The next time you are designing a database, do yourself a favor and mimic the pattern to the left.  <strong>Always prefix column names with the table name if the column name is likely to be repeated  in more than one table.</strong>  ID, Name, Description, DateAdd and DateChange are good examples of column names which tend to show up in multiple places.  When it comes time to build your queries and work with the result sets, you will thank me. </p>
<p>Consider the two following routines &#8212; each returns the same result but the latter is much cleaner, readable, consists of less code and is inherently greater resistant to stupid coding errors especially within the syntax of the join and the column aliases.</p>
<pre class="code"><span style="color: #008000;">-- Poor implementation
</span><span style="color: #0000ff;">declare </span>@Product <span style="color: #0000ff;">table
</span><span style="color: #808080;">(
    </span>ID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span><span style="color: #0000ff;">Name varchar</span><span style="color: #808080;">(</span>50<span style="color: #808080;">)
)

</span><span style="color: #0000ff;">declare </span>@ProductVersion <span style="color: #0000ff;">table
</span><span style="color: #808080;">(
    </span>ID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span>ProductID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span>VersionNumber <span style="color: #0000ff;">int
</span><span style="color: #808080;">)

</span><span style="color: #0000ff;">insert into </span>@Product<span style="color: #808080;">(</span>ID<span style="color: #808080;">, </span><span style="color: #0000ff;">Name</span><span style="color: #808080;">)
</span><span style="color: #0000ff;">select </span>1<span style="color: #808080;">, </span><span style="color: #ff0000;">'product 1'
</span><span style="color: #0000ff;">union
select </span>2<span style="color: #808080;">, </span><span style="color: #ff0000;">'product 2'

</span><span style="color: #0000ff;">insert into </span>@ProductVersion <span style="color: #808080;">(</span>ID<span style="color: #808080;">, </span>ProductID<span style="color: #808080;">, </span>VersionNumber<span style="color: #808080;">)
</span><span style="color: #0000ff;">select </span>1<span style="color: #808080;">, </span>1<span style="color: #808080;">, </span>1
<span style="color: #0000ff;">union
select </span>1<span style="color: #808080;">, </span>2<span style="color: #808080;">, </span>1

<span style="color: #008000;">-- Note the column aliases and
-- join on less-than-obvious columns
</span><span style="color: #0000ff;">select </span>P<span style="color: #808080;">.</span>ID <span style="color: #0000ff;">as </span>ProductID<span style="color: #808080;">, </span>PV<span style="color: #808080;">.</span>ID <span style="color: #0000ff;">as </span>ProductVersionID <span style="color: #0000ff;">from
</span>@Product P <span style="color: #808080;">inner join
</span>@ProductVersion PV <span style="color: #0000ff;">on </span><span style="color: #808080;">(</span>P<span style="color: #808080;">.</span>ID <span style="color: #808080;">= </span>PV<span style="color: #808080;">.</span>ProductID<span style="color: #808080;">)

</span>go

<span style="color: #008000;">-- Proper implementation
</span><span style="color: #0000ff;">declare </span>@Product <span style="color: #0000ff;">table
</span><span style="color: #808080;">(
    </span>ProductID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span><span style="color: #0000ff;">Name varchar</span><span style="color: #808080;">(</span>50<span style="color: #808080;">)
)

</span><span style="color: #0000ff;">declare </span>@ProductVersion <span style="color: #0000ff;">table
</span><span style="color: #808080;">(
    </span>ProductVersionID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span>ProductID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span>VersionNumber <span style="color: #0000ff;">int
</span><span style="color: #808080;">)

</span><span style="color: #0000ff;">insert into </span>@Product<span style="color: #808080;">(</span>ProductID<span style="color: #808080;">, </span><span style="color: #0000ff;">Name</span><span style="color: #808080;">)
</span><span style="color: #0000ff;">select </span>1<span style="color: #808080;">, </span><span style="color: #ff0000;">'product 1'
</span><span style="color: #0000ff;">union
select </span>2<span style="color: #808080;">, </span><span style="color: #ff0000;">'product 2'

</span><span style="color: #0000ff;">insert into </span>@ProductVersion <span style="color: #808080;">(</span>ProductVersionID<span style="color: #808080;">, </span>ProductID<span style="color: #808080;">, </span>VersionNumber<span style="color: #808080;">)
</span><span style="color: #0000ff;">select </span>1<span style="color: #808080;">, </span>1<span style="color: #808080;">, </span>1
<span style="color: #0000ff;">union
select </span>1<span style="color: #808080;">, </span>2<span style="color: #808080;">, </span>1

<span style="color: #008000;">-- Note there's no need for aliases and
-- the join obvious
</span><span style="color: #0000ff;">select </span>P<span style="color: #808080;">.</span>ProductID<span style="color: #808080;">, </span>PV<span style="color: #808080;">.</span>ProductVersionID <span style="color: #0000ff;">from
</span>@Product P <span style="color: #808080;">inner join
</span>@ProductVersion PV <span style="color: #0000ff;">on </span><span style="color: #808080;">(</span>P<span style="color: #808080;">.</span>ProductID <span style="color: #808080;">= </span>PV<span style="color: #808080;">.</span>ProductID<span style="color: #808080;">)</span></pre>
<pre class="code"></pre>
<p>Keep this tip in mind.  It will save you heartache throughout your next project.</p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:2089731e-2353-4b16-84f0-235d0d727151" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CAPTCHA Roulette</title>
		<link>http://johnnycoder.com/blog/2008/06/10/captcha-roulette/</link>
		<comments>http://johnnycoder.com/blog/2008/06/10/captcha-roulette/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 22:39:48 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/06/10/captcha-roulette/</guid>
		<description><![CDATA[I vividly recall creating my Windows Live account and wondering how many folks are able to guess the 8 character CAPTCHA on the first attempt. I swear the CAPTCHA presented to me looked like random scribbles in a box. I did take screen shots but they seemed to have disappeared just like my patience on [...]]]></description>
			<content:encoded><![CDATA[<p>I vividly recall creating my Windows Live account and wondering how many folks are able to guess the 8 character <a href="http://en.wikipedia.org/wiki/Captcha">CAPTCHA</a> on the first attempt. I swear the CAPTCHA presented to me looked like random scribbles in a box. I did take screen shots but they seemed to have disappeared just like my patience on the day of signup. <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image7.png"><img style="border-width: 0px; margin: 10px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image-thumb4.png" border="0" alt="image" width="244" height="72" align="right" /></a></p>
<p>Yesterday, I revisited the page and came up with the following examples. I don&#8217;t think these samples are THAT bad, but can you decipher any of characters strings with 100% confidence? I doubt anyone can and I think this feat is well-known to be impossible.</p>
<p>Have a look at all the help one gets. For one, the &#8220;8 character&#8221; hint helps a lot. And if you are still stumped, a new CAPTCHA can be requested until one becomes answerable. And if that fails, take a whack at the audio version in order to validate being human.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image6.png"><img style="border-width: 0px; margin: 10px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image-thumb5.png" border="0" alt="image" width="244" height="72" align="right" /></a></p>
<p>Coding Horror had a nice write up on <a href="http://www.codinghorror.com/blog/archives/000712.html">CAPTCHA Effectiveness</a> a while back. The claim was that even the most basic, most ineffective form of CAPTCHA, &#8220;naive CAPTCHA&#8221; where the CAPTCHA term is the same every single time, stops 99.9% of content span.</p>
<p>Granted, these statements were written before Coding Horror had 103K subscribers. I suspect this was well before Coding Horror needed to be overly concerned with telling computers and humans apart, but I think the sentiment that CAPTCHA doesn&#8217;t need to overly inconvenience the user to be highly effective still applies.</p>
<p>I am not opposed to extreme CAPTCHA &#8212; especially when hints are provided &#8212; but the extra clicks and guesses bugs me enough to go into a useless rant about Y&#8217;s, I&#8217;s and J&#8217;s&#8230;</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image7.png"></a></p>
<p id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:a3f3894a-72fa-4f7f-95dd-66a85d90d5ef" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; display: inline"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/06/10/captcha-roulette/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/06/10/captcha-roulette/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image8.png"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/06/10/captcha-roulette/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Code Generation with Stored Procedures?</title>
		<link>http://johnnycoder.com/blog/2008/06/02/code-generation-with-stored-procedures/</link>
		<comments>http://johnnycoder.com/blog/2008/06/02/code-generation-with-stored-procedures/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 20:49:40 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Code Generation]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SubSonic]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/06/02/code-generation-with-stored-procedures/</guid>
		<description><![CDATA[I very recently posted about using SubSonic to generate my DAL and SSMS Tool Pack to generate the complementing stored procedures.  In response to the post, Jon Galloway asked a great question in the comments: Thanks for the pointer to SSMS Tool Packs. It looks really interesting. One thing I’m having trouble picturing is the [...]]]></description>
			<content:encoded><![CDATA[<p>I very recently posted about using <a href="http://johnnycoder.com/blog/2008/05/21/subsonic-and-ssms-tools-pack-saved-the-day/">SubSonic to generate my DAL and SSMS Tool Pack to generate the complementing stored procedures</a>.  In response to the post, <a href="http://weblogs.asp.net/jgalloway/">Jon Galloway</a> asked a great question in the comments:</p>
<blockquote><p>Thanks for the pointer to SSMS Tool Packs. It looks really interesting. One thing I’m having trouble picturing is the overlap between the two [SubSonic and SSMS Tool Pack]. Once you have a DAL, what do you need CRUD routines for? Bulk operations, or something that’s a result of the existing architecture?</p></blockquote>
<p>For those familiar with SubSonic you can appreciate Jon&#8217;s question.  Since SubSonic&#8217;s generated DAL provides you with CRUD methods and easily allows you build resulting parameterized queries, you are no longer dependent upon having compiled routines sitting in the database. </p>
<p>Almost on queue, Caffeinated Coder recently a great article on why one should &#8220;<a href="http://www.caffeinatedcoder.com/just-say-no-to-manual-crud/">Just Say No to Manual CRUD</a>&#8221; which provide a list of resources which present good counter arguments against the conventional stored proc wisdom.</p>
<p>So, why the heck am I still using stored procedures?</p>
<p>If I were to be honest, the number one reason I&#8217;m sticking with SPs is they are familiar and they provide me with a sense of comfort.  Most of my uneasiness with &#8220;embedding&#8221; data access into the application code is tied to deployment and maintenance.  For example, I like to have multiple &#8220;outs&#8221; when it comes to rollbacks and I like to keep emergency fixes as isolated as possible. Since stored procedures could be considered more atomic than even the most lightweight DLL, I can update a live application by altering a single stored procedure with more confidence than copying/replacing application file(s.)  Assuming you have a single database and a web application running on multiple web servers, in my opinion, the stored procedure update is best solution since time to implement is low, risk is minimal and downtime is eliminated. </p>
<p>I had a good follow up conversation with Jon about all of this last week and the bottom-line is that one needs to put the right architecture in place based on their coding, deployment and maintenance needs.  I am currently sticking with stored procedures but this approach isn&#8217;t necessarily right for everyone.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/06/02/code-generation-with-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Multiple Web Sites with Host Headers?</title>
		<link>http://johnnycoder.com/blog/2008/05/24/multiple-web-sites-with-host-headers/</link>
		<comments>http://johnnycoder.com/blog/2008/05/24/multiple-web-sites-with-host-headers/#comments</comments>
		<pubDate>Sat, 24 May 2008 14:41:17 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Hosting]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/05/24/multiple-web-sites-with-host-headers/</guid>
		<description><![CDATA[I woke up this morning (whew) wondering what percentage of the development community is privileged enough to deploy their own stuff.  I wonder because I think I&#8217;m out of touch in this area.  Over the past 6 or so years I&#8217;ve been handing off installation/deployment duties to other groups.  My development teams and I were [...]]]></description>
			<content:encoded><![CDATA[<p>I woke up this morning (whew) wondering what percentage of the development community is privileged enough to deploy their own stuff.  I wonder because I think I&#8217;m out of touch in this area.  Over the past 6 or so years I&#8217;ve been handing off installation/deployment duties to other groups.  My development teams and I were very involved in the release of our applications &#8212; sometimes to the point of executing the installation ourselves &#8212; but 95% of the time the actual server/network setup fell outside of our responsibility.  With my new position, things are very different.  Now, I&#8217;m pretty much responsible for everything and anything. </p>
<p>Last week, I setup a new web site.  This task included everything from registering the domain to getting the various instances of the site (for example, dev.site.com and qa.site.com) mapped to different IPs.  It was a &#8220;fun&#8221; exercise as it&#8217;s been forever since I needed to do this sort of thing.   In fact, it didn&#8217;t go super-smoothly the first time around as the host company didn&#8217;t apply the IP mapping appropriately.  Anyhow, I shared my woes with the former colleague and their response was something along the lines of &#8220;you know so much more about that stuff than I do.&#8221; </p>
<p>As it turns out, it was the Host Header Names reference which threw my colleague.  If you are in the same boat, Microsoft Internet Information Services (IIS) allows you to map multiple web sites with the same port number to a single IP address by using a feature called Host Header Names. By assigning a unique host header name to each web site, this feature allows you to map more than one web site to an IP address.  Knowing about Host Header Names can come in handy &#8212; especially if someone else isn&#8217;t always going to be doing your dirty work.</p>
<p>Back to my point: I was still a bit surprised by my buddy&#8217;s response, but then I thought it through.  In order to develop a .NET web site, one doesn&#8217;t even need to open IIS. Not ever. Not since 2.0 at least. And once the basic setup (domain registering, DNS entries, IIS configuration) is in place on the destination server, a .NET web site can be deployed through a mere file copy.  If you aren&#8217;t involved in the initial setup/install, a developer doesn&#8217;t need to know how to do anything other than how to code and copy files in order to maintain/enhance a live site.  Is it possible that a developer can get along perfectly well without having to know anything about web site deployment?</p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:cf177ab8-7ee3-48b5-91d4-7e3dfebc666d" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/05/24/multiple-web-sites-with-host-headers/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/05/24/multiple-web-sites-with-host-headers/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/05/24/multiple-web-sites-with-host-headers/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Hide Troubleshooting Info In The App Footer</title>
		<link>http://johnnycoder.com/blog/2008/02/09/hide-troubleshooting-info-in-the-app-footer/</link>
		<comments>http://johnnycoder.com/blog/2008/02/09/hide-troubleshooting-info-in-the-app-footer/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 04:35:03 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Tip and Tricks]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/02/09/hide-troubleshooting-info-in-the-app-footer/</guid>
		<description><![CDATA[Whenever I can get away with it, I include basic troubleshooting information in the footer of my web applications.  So it isn&#8217;t distracting (or blatantly exposed) to the standard user, the text is hidden.  In other words, I make the font color the same as the background color so the text is only visible when [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever I can get away with it, I include basic troubleshooting information in the footer of my web applications.  So it isn&#8217;t distracting (or blatantly exposed) to the standard user, the text is hidden.  In other words, I make the font color the same as the background color so <strong>the text is only visible when selected</strong>. </p>
<p>The hidden text is intended to give the developer basic information about the logged-in user, server and build as well as enough information to link the user&#8217;s session back to more detailed logs. </p>
<p>So, prior to a release to the Test Environment, I share the location of the hidden text with the QA <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/02/image2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 10px 0px 10px 10px; border-right-width: 0px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/02/image-thumb.png" border="0" alt="image" width="330" height="128" align="right" /></a>and UAT groups and request they include the information when writing up defects.  And once the application rolls to the Production Environment, the Help Desk and Stability Groups begin to leverage the information as well. </p>
<p>Even though the information is &#8220;hidden,&#8221; I am very particular/careful when it comes to the troubleshooting information which I present.  As a general rule, I only include information which would be harmless if &#8220;found&#8221; by anyone &#8212; including future auditors.  I use this technique with caution, but I do use it whenever I can.  I&#8217;ve found this &#8220;trick&#8221; very handy over the years and maybe now you will too.</p>
<p>Do you have any troubleshooting tips which can be shared?</p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:00c6c837-69a4-443a-b9c0-e1dd44d0e26f" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/02/09/hide-troubleshooting-info-in-the-app-footer/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/02/09/hide-troubleshooting-info-in-the-app-footer/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/02/09/hide-troubleshooting-info-in-the-app-footer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Mix DDL and DML</title>
		<link>http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/</link>
		<comments>http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 03:16:28 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/</guid>
		<description><![CDATA[I sat through an absolutely fantastic presentation on query optimization a couple of weeks back.  The presenter did a fine job of covering many of the basics like SET NOCOUNT ON, minimize cursor use, avoid explicit or implicit functions in the WHERE clause and why not to use the sp_ prefix when naming custom stored [...]]]></description>
			<content:encoded><![CDATA[<p>I sat through an absolutely fantastic presentation on query optimization a couple of weeks back.  The presenter did a fine job of covering many of the basics like <span style="color: #0000ff;">SET</span> NOCOUNT <span style="color: #0000ff;">ON</span>, minimize cursor use, avoid explicit or implicit functions in the <span style="color: #0000ff;">WHERE </span>clause and why not to use the sp_ prefix when naming custom stored procedures.  He also touched upon practices which are critical aspects of query optimization, yet, in my opinion, few put into practice. Specifically, he talked about the need for benchmarks and how to establish them.  He also demonstrated how to conduct sufficient testing.  Then there were the more advanced topics like table fragmentation, associated DBCC commands, Statistics IO, Fill Factor and how procedure cache works.  He also shared plenty of TSQL samples and how they will (or will not) use a given index.  For example, did you know the LIKE clause can use indexes if the pattern starts with a character string such as <span style="color: #0000ff;">WHERE</span> lname <span style="color: #808080;">LIKE</span> <span style="color: #ff0000;">&#8216;W%&#8217;</span> but LIKE cannot use an index if the pattern starts with a leading wildcard, such as <span style="color: #0000ff;">WHERE</span> lname <span style="color: #808080;">LIKE </span><span style="color: #ff0000;">&#8216;%wold&#8217;</span>?  Again, excellent presentation and did I mention it was wrapped up in under an hour? </p>
<p>I typically roll the dice with these types of presentation knowing they may turn out to be a refresher course, way over my head, or worse, an absolute bore.  This one was worth sitting through as I picked up the following nugget: <strong>Mixing DDL and DML Operations Can Cause a Recompile</strong>.</p>
<p>What does this mean?  DDL (Data Definition Language) and DML (Data Manipulation Language) almost always exists in our stored procedures.  Examples of DDL are our <span style="color: #0000ff;">DECLARE </span>variable and <span style="color: #0000ff;">CREATE</span> <span style="color: #0000ff;">TABLE </span>statements.  DML, on the other hand, includes our <span style="color: #0000ff;">SET</span><span style="color: #808080;">,</span> <span style="color: #0000ff;">SELECT </span>and <span style="color: #0000ff;">INSERT </span>to name a few.  A key cause of stored procedure recompiles is the interleaving of DML and DDL statements &#8212; especially DDL following DML statements.  In other words, according to Microsoft best practices, place all of your DDL statements at the top of your stored procedures and then do your actual query work. Now, are recompiles always going to happen if you have interleaved DDL and DML?  Nope, not in all case, but you should do everything possible to prevent recompiles (even if it is super easy.)</p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:7264d5d9-d6ce-4eb8-a333-4bdff3c2b4ed" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Rolling Back Refactored Code</title>
		<link>http://johnnycoder.com/blog/2006/12/14/rolling-back-refactored-code/</link>
		<comments>http://johnnycoder.com/blog/2006/12/14/rolling-back-refactored-code/#comments</comments>
		<pubDate>Thu, 14 Dec 2006 17:21:27 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2006/12/14/rolling-back-refactored-code/</guid>
		<description><![CDATA[My current project has me exercising a number of financial formulas on security and benchmark data. I have 2 &#8211; 3 sets of data which based on their type (benchmark or not) have varying calculations which set similar properties.  I won&#8217;t bore you with the details, but the calculations do require more than the four basic math operators.  In [...]]]></description>
			<content:encoded><![CDATA[<p>My current project has me exercising a number of financial formulas on security and benchmark data. I have 2 &#8211; 3 sets of data which based on their type (benchmark or not) have varying calculations which set similar properties.  I won&#8217;t bore you with the details, but the calculations do require more than the four basic math operators.  In addition, the sets are dependent upon each other.  For example, a start date common to each set needs to be determined and, in cases, benchmark results are leveraged in non-benchmark sets.   </p>
<p>Along with a test application, I&#8217;m going to be handing my code off to other developers and I really want the transition to be as seamless as possible.  To help out with this, I have spent some time creating my component in an intelligent, easy-to-use manner. (What?  I don&#8217;t always do this?) For example, I&#8217;ve opted to have my component simply accept whatever raw data is available.  The component will &#8220;clean&#8221; the data, determine the number of sets and types and process.  Most importantly, the results will then provided back using datatypes which I think are most suitable for consumption by the calling application. </p>
<p>I like the current architecture, but I had reservations with the way the calculations were coded.  As it turns out, a few of the calculations require the exact same logic.  For example, Formula A and Formula B might each loop through the last 10 years of quarterly return data.  Obviously, this had me wanting to combine some of my routines.  But as I refactored and refactored and refactored, I found my code was getting more and more and more obscure.  The logic was very difficult to understand (never mind read) and I wasn&#8217;t comfortable handing it off to others. </p>
<p>I&#8217;ve rolled back my refactored code.  I&#8217;ve blatantly abandoned refactoring in this case.  Instead, I&#8217;m keeping the code in logical blocks which I believe will aid in learning, extending and (gasp!) troubleshooting the component in the future.  Though I&#8217;m sure there would have been performance gains if I were to continue down the refactoring path, I&#8217;ve convinced myself that they would be subtle.   Perhaps I could have added ample (read: lots and lots) comments to accompany the obscure, refactored code, but I don&#8217;t think good code requires such measures. </p>
<p>I&#8217;m happy with my decision.  Now it&#8217;s time to finish up, hand off the code and wait for the new owners to laugh at its poor quality &#8212; of which they will hopefully understand and be able to manage every line.  We&#8217;ll see.</p>
<p>I should mention, I will be reworking some of my code.  Do yourself a favor.  If you know you are going to be performing anything other than basic math, don&#8217;t use decimals.  Use doubles instead.  Thanks to functions like Math.Pow() and Math.Sqrt(), I&#8217;ve been casting my brains out over the past couple of days and it is time I bite the bullet and change my datatypes.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/12/14/rolling-back-refactored-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Over 2,147,483,648 Users Served</title>
		<link>http://johnnycoder.com/blog/2006/11/19/over-2147483648-users-served/</link>
		<comments>http://johnnycoder.com/blog/2006/11/19/over-2147483648-users-served/#comments</comments>
		<pubDate>Sun, 19 Nov 2006 17:56:59 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Humor]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2006/11/19/over-2147483648-users-served/</guid>
		<description><![CDATA[Not so long ago, one of our applications failed when we tried to handle the 32,768th user entry. Though the database was able to manage the request, the application held onto the row&#8217;s identity in an Int16 property.  The overwhelming response to the error was &#8220;That was really, really dumb.&#8221;  I tend to agree on a couple of [...]]]></description>
			<content:encoded><![CDATA[<p>Not so long ago, one of our applications failed when we tried to handle the 32,768th user entry. Though the database was able to manage the request, the application held onto the row&#8217;s identity in an Int16 property.  The overwhelming response to the error was &#8220;That was really, really dumb.&#8221; </p>
<p>I tend to agree on a couple of accounts.  First and foremost, capacity/growth requirements should have been better measured (especially since the coders decided to go out of their way to use a data type other than the de facto standard Int32.)  Second, complementary data types should have been used in SQL Server and the C# code. </p>
<p>Understandably, the coders were embarrassed, but the problem was quickly remedied with very little damage done.</p>
<p>Possibly triggered by a recent article I read, this morning I got to thinking, &#8220;What if it wasn&#8217;t an Int16?  What if the system failed because the coders were <em>only</em> using an Int32?&#8221;  I have to think that any acknowledgement that your application has handled over a two billion entries would be welcome &#8212; even if it comes in the form of a system failure.  </p>
<p>How&#8217;s that for looking at the bright side?</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/11/19/over-2147483648-users-served/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Coding Standards &#8211; The Devil Is In The Details</title>
		<link>http://johnnycoder.com/blog/2006/11/03/coding-standards-the-devil-is-in-the-details/</link>
		<comments>http://johnnycoder.com/blog/2006/11/03/coding-standards-the-devil-is-in-the-details/#comments</comments>
		<pubDate>Fri, 03 Nov 2006 19:55:30 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Management]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2006/11/03/coding-standards-the-devil-is-in-the-details/</guid>
		<description><![CDATA[A couple of years back, I was tasked with compiling C# coding standards for our development department.  To be honest, I wasn&#8217;t all that excited about the assignment.  Previous attempts had been met with quite a bit of resistance and worthless debate and I wasn&#8217;t sure I really wanted to open that can of worms again.  After [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of years back, I was tasked with compiling C# coding standards for our development department.  To be honest, I wasn&#8217;t all that excited about the assignment.  Previous attempts had been met with quite a bit of resistance and worthless debate and I wasn&#8217;t sure I really wanted to open that can of worms again.  After all, I felt that we had built a talented team of developers who saw eye-to-eye on most &#8220;technical things&#8221; so why bother getting everyone riled up? As you know, there are many legitimate reasons for &#8220;getting everyone riled up.&#8221;  In our case, there were two very good reasons which made my assignment somewhat mandatory:</p>
<ol>
<li>We had plans to greatly expand the size of our group in the very near future and documented standards would help get the newbies up-to-speed quickly.</li>
<li>Our group&#8217;s technical roadmap was becoming more defined (heck, it was taking a turn with SOA) and there were embracing a number of technical advances such as .NET 2.0, Remoting and AJAX and we needed to ensure the existing staff on the same page. </li>
</ol>
<p>Ultimately, I accepted the challenge and standards were put in place with very little blood shed.  Of course, I took a few measure to ensure that mud-slinging and stone-throwing was kept to a minimum.First, I anticipated the pain and I didn&#8217;t let it happen. To accomplish this, I guess I was a bit evasive.  I didn&#8217;t solicit any help or opinions at first.  I did endless online searches and I consulted a few books, but I avoided internal roundtable discussions. I also decided to wait until the documentation was rather polished before requesting any feedback. Once I did seek feedback, I kept participant counts low.  In fact, only a handful of our technical leaders were invited to the review before distributing before the document was distributed to the entire development group.</p>
<p>Second, it was established early on that there would be difference of opinion and this was okay.  Actually, it was almost encouraged, but we all (non-verbally) agreed to keep our egos out of the debate.  This ultimately lead to us coming to a common ground or simply opting to &#8220;choose our battles&#8221; and accept that we wouldn&#8217;t always get what we wanted.  This, in conjunction with everyone knowing their feedback was valued and respected, kept our conversations on track.  Also if a topic got at all heated, we quickly moved onto something else in an effort to stay focused, to keep moving forward and keep everyone happy.</p>
<p>Most importantly, however, we didn&#8217;t sweat the small stuff.  If you have been responsible for documenting <span style="text-decoration: underline;">agreed upon</span> standards, you know what I&#8217;m talking about.  Developers tend to spend just as much time hashing out the small stuff as they do the big stuff.  When it comes to establishing your team&#8217;s coding guidelines, <strong>the devil is in the details</strong>.  The classic example is code formatting.  &#8220;Which case are we going to use? Camel or Pascal or both?&#8221;  &#8220;Is Hungarian notation really dead because there is still a lot of merit in using it for form elements?&#8221; &#8220;Should we prefix private property names with underscores?&#8221; &#8220;We will use curly braces within our if-else statements even if the conditions are only a single line, right?&#8221; &#8220;How many spaces are we going to agree to indent?  Please assure me that no one indents using spaces!  Everyone better be using the Tab key!&#8221;  There are about a million distracting, time-consuming, worthless arguments which one can have about code formatting (and other similar topics) but they provide little value. These debates can suck the life out of an initiative so beware.</p>
<p>I think I got lucky on my third point. To some extend, our development focus had been rapidly changing over the past few years and the individuals helping to define our standards were now interested in the big picture.  Perhaps we felt we had &#8220;better things&#8221; to discuss or maybe we had all learned from our past and we knew the danger of  &#8220;the details.&#8221;  In any case, we concentrate on the big ticket items like namespacing, data access and logging.  We traded in the time we would have given to meaningless debates and we put frameworks and templates in place.    </p>
<p>Whatever your reason, it is important to have standards.  Do yourself a favor.  When it comes time to defining your own, avoid the details.  Otherwise, prepare for a battle which nobody wins and nothing gets done.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/11/03/coding-standards-the-devil-is-in-the-details/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Take Advantage of Application Name</title>
		<link>http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/</link>
		<comments>http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/#comments</comments>
		<pubDate>Tue, 24 Oct 2006 07:44:21 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/</guid>
		<description><![CDATA[Along with the SQL Server, Database, Username and Password, don&#8217;t forget to include the Application Name in your connection string.  It&#8217;s an optional parameter, but it can be a lifesaver.       Data Source=myServer;      Initial Catalog=myDB;      User Id=myUsername;      Password=myPassword;      Application Name=myApp; Consider this example:  There are multiple .NET applications running on a single web server.  Each application [...]]]></description>
			<content:encoded><![CDATA[<p>Along with the SQL Server, Database, Username and Password, don&#8217;t forget to include the Application Name in your connection string.  It&#8217;s an optional parameter, but it can be a lifesaver. </p>
<p><em>     Data Source=myServer;<br />
     Initial Catalog=myDB;<br />
     User Id=myUsername;<br />
     Password=myPassword;<br />
     <strong>Application Name=myApp;</strong></em></p>
<p>Consider this example:  There are multiple .NET applications running on a single web server.  Each application shares a common SQL Server Server which is suddenly performing very poorly.   You are tasked with determine which of the applications is causing havoc.  You launch SQL Profiler and run a trace.  Since you have included the optional parameter in your connection string, you may now filter the application specific queries and troubleshoot the problem far more effectively.  If you hadn&#8217;t specified the application name, you would have some work ahead of you.  In this case, all of the queries would have had a generic app name, <em>.NET sqlClient Data Provider</em>, and that isn&#8217;t very helpful, is it?  </p>
<p>Do yourself a favor and be sure to add this practice to your coding standards&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Poor Performance with DateTime.Parse()</title>
		<link>http://johnnycoder.com/blog/2006/10/18/poor-performance-with-datetimeparse/</link>
		<comments>http://johnnycoder.com/blog/2006/10/18/poor-performance-with-datetimeparse/#comments</comments>
		<pubDate>Wed, 18 Oct 2006 22:42:47 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Samples]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/?p=55</guid>
		<description><![CDATA[We traced a performance bottleneck to a single function recently. Interestingly enough, this function has been in existence (running in a production environment in all of its glory) for roughly 4 years now. Only now that we are required to execute the offending piece of code approximately 10 million times within a short four hour [...]]]></description>
			<content:encoded><![CDATA[<p>We traced a performance bottleneck to a single function recently. Interestingly enough, this function has been in existence (running in a production environment in all of its glory) for roughly 4 years now. Only now that we are required to execute the offending piece of code approximately 10 million times within a short four hour window has the problem actually surfaced.Our function has about 100 LOC. It contains custom collection class references, string manipulation, financial calculations and numerous other operations which I would flag as suspicious. We successfully avoided performance counters and simply stepped through the code after ensuring we had set an adequate number of timespan variables to track execution times the old fashion way. As it works out, DateTime.Parse we the bottleneck and our simple logic to determine is IsDate() or IsDatePast() might as well have been the most complicated, resource-eating routines on the planet.Why was this? Well, the Parse method tries very hard to make sense of the string thatâ€™s passed to it in order to create a valid DateTime value. It ignores leading and trailing white space, and unrecognized characters if possible, and it fills in missing information with the corresponding current date and time values. Parse <em>will</em> throw a FormatException if itâ€™s unable to decipher the string you send to it, but otherwise, it bends over backwards for you. Our guess is it tries to do too much for its own good and exhausts itself in the process.We tried to replace the Parse method with the <em>other</em> DateTime static method â€” ParseExact â€” but it didnâ€™t provide much relief.In the end, we got creative. We opted to create a simple function which first instantiates a new DateTime reference by using the month, day and year from the string representation of the date. (We were lucky because we knew this string would either be in the MM/DD/YYYY format or emtpy.)  Would you believe that splitting our string and then constructing a new DateTime reference performed considerably better than using the standard DateTime.Parse method?  Well, it did.</p>
<div class="csharpcode"><span class="lnum">1: </span><span class="rem">///&lt;summary&gt; </span><span class="lnum">2: </span><span class="rem">///Do not rely on the DateTime.Parse() method </span><span class="lnum">3: </span><span class="rem">///Check if date is in the past by splitting string, </span><span class="lnum">4: </span><span class="rem">///building datetime object then compare against today </span><span class="lnum">5: </span><span class="rem">///&lt;/summary&gt; </span><span class="lnum">6: </span><span class="rem">///&lt;param name=&#8221;sDate&#8221;&gt;Date to Check&lt;/param&gt; </span><span class="lnum">7: </span><span class="rem">///&lt;returns&gt;False if greater than today&lt;/returns&gt;</span><span class="lnum">8: </span><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">bool</span> IsDatePastParse(<span class="kwrd">string</span> sDate) <span class="lnum">9: </span>{ <span class="lnum">10: </span><span class="kwrd">try</span> <span class="lnum">11: </span>{ <span class="lnum">12: </span><span class="kwrd">if</span> (sDate.Length &gt; 0) <span class="lnum">13: </span>{ <span class="lnum">14: </span><span class="kwrd">string</span>[] dt = sDate.Split(<span class="str">&#8216;/&#8217;</span>); <span class="lnum">15: </span><span class="kwrd">return</span> IsDatePast(<span class="lnum">16: </span><span class="kwrd">new</span> DateTime(Convert.ToInt32(dt[2]), <span class="lnum">17: </span>Convert.ToInt32(dt[0]),<span class="lnum">18: </span>Convert.ToInt32(dt[1])));<span class="lnum">19: </span>} <span class="lnum">20: </span><span class="kwrd">else</span> <span class="lnum">21: </span>{<span class="lnum">22: </span><span class="rem">// Invalid if no date is passed </span><span class="lnum">23: </span><span class="kwrd">return</span> <span class="kwrd">false</span>; <span class="lnum">24: </span>} <span class="lnum">25: </span>} <span class="lnum">26: </span><span class="kwrd">catch</span> <span class="lnum">27: </span>{ <span class="lnum">28: </span><span class="rem">// Assume the string was an invalid date</span><span class="lnum">29: </span><span class="kwrd">return</span> <span class="kwrd">false</span>; <span class="lnum">30: </span>} <span class="lnum">31: </span>} <span class="lnum">32: </span> <span class="lnum">33: </span><span class="rem">///&lt;summary&gt; </span><span class="lnum">34: </span><span class="rem">///Has the date past? Compare against today&#8217;s date. </span><span class="lnum">35: </span><span class="rem">///&lt;/summary&gt; </span><span class="lnum">36: </span><span class="rem">///&lt;param name=&#8221;dtDate&#8221;&gt;Date to Check&lt;/param&gt; </span><span class="lnum">37: </span><span class="rem">///&lt;returns&gt;False if date is in the past&lt;/returns&gt;</span><span class="lnum">38: </span><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">bool</span> isDatePast(DateTime dtDate) <span class="lnum">39: </span>{ <span class="lnum">40: </span><span class="rem">// Consider today in the past</span><span class="lnum">41: </span><span class="kwrd">if</span> (DateTime.Today.Date &gt;= dtDate.Date) <span class="lnum">42: </span><span class="kwrd">return</span> <span class="kwrd">true</span>; <span class="lnum">43: </span><span class="kwrd">else</span> <span class="lnum">44: </span><span class="kwrd">return</span> <span class="kwrd">false</span>; <span class="lnum">45: </span>} </div>
<p><!-- .csharpcode { 	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff } .csharpcode pre { 	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff } .csharpcode pre { 	margin: 0em } .csharpcode .rem { 	color: #008000 } .csharpcode .kwrd { 	color: #0000ff } .csharpcode .str { 	color: #006080 } .csharpcode .op { 	color: #0000c0 } .csharpcode .preproc { 	color: #cc6633 } .csharpcode .asp { 	background-color: #ffff00 } .csharpcode .html { 	color: #800000 } .csharpcode .attr { 	color: #ff0000 } .csharpcode .alt { 	margin: 0em; width: 100%; background-color: #f4f4f4 } .csharpcode .lnum { 	color: #606060 } --><!-- .csharpcode { 	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff } .csharpcode pre { 	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff } .csharpcode pre { 	margin: 0em } .csharpcode .rem { 	color: #008000 } .csharpcode .kwrd { 	color: #0000ff } .csharpcode .str { 	color: #006080 } .csharpcode .op { 	color: #0000c0 } .csharpcode .preproc { 	color: #cc6633 } .csharpcode .asp { 	background-color: #ffff00 } .csharpcode .html { 	color: #800000 } .csharpcode .attr { 	color: #ff0000 } .csharpcode .alt { 	margin: 0em; width: 100%; background-color: #f4f4f4 } .csharpcode .lnum { 	color: #606060 } --><!-- .csharpcode { 	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff } .csharpcode pre { 	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff } .csharpcode pre { 	margin: 0em } .csharpcode .rem { 	color: #008000 } .csharpcode .kwrd { 	color: #0000ff } .csharpcode .str { 	color: #006080 } .csharpcode .op { 	color: #0000c0 } .csharpcode .preproc { 	color: #cc6633 } .csharpcode .asp { 	background-color: #ffff00 } .csharpcode .html { 	color: #800000 } .csharpcode .attr { 	color: #ff0000 } .csharpcode .alt { 	margin: 0em; width: 100%; background-color: #f4f4f4 } .csharpcode .lnum { 	color: #606060 } --></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/10/18/poor-performance-with-datetimeparse/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Why Don&#8217;t We Handle Exceptions</title>
		<link>http://johnnycoder.com/blog/2006/10/17/why-dont-we-handle-exceptions/</link>
		<comments>http://johnnycoder.com/blog/2006/10/17/why-dont-we-handle-exceptions/#comments</comments>
		<pubDate>Tue, 17 Oct 2006 16:59:00 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Management]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/?p=57</guid>
		<description><![CDATA[Exception handling is extremely important, isn&#8217;t it? When it comes to testing, troubleshooting and maintenance it is paramount. Exception handling is definitely highlighted on every developers list of application technical requirements. So, why don&#8217;t all applications have proper exception handling? I have a few ideas. The first and most likely reason is most developers (no [...]]]></description>
			<content:encoded><![CDATA[<p>Exception handling is extremely important, isn&#8217;t it? When it comes to testing, troubleshooting and maintenance it is paramount. Exception handling is definitely highlighted on every developers list of application technical requirements. So, why don&#8217;t all applications have proper exception handling? I have a few ideas.</p>
<p>The first and most likely reason is most developers (no matter how experienced) don&#8217;t have a good understanding of how to do it. This operation may seem trivial to some, but it actually takes a good amount of attention and care to do correctly. Granted, in many cases it&#8217;s perfectly fine to simply wrap the contents of a function with a &#8220;generic&#8221; try/catch block and merely bubble the exception up to its caller. Great. But what does the caller do with the exception? Nine out of ten times the caller, in turn, will also bubble the exception up (because that&#8217;s what the &#8220;pattern&#8221; does) or it swallows it. Even if a coder uses this bare bones approach, there are usually issues with the implementation. For example, there is a big difference between <em>throw;</em> and <em>throw ex;</em>. The difference is that <em>throw;</em> preserves the original stack trace and <em>throw ex;</em> truncates the stack trace below the method in which the <em>throw ex;</em> call is located. Most of the time, <em>throw ex;</em> is inappropriately. There are many other examples of poor exception handling, but here&#8217;s my favorite &#8212; the coder does everything &#8220;by the book&#8221; until it is time to display a error page and a coder reveals the exception details including secure information such as connection strings to the user. Yikes! Not understand proper exception handling can be dangerous.</p>
<p>The second reason is priority and timeline. Exception handling isn&#8217;t sexy and, let&#8217;s be honest, it doesn&#8217;t need to be in place before an application can be deployed. Hence, exception handling is usually pushed to the backburner &#8212; along with technical documentation. Only once the application requires future troubleshooting do we feel the pain of the missing &#8220;requirement.&#8221; Interesting enough, a colleague of mine now waits until his code base is quite stable to implement his error handling. He does this without regard for priority and timeline. He&#8217;d prefer to have his application assume unnecessary fatal errors early on it the project lifecycle rather than mask the issues through improper exception handling. All the same, timeline is still a standard developer excuse for lack of error handling.</p>
<p>The third reason is ego. Aren&#8217;t we all a little guilty of thinking our code can&#8217;t fail? After all, we can&#8217;t have a bunch of coders with defeatist-attitudes working on our projects. <img src='http://johnnycoder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Without the safety net of exception handling, we are bound to write better code, right? (Of course, this argument doesn&#8217;t hold a lot of water since it would promote getting rid of the QA team if we wanted really good code.) I do think ego is a factor though, but I&#8217;m not sure to what extent.</p>
<p>That&#8217;s my take on exception handling. What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/10/17/why-dont-we-handle-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improve String Management with StringBuilder</title>
		<link>http://johnnycoder.com/blog/2006/08/09/improve-string-management-with-stringbuilder/</link>
		<comments>http://johnnycoder.com/blog/2006/08/09/improve-string-management-with-stringbuilder/#comments</comments>
		<pubDate>Wed, 09 Aug 2006 22:17:00 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/?p=54</guid>
		<description><![CDATA[Strings are immutable. In other words, a string can not be changed once assigned. When you append a string to an existing string, the .NET framework actually creates a new string containing the original string and the appended string. This is a resource-hungry and time-consuming process. The alternative to appending strings, is the StringBuilder class [...]]]></description>
			<content:encoded><![CDATA[<p>Strings are immutable. In other words, a string can not be changed once assigned. When you append a string to an existing string, the .NET framework actually creates a new string containing the original string and the appended string. This is a resource-hungry and time-consuming process.</p>
<p>The alternative to appending strings, is the StringBuilder class which is somewhat hidden in the System.Text namespace. The class is faster because it allocates an initial space when an instance of it is created. By default, a StringBuilder object created using the StringBuilder class default constructor reserves a space of 16 characters in memory. This default can be overloaded.</p>
<p>Generally, the recommended cutoff number is five. If you have more than five separate string concatenations, StringBuilder is generally more efficient than appending the strings.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/08/09/improve-string-management-with-stringbuilder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Convert ToString with Caution</title>
		<link>http://johnnycoder.com/blog/2006/08/04/convert-tostring-with-caution/</link>
		<comments>http://johnnycoder.com/blog/2006/08/04/convert-tostring-with-caution/#comments</comments>
		<pubDate>Fri, 04 Aug 2006 19:48:00 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/?p=52</guid>
		<description><![CDATA[Assume we have a datarow field, name, which evaluates to null. What is the result of the following two cases? CASE A string name = Convert.ToString(dr["name"]); CASE B string name = dr["name"].ToString(); In the first case, Convert.ToString() will evaluate to null. In the second case, however, .ToString() will throw an exception. And it makes sense, [...]]]></description>
			<content:encoded><![CDATA[<p>Assume we have a datarow field, name, which evaluates to null. What is the result of the following two cases?</p>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr"><p><strong>CASE A<br />
</strong>string name = Convert.ToString(dr["name"]);</p>
<p><strong>CASE B</strong><br />
string name = dr["name"].ToString();</p></blockquote>
<p>In the first case, Convert.ToString() will evaluate to null. In the second case, however, .ToString() will throw an exception. And it makes sense, doesn&#8217;t it? After all, &#8220;nothing&#8221; doesn&#8217;t have a ToString() function to execute!</p>
<p>So, do yourself a favor and use object.ToString() sparingly. Use is only when using non-null values. In cases where null is a possibility, use Convert.ToString().</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/08/04/convert-tostring-with-caution/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Short-circuit Operators in C#</title>
		<link>http://johnnycoder.com/blog/2006/08/02/short-circuit-operators-in-c/</link>
		<comments>http://johnnycoder.com/blog/2006/08/02/short-circuit-operators-in-c/#comments</comments>
		<pubDate>Wed, 02 Aug 2006 17:21:00 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/?p=51</guid>
		<description><![CDATA[Do you know how to short-circuit operators? In C#, And (&#38;) and Or (&#124;) operators evaluate both boolean expressions in the statement. However, the &#38;&#38; operator only evaluates the first Boolean if false and the &#124;&#124; operator only evaluates the first Boolean if true. This technique prevents the execution of the second expression if unnecessary [...]]]></description>
			<content:encoded><![CDATA[<p>Do you know how to short-circuit operators? In C#, And (&amp;) and Or (|) operators evaluate both boolean expressions in the statement. However, the &amp;&amp; operator only evaluates the first Boolean if false and the || operator only evaluates the first Boolean if true. This technique prevents the execution of the second expression if unnecessary &#8212; therefore optimizing your logic.</p>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr"><p>//Avoid:<br />
if (_username ==&#8221;" &amp; _password == &#8220;&#8221;)<br />
{<br />
&#8230;<br />
}</p>
<p>//Correct:<br />
if (_username == &#8220;&#8221; &amp;&amp; _password == &#8220;&#8221;)<br />
{<br />
&#8230;<br />
}</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/08/02/short-circuit-operators-in-c/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

