<?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>.Net Smoothie &#187; Design</title>
	<atom:link href="http://www.richardbushnell.net/tag/design/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.richardbushnell.net</link>
	<description></description>
	<lastBuildDate>Wed, 30 Dec 2009 11:42:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Design Guidelines for LINQ</title>
		<link>http://www.richardbushnell.net/2008/03/13/design-guidelines-for-linq/</link>
		<comments>http://www.richardbushnell.net/2008/03/13/design-guidelines-for-linq/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 18:40:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Guidelines]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/13/design-guidelines-for-linq/</guid>
		<description><![CDATA[Have you wondered if and when you should use the new LINQ features in .Net 3.5? Like, where should I put a new extension method? Should I use Func&#60;T&#62; or a custom delegate? How do I best implement a mix-in (extension methods on an interface)? Well, Mircea Trofin has just published a new draft of [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F03%2F13%2Fdesign-guidelines-for-linq%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>Have you wondered if and when you should use the new LINQ features in .Net 3.5?</p>
<p>Like, where should I put a new extension method? Should I use Func&lt;T&gt; or a custom delegate? How do I best implement a mix-in (extension methods on an interface)?</p>
<p>Well, Mircea Trofin has just published a new draft of some <a href="http://blogs.msdn.com/mirceat/archive/2008/03/13/linq-framework-design-guidelines.aspx" target="_blank">LINQ design guidelines</a>. You might just find your answers there.</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F03%2F13%2Fdesign-guidelines-for-linq%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/03/13/design-guidelines-for-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net MVC Corollary &#8211; What to do?</title>
		<link>http://www.richardbushnell.net/2008/01/28/aspnet-mvc-corollary-what-to-do/</link>
		<comments>http://www.richardbushnell.net/2008/01/28/aspnet-mvc-corollary-what-to-do/#comments</comments>
		<pubDate>Mon, 28 Jan 2008 03:50:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[SubSonic]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/01/28/aspnet-mvc-corollary-what-to-do/</guid>
		<description><![CDATA[Dude! I got quoted! And by none other than Rob Conery of SubSonic fame. It seems like my last post caused quite an unexpected stir. Thanks to both Rob and Scott for taking the time to answer me. I really appreciate it. A Word of Appreciation Let&#8217;s get something in perspective. Rob has actually produced [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F01%2F28%2Faspnet-mvc-corollary-what-to-do%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>Dude! I got <a href="http://blog.wekeroad.com/2008/01/25/ramble-aspnet-mvc-is-a-geek-chisel/" target="_blank">quoted</a>! And by none other than Rob Conery of SubSonic fame.</p>
<p>It seems like my <a href="http://richardbushnell.net/index.php/2008/01/25/does-the-aspnet-mvc-framework-frustrate-you/" target="_blank">last post</a> caused quite an unexpected stir. Thanks to both <a href="http://blog.wekeroad.com/2008/01/25/ramble-aspnet-mvc-is-a-geek-chisel/" target="_blank">Rob</a> and <a href="http://www.hanselman.com/blog/" target="_blank">Scott</a> for taking the time to answer me. I really appreciate it.<br />
<span id="more-43"></span></p>
<h2>A Word of Appreciation</h2>
<p>Let&#8217;s get something in perspective. Rob has actually <em>produced</em> something of immense value with SubSonic. I have just <em>complained </em>about it. Rob could very easily have just hammered me down, but he didn&#8217;t. Thanks, Rob.</p>
<p>Scott too.</p>
<p>In the <a href="http://www.hanselman.com/blog/HanselminutesPodcast98RaisingGeeksWithScottsDad.aspx" target="_blank">last episode of his most excellent podcast</a>, Scott said to his Dad that he likes to stir things up. &#8220;Presenting options&#8221; was the phrase I think he used. In that case, we are two peas in a pod. I <em>always</em> like to ask questions. If my question uncovers an unjustified assumption, things usually get better. If I&#8217;m wrong, then at least I come out knowing why I was wrong and understand the problem better.</p>
<p>While studying for my physics degree, I was asked to give feedback for a course on &#8220;Cosmic Dust&#8221;. I commented that it was just a completely pointless course. I mean, why waste 12 weeks of lectures studying the invisible dust floating around in space? Instead of numbing our brains with such useless information, we could have been learning something much more relevant. That particular comment, although made privately, really stirred up the lecturer. He got quite mad actually. He even wrote a long letter to the students with his  reasoning for why cosmic dust was so important. That itself was unprecedented. No lecturer had ever given us feedback to our feedback before.</p>
<p>Not much changed in the end, but at least I came out of it understanding more about what I&#8217;d been doing. Maybe that will happen with ASP.Net MVC.</p>
<p>So thanks to both of you for taking me seriously.</p>
<h2>How Dare They!</h2>
<p>Last month I watched a documentary about J.K. Rowling. It followed her as she completed and published the 7th and final Harry Potter book. It was the fasting selling book of all time. Truly amazing. But what amazed me most about the whole documentary was a comment made by two girls who had been queuing all night to get their copy of the book:</p>
<blockquote><p>&#8220;Finally! We&#8217;ve been waiting 10 years for this!&#8221;</p></blockquote>
<p>The remark was made with a tinge of disgust. It was as if the author had no right to take such a long time writing the book. How dare Mrs Rowling take so much time to finish her book while they had to suffer while sitting around waiting for it. How inconvenient for them! How inconsiderate of Mrs Rowling!</p>
<p>I thought, &#8220;if you wanted the book so much, why didn&#8217;t you write your own?&#8221;</p>
<p>In that spirit, I&#8217;m going to try to do something about the ASP.Net MVC thing myself. I don&#8217;t want to be that kind of person that complains but does nothing.</p>
<h2>Wait! There&#8217;s a baby in that bath-water!</h2>
<p>I read <a href="http://blog.wekeroad.com/2008/01/25/ramble-aspnet-mvc-is-a-geek-chisel/" target="_blank">Rob&#8217;s readers&#8217; comments</a>, and I think that it doesn&#8217;t require a full rewrite of ASP.Net to do what they want. In fact, I already wrote a bit of code, modeled loosely on <a href="http://www.djangoproject.com/documentation/templates/" target="_blank">Django templates</a>, which allows an ASP.Net developer to control the page output pretty much the same way as MVC promises to do. I&#8217;ll have to dig the code out of its hiding place, but then I plan to integrate it with a small Model-View-Presenter framework (a couple of generic base-classes for a Page and Presenter) which will enable a much better way for writing pages than the normal ASP.Net pages do. It also allows full testing of the controlling code.</p>
<p>And better yet, the MVP stuff is based on a refactored and simplified version of some Patterns and Practices code. (Yaaay, we can all be happy together!)</p>
<p>I&#8217;ve used this pattern, and each Presenter class is usually a few lines long. My ASP.Net page only contains presentation logic, i.e. stuff to render the page and retrieve input. I don&#8217;t need a controller nor a completely new framework to do it. In fact, a Controller class would be much worse, IMHO, because Controllers contain the code for more than one concern &#8211; a list page, an edit page, a delete page, etc. (I think that those things could be pragmatically abstracted and made easier anyhow, but that&#8217;s another story.) I personally prefer to keep my concerns separate.</p>
<p>And I&#8217;m not the only one who likes MVP. <a href="http://weblogs.asp.net/craigshoemaker/archive/2007/12/06/podcast-asp-net-mvc-and-the-future-of-model-view-presenter-interview-with-jeffery-palermo.aspx" target="_blank">Craig Shoemaker</a> does too.</p>
<p>So here&#8217;s my plan: I&#8217;ll try to publish some ideas and persuade you all to use them. Then I&#8217;ll get Microsoft to take Routes, Controllers, and whatever other goodies they&#8217;ve got in ASP.Net MVC, and put them in the next full-blown version of ASP.Net. Then everyone can use them and we can carry on with life as normal. I won&#8217;t have to use UrlRewriter to do my Routing any more and Microsoft can go back and finish off Workflow Foundation, ASP.Net Ajax, and Patterns and Practices.</p>
<p>Well, that&#8217;s the plan, anyway.</p>
<p>(I&#8217;ve just got to tidy up some of my code before I publish it. Give me a moment&#8230;)</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F01%2F28%2Faspnet-mvc-corollary-what-to-do%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/01/28/aspnet-mvc-corollary-what-to-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using LinqPad to Create a Time-Selector Drop-Down List</title>
		<link>http://www.richardbushnell.net/2008/01/18/using-linqpad-to-create-a-time-selector-drop-down-list/</link>
		<comments>http://www.richardbushnell.net/2008/01/18/using-linqpad-to-create-a-time-selector-drop-down-list/#comments</comments>
		<pubDate>Fri, 18 Jan 2008 17:47:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[LinqPad]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/01/18/using-linqpad-to-create-a-time-selector-drop-down-list/</guid>
		<description><![CDATA[I am really getting into LINQ now! I think it&#8217;s fantastic. I recently wanted to develop a quick drop-down list in ASP.Net which allows a user to select a time of day from a list. The times are 15 minutes apart, so the list would look like this: &#8230; 08:00 08:15 08:30 08:45 09:00 &#8230; [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F01%2F18%2Fusing-linqpad-to-create-a-time-selector-drop-down-list%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>I am <em>really </em>getting into LINQ now! I think it&#8217;s fantastic. I recently wanted to develop a quick drop-down list in ASP.Net which allows a user to select a time of day from a list. The times are 15 minutes apart, so the list would look like this:</p>
<p>&#8230;<br /> 08:00<br /> 08:15<br /> 08:30<br /> 08:45<br /> 09:00<br /> &#8230;</p>
<p>&#8230; and so on.</p>
<p>Before LINQ, I would have done this with a for loop, like this:</p>
<pre class="code"><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt; times = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;();
<span style="color: blue">for </span>(<span style="color: blue">int </span>hour = 0; hour &lt; 24; hour++)
  <span style="color: blue">for </span>(<span style="color: blue">int </span>minute = 0; minute &lt; 60; minute++)
    <span style="color: blue">if </span>(minute % 15 == 0)
       times.Add(<span style="color: blue">string</span>.Format(
         <span style="color: #a31515">"{0:00}:{1:00}"</span>, hour, minute));</pre>
<p>That&#8217;s not difficult, although it&#8217;s not so easy to understand. I would have to write a small console app or test to make sure I had done it correct though.</p>
<p>I thought this might be a good opportunity to use <a href="http://www.linqpad.net" target="_blank">LinqPad</a>. It&#8217;s a great tool. You can use it to test a LINQ statement in a live window, so I thought I&#8217;d give it a go.</p>
<p>First I needed a LINQ statement to test.</p>
<p><span id="more-36"></span></p>
<h2>Designing the LINQ Statement</h2>
<p>The first thing I needed was an integer for the hour. That&#8217;s quite easy, especially if you use the Range Extension Method technique as I wrote about before. That method allows you to create an IEnumerable&lt;int&gt; from a simple statement, like 1.To(10). So to get the hours of the day, I can simply start with:</p>
<pre class="code"><span style="color: blue">from </span><span style="color: black">hour </span><span style="color: blue">in </span><span style="color: #c81efa">0</span><span style="color: black">.To(</span><span style="color: #c81efa">23</span><span style="color: black">)</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Now I need to do a cross-join with the minutes. In C# comprehension syntax, you do that by simply adding another <font color="#0000ff">from</font> statement. At first, I thought I could do it by using an enumeration of minutes, specifying each value I wanted specifically. To do that I wrote this:</p>
<pre class="code"><span style="color: blue">from </span><span style="color: black">hour </span><span style="color: blue">in </span><span style="color: #c81efa">0</span><span style="color: black">.To(</span><span style="color: #c81efa">23</span><span style="color: black">)
</span><span style="color: blue">from </span><span style="color: black">minute </span><span style="color: blue">in new</span><span style="color: black">[] {</span><span style="color: #c81efa">0</span><span style="color: black">, </span><span style="color: #c81efa">15</span><span style="color: black">, </span><span style="color: #c81efa">30</span><span style="color: black">, </span><span style="color: #c81efa">45</span><span style="color: black">}</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>That works very nicely. I think it&#8217;s easy to understand too. Even if you were going to come back to it years from now, you could still easily see what is being done.</p>
<p>Another alternative is to do the same as the <font color="#0000ff">for</font> statement above, go through the numbers 0 to 59, selecting only those which are divisible by 15. You would do that using another range and a filter:</p>
<pre class="code"><span style="color: blue">from </span><span style="color: black">hour </span><span style="color: blue">in </span><span style="color: #c81efa">0</span><span style="color: black">.To(</span><span style="color: #c81efa">23</span><span style="color: black">)
</span><span style="color: blue">from </span><span style="color: black">minute </span><span style="color: blue">in </span><span style="color: #c81efa">0</span><span style="color: black">.To(</span><span style="color: #c81efa">59</span><span style="color: black">)
</span><span style="color: blue">where </span><span style="color: black">minute % </span><span style="color: #c81efa">15 </span><span style="color: black">== </span><span style="color: #c81efa">0</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Again, I like the way this looks. Another developer should have no difficulty reading that.</p>
<p>To select the string, we will also use the same format as before, this time using the <font color="#0000ff">select</font> keyword:</p>
<pre class="code"><span style="color: blue">select string</span><span style="color: black">.Format(</span><span style="color: #dc1414">"{0:00}:{1:00}"</span><span style="color: black">, hour, minute)</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>You then simply assign the value of this statement to a variable, like this:</p>
<pre class="code"><span style="color: blue">var </span>times = <span style="color: blue">from </span>hour <span style="color: blue">in </span>0.To(23)
            <span style="color: blue">from </span>minute <span style="color: blue">in </span>0.To(59)
            <span style="color: blue">where </span>minute % 15 == 0
            <span style="color: blue">select string</span>.Format(<span style="color: #a31515">"{0:00}:{1:00}"</span>, hour, minute);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<h2>Using LinqPad to Test the Result</h2>
<p>Now, if you haven&#8217;t already, go <a href="http://www.linqpad.net/" target="_blank">download LinqPad from here</a>, and open it up. You will see a window to write a statement in the top right.</p>
<p>Before you continue, you need to add the extension methods to use my &#8220;To()&#8221; method. As a treat, just for you, <a href="http://www.richardbushnell.net/wp-content/uploads/2008/01/richardbushnellextensions.zip" target="_blank">here&#8217;s a simple assembly and a code file</a> you can use straight away. Download it, save the binary dll somewhere, then do the following in LinqPad:</p>
<ol>
<li>From the menu, click &#8220;Query&#8221;, then &#8220;Advanced Properties&#8221; (or press F4).
<li>On the Additional References tab, click the &#8220;Add&#8230;&#8221; button.
<li>Click the &#8220;Browse&#8230;&#8221; button on the window which pops up.
<li>Go to the location you saved RichardBushnell.Extensions.dll to, and select it. You should see it added to the list of additional references.
<li>Change to the Additional Namespace Imports tab.
<li>Type &#8220;RichardBushnell.Extensions&#8221;
<li>Click &#8220;OK&#8221;. </li>
</ol>
<p>Now, put your cursor in the Query1 tab, and paste in the following:</p>
<pre class="code"><span style="color: blue">from </span><span style="color: black">hour </span><span style="color: blue">in </span><span style="color: #c81efa">0</span><span style="color: black">.To(</span><span style="color: #c81efa">23</span><span style="color: black">)
</span><span style="color: blue">from </span><span style="color: black">minute </span><span style="color: blue">in </span><span style="color: #c81efa">0</span><span style="color: black">.To(</span><span style="color: #c81efa">59</span><span style="color: black">)
</span><span style="color: blue">where </span><span style="color: black">minute % </span><span style="color: #c81efa">15 </span><span style="color: black">== </span><span style="color: #c81efa">0
</span><span style="color: blue">select string</span><span style="color: black">.Format(</span><span style="color: #dc1414">"{0:00}:{1:00}"</span><span style="color: black">, hour, minute)</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Press F5, and you will see a generated list like this:</p>
<p><a href="http://www.richardbushnell.net/wp-content/uploads/2008/01/image2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="176" alt="image" src="http://www.richardbushnell.net/wp-content/uploads/2008/01/image-thumb2.png" width="244" border="0"></a></p>
<p>And that&#8217;s it! You can now see <em>exactly</em> what you will get when you run this code.</p>
<p>What do you think? I&#8217;d love to hear your comments.</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F01%2F18%2Fusing-linqpad-to-create-a-time-selector-drop-down-list%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/01/18/using-linqpad-to-create-a-time-selector-drop-down-list/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

