<?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; Refactoring</title>
	<atom:link href="http://www.richardbushnell.net/category/refactoring/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>Remove and Sort Those Ugly &#8220;using-Statements&#8221;</title>
		<link>http://www.richardbushnell.net/2008/03/03/remove-and-sort-those-ugly-using-statements/</link>
		<comments>http://www.richardbushnell.net/2008/03/03/remove-and-sort-those-ugly-using-statements/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 08:10:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Commands]]></category>
		<category><![CDATA[PowerCommands]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/03/remove-and-sort-those-ugly-using-statements/</guid>
		<description><![CDATA[Visual Studio 2008 has lots of goodies in it, like LINQ syntax, CSS editing, and testing tools. There&#8217;s a lesser-known feature which I really appreciate though &#8211; the &#8220;Remove and Sort Usings&#8221; command in the C# editor. You activate the command by placing your cursor over the using statements and clicking on the right mouse-button. [...]]]></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%2F03%2Fremove-and-sort-those-ugly-using-statements%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>Visual Studio 2008 has lots of goodies in it, like LINQ syntax, CSS editing, and testing tools. There&#8217;s a lesser-known feature which I really appreciate though &#8211; the &#8220;Remove and Sort Usings&#8221; command in the C# editor.</p>
<p>You activate the command by placing your cursor over the using statements and clicking on the right mouse-button.</p>
<p><a href="http://www.richardbushnell.net/wp-content/uploads/2008/03/image2.png"><img src="http://www.richardbushnell.net/wp-content/uploads/2008/03/image-thumb.png" style="border: 0px none " alt="image" border="0" height="411" width="488" /></a></p>
<p><span id="more-65"></span></p>
<p>Using this groovy tool, I&#8217;ve been able to go through my old ugly C# files and get rid of all the superfluous using statements, then tidy them up, all at the click of a button. It&#8217;s something I always wanted to do, but had no time for, and didn&#8217;t want to pay for an extra tool to do it for me.</p>
<p>The <em>only </em>problem with the feature is that you have to go through every file and right-click on the &#8220;using&#8221; statements to tidy them up. That can get a bit tedious, but it&#8217;s worth it.</p>
<p>But now it&#8217;s the Visual Studio Extensibility Team to the rescue!</p>
<p>The VSX team at Microsoft have just released <a href="http://www.visualstudiogallery.com/ExtensionDetails.aspx?ExtensionID=df3f0c30-3d37-4e06-9ef8-3bff3508be31">PowerCommands for Visual Studio 2008</a>. It&#8217;s a free tool for Visual Studio with loads of new tools for making a VS-developer&#8217;s life easier. And one of those new tools is a Remove and Sort Usings command at the project level.</p>
<p>You activate it with a right-click on the project itself.</p>
<p><a href="http://www.richardbushnell.net/wp-content/uploads/2008/03/image3.png"><img src="http://www.richardbushnell.net/wp-content/uploads/2008/03/image-thumb1.png" style="border: 0px none ; margin: 0pt 140px 0pt 0pt" alt="image" border="0" height="288" width="357" /></a></p>
<p>The tool then does the same Remove and Sort command for every file in the project.</p>
<p><strong>Tip: </strong>Make sure your project is buildable before using the tool. If there is an error stopping the build from running, you will get dialogs asking you to confirm every change in every file.</p>
<p>PowerCommands for Visual Studio 2008 also contains commands for:</p>
<ul>
<li>Collapse Projects</li>
<li>Copy Class</li>
<li>Paste Class</li>
<li>Copy References</li>
<li>Paste References</li>
<li>Copy As Project Reference</li>
<li>Edit Project File</li>
<li>Open Containing Folder</li>
<li>Open Command Prompt</li>
<li>Unload Projects</li>
<li>Reload Projects</li>
<li>Remove and Sort Usings</li>
<li>Extract Constant</li>
<li>Clear Recent File List</li>
<li>Clear Recent Project List</li>
<li>Transform Templates</li>
<li>Close All</li>
</ul>
<p>So, where can you get the tool?</p>
<p>The official site for PowerCommands is at the <a href="http://www.visualstudiogallery.com/ExtensionDetails.aspx?ExtensionID=df3f0c30-3d37-4e06-9ef8-3bff3508be31">Visual Studio Gallery</a>, but when you get there, you won&#8217;t see a download button. You actually have to click the &#8220;Learn More&#8221; button to go to the <a href="http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=PowerCommands&amp;ReleaseId=559.">download page at the MSDN code gallery</a>.</p>
<p>You can read more about PowerCommands on the <a href="http://blogs.msdn.com/vsxteam/archive/2008/02/29/PowerCommands-for-Visual-Studio-2008-released.aspx">Visual Studio Team Extensibility blog</a>.</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%2F03%2Fremove-and-sort-those-ugly-using-statements%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/03/remove-and-sort-those-ugly-using-statements/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Refactoring C# Series: Aggregation of IEnumerable</title>
		<link>http://www.richardbushnell.net/2008/03/02/refactoring-c-series-aggregation-of-ienumerable/</link>
		<comments>http://www.richardbushnell.net/2008/03/02/refactoring-c-series-aggregation-of-ienumerable/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 20:54:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C# 2.0]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Accumulator]]></category>
		<category><![CDATA[Aggregate]]></category>
		<category><![CDATA[Lambda Expressions]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/02/refactoring-c-series-aggregation-of-ienumerable/</guid>
		<description><![CDATA[I was recently reading Programming Ruby: The Pragmatic Programmers&#8217; Guide, Second Edition, and came across this piece of example Ruby code: [1,3,5,7].inject(0) {&#124;sum, element&#124; sum+element} -&#62; 16 [1,3,5,7].inject(1) {&#124;product, element&#124; product*element} -&#62; 105 Inject is a method which acts on an array by aggregating or accumulating the values within that array. It loops through the [...]]]></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%2F02%2Frefactoring-c-series-aggregation-of-ienumerable%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><a href="http://www.amazon.com/gp/product/0974514055?ie=UTF8&amp;tag=netsmoo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0974514055"><img style="margin: 0px 20px 20px 0px" src="/images/21VJS5BMKVL._AA_SL160_.jpg" align="left" border="0" /></a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=netsmoo-20&amp;l=as2&amp;o=1&amp;a=0974514055" width="1" border="0" /></p>
<p>I was recently reading <a href="http://www.amazon.com/gp/product/0974514055?ie=UTF8&amp;tag=netsmoo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0974514055">Programming Ruby: The Pragmatic Programmers&#8217; Guide, Second Edition</a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=netsmoo-20&amp;l=as2&amp;o=1&amp;a=0974514055" width="1" border="0" />, and came across this piece of example Ruby code:</p>
<blockquote><p>[1,3,5,7].inject(0) {|sum, element| sum+element} -&gt; 16      <br />[1,3,5,7].inject(1) {|product, element| product*element} -&gt; 105</p>
</blockquote>
<p><strong>Inject</strong> is a method which acts on an array by <em>aggregating</em> or <em>accumulating</em> the values within that array. It loops through the array, and for every item in the array, it performs a function. It then saves the result for the next iteration of the loop and eventually returns the aggregated value.</p>
<p>In <strong>C# 1.0</strong> you would probably write such a method like this:</p>
<pre class="code"><span style="color: blue">int </span>sum = 0;
<span style="color: blue">int</span>[] list = <span style="color: blue">new int</span>[] { 1, 3, 5, 7 };
<span style="color: blue">foreach </span>(<span style="color: blue">int </span>item <span style="color: blue">in </span>list)
{
  <span style="color: green">// Perform some function, then save the result
  </span>sum = sum + item;
}</pre>
<p>It&#8217;s a bit long-winded, and if you wanted to make it reusable, you&#8217;d have a hard time.</p>
<p>In C# 3.0, you can do it just like you can in Ruby.</p>
<p><span id="more-60"></span></p>
<h2>Defining the Aggregation</h2>
<p>First, let me explain how the Ruby <strong>inject </strong>method works.</p>
<p>First of all, it&#8217;s really misnamed in Ruby. The method is an aggregator, or even an &quot;accumulator&quot;. It aggregates or accumulates values. It takes two parameters &#8211; a starter value, and a block. In C# 3.0 we basically call a block a delegate, although in this case, it&#8217;s more like a Lambda Expression.</p>
<p>The <strong>inject</strong> method works like this:</p>
<ol>
<li>it takes the starter parameter and sets the aggregated value (the <strong>sum</strong> in the above example) to its value. </li>
<li>For the first item in the array, it passes the tarter value and the item itself to the block, which then performs the defined function on it. </li>
<li>The return value from the block is then assigned to the running aggregated value. </li>
<li>The running aggregated value is passed into the next iteration with the next item from the list. The function is called on those items again. </li>
<li>When the method has iterated over all items in the list, it returns the aggregated value. </li>
</ol>
<h2>Moving to C# 2.0</h2>
<p>So, let&#8217;s imagine you were trying to write the <strong>Inject </strong>method in <strong>C# 2.0</strong>. If you were to refactor the above <strong>C# 1.0</strong> example as <strong>C# 2.0</strong>, you might use anonymous methods to write this:</p>
<pre class="code"><span style="color: green">// Define a delegate
</span><span style="color: blue">delegate int </span><span style="color: #2b91af">Aggregator</span>(<span style="color: blue">int </span>sum, <span style="color: blue">int </span>item);

<span style="color: blue">static void </span>Main(<span style="color: blue">string</span>[] args) {

  <span style="color: blue">int </span>sum = 0;
  <span style="color: blue">int</span>[] list = <span style="color: blue">new int</span>[] { 1, 3, 5, 7 };

  sum = Inject(sum, list,     <span style="color: blue">delegate</span>(<span style="color: blue">int </span>starterVal, <span style="color: blue">int </span>item) {
      <span style="color: blue">return </span>starterVal + item;
    });
}

<span style="color: blue">int </span>Inject(<span style="color: blue">int </span>starterVal, <span style="color: blue">int</span>[] list,
           <span style="color: #2b91af">Aggregator </span>aggregator) {
  <span style="color: blue">int </span>sum = starterVal;
  <span style="color: blue">foreach </span>(<span style="color: blue">int </span>item <span style="color: blue">in </span>list) {
    <span style="color: green">// Perform some function, then save the result
    </span>sum = aggregator(sum, item);
  }
  <span style="color: blue">return </span>sum;</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>However, that would only work for <strong>int</strong> objects. You could really make it generic, and use the same method for other types:</p>
<pre class="code"><span style="color: green">// Define a delegate
</span><span style="color: blue">delegate </span>T <span style="color: #2b91af">Aggregator</span>&lt;T&gt;(T sum, T item);

<span style="color: blue">...</span></pre>
<p>
  </p>
<pre class="code"><span style="color: blue"></span>  sum = Inject&lt;<span style="color: blue">int</span>&gt;(sum, list,
     <span style="color: blue">delegate</span>(<span style="color: blue">int </span>starterVal, <span style="color: blue">int </span>item) {
      <span style="color: blue">return </span>starterVal + item;
    });</pre>
<p>
  </p>
<pre class="code">...

T Inject&lt;T&gt;(T starterVal, T[] list,
  <span style="color: #2b91af">Aggregator</span>&lt;T&gt; aggregator) {
  T sum = starterVal;
  <span style="color: blue">foreach </span>(T item <span style="color: blue">in </span>list) {
    <span style="color: green">// Perform some function, then save the result
    </span>sum = aggregator(sum, item);
  }
  <span style="color: blue">return </span>sum;
}</pre>
<p>It&#8217;s nicer, but the Ruby method still wins hands-down for neatness.</p>
<h2>Move Over Ruby, Here Comes C# 3.0</h2>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The good news is, the C# 3.0 compiler and the .Net 3.5 framework can now take care of most of this for you.</p>
<p>To start with, the Aggregator delegate is no longer necessary, because the new <strong>Func&lt;T,T,T&gt;</strong> delegate already defines a generic delegate which returns a value.</p>
<pre class="code">T Inject&lt;T&gt;(T starterVal, T[] list, <span style="color: #2b91af">Func</span>&lt;T,T,T&gt; aggregator)</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Secondly, the anonymous function using the delegate keyword can be replaced by a lambda expression like this:</p>
<pre class="code">(starterVal, item) =&gt; starterVal + item</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Thirdly, the Inject method can be defined as an extension method so that you can call it like this:</p>
<pre class="code">sum = list.Inject(sum, (starterVal, item) =&gt; starterVal + item );</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>And fourthly, the compiler can infer the type for you, so you don&#8217;t need to specify it on calling the method.</p>
<h2>The Aggregate Method</h2>
<p>But the <em>even better news</em> is that this method is already defined in the .Net framework for you, so you don&#8217;t even have to write it. Instead of being called <strong>inject</strong>, it&#8217;s called <strong>Aggregate</strong>, and is defined on the <strong>System.Linq.Enumerable&lt;T&gt;</strong> class.</p>
<p>So basically, using C# 3.0, you could reduce the above code to this:</p>
<pre class="code"><span style="color: blue">var </span>sum = 0;
<span style="color: blue">var </span>list = <span style="color: blue">new</span>[] { 1, 3, 5, 7 };
sum = list.Aggregate(sum,
                     (starterVal, item) =&gt; starterVal + item );</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>You get an extra bonus point if you spotted the extra C# 3.0 features I sneaked in there &#8211; the var keyword, and array initializers.</p>
<p>C# 3.0 is pretty neat huh? Move over Ruby.</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%2F02%2Frefactoring-c-series-aggregation-of-ienumerable%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/02/refactoring-c-series-aggregation-of-ienumerable/feed/</wfw:commentRss>
		<slash:comments>1</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>Calculating the Fibonacci Sequence with C# 3.0</title>
		<link>http://www.richardbushnell.net/2008/01/24/calculating-the-fibonacci-sequence-with-c-30/</link>
		<comments>http://www.richardbushnell.net/2008/01/24/calculating-the-fibonacci-sequence-with-c-30/#comments</comments>
		<pubDate>Thu, 24 Jan 2008 09:36:40 +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[Refactoring]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Fibonacci Sequence]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/01/24/calculating-the-fibonacci-sequence-with-c-30/</guid>
		<description><![CDATA[Scott Hanselman just posted his latest article in his weekly source code series. He shows various ways of producing the Fibonacci Sequence using various languages. I found it really interesting, for two reasons: I tried to do the C#3.0 one on my own after listening to a podcast about F#, and never could work it [...]]]></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%2F24%2Fcalculating-the-fibonacci-sequence-with-c-30%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><a href="http://www.hanselman.com/blog" target="_blank">Scott Hanselman</a> just posted his <a href="http://www.hanselman.com/blog/TheWeeklySourceCode13FibonacciEdition.aspx" target="_blank">latest article in his weekly source code series</a>. He shows various ways of producing the Fibonacci Sequence using various languages. I found it really interesting, for two reasons:</p>
<ol>
<li>I tried to do the C#3.0 one on my own after listening to a podcast about F#, and never could work it out. (Doh!) </li>
<li>It makes me question what I thought about coding. </li>
</ol>
<p>You see, I spend a lot of time refactoring. Sometimes too much. I have to ask myself why. It&#8217;s usually so that I can come back to the code later, and still understand what I was trying to do. <em>Most</em> of the time, <em>conciser is better. </em>But not always!</p>
<p>And that&#8217;s what I see in this post.</p>
<p><span id="more-38"></span></p>
<p>Suppose I had written this C# function (shamelessly stolen from Scott&#8217;s post):</p>
<pre class="code"><span style="color: #2b91af">Func</span>&lt;<span style="color: blue">int</span>, <span style="color: blue">int</span>&gt; fib = <span style="color: blue">null</span>;
fib = n =&gt; n &gt; 1 ? fib(n - 1) + fib(n - 2) : n;</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Compare this to the C# 2.0 version:</p>
<pre class="code"><span style="color: blue">static int </span>Fibonacci(<span style="color: blue">int </span>x) {
  <span style="color: blue">if </span>(x &lt;= 1)
    <span style="color: blue">return </span>1;
  <span style="color: blue">return </span>Fibonacci(x - 1) + Fibonacci(x - 2);
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Apart from the fact that these methods actually give different answers (sorry, Scott), if I were to try to understand these methods 6 months after writing them, which one of the code samples would I be most glad of seeing again?</p>
<p>You see, most code only gets read again for two reasons:</p>
<ol>
<li>to debug it, or </li>
<li>to hand it over to someone else </li>
</ol>
<p>In both cases, clever though it may seem, the first conciser version would probably cause more trouble. Now, don&#8217;t get me wrong, I&#8217;m all for good concise code, but XSLT is concise, and I hate debugging that.</p>
<p>Now, considering that in order to reuse the <span style="color: #2b91af">Func</span>&lt;<span style="color: blue">int</span>, <span style="color: blue">int</span>&gt; function, I would have to pass the around, thus holding it in a static variable, or wrapping it in another class, it doesn&#8217;t actually turn out to be that practical after all. Concise, yes. Practical and readable, hmm.</p>
<p>So, while we have a very-much-by-Ruby-On-Rails-driven trend going to make code as beautiful as possible, don&#8217;t forget to not go too far. We have to be able to read code later on, remember.</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%2F24%2Fcalculating-the-fibonacci-sequence-with-c-30%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/24/calculating-the-fibonacci-sequence-with-c-30/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Can You Pass an Anonymous Type Across Functions?</title>
		<link>http://www.richardbushnell.net/2008/01/08/can-you-pass-an-anonymous-type-across-functions/</link>
		<comments>http://www.richardbushnell.net/2008/01/08/can-you-pass-an-anonymous-type-across-functions/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 09:22:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Anonymous Types]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[passing anonymous types functions]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/01/08/can-you-pass-an-anonymous-type-across-functions/</guid>
		<description><![CDATA[One of the biggest questions with Anonymous Types is &#8220;can I pass them around?&#8221; If not, why not? Can you do something like this, for example: var GetAnonymousValue() { return new { Name = "Richard Bushnell" }; } void Main() { var value = GetAnonymousValue(); var name = value.Name;} The answer is simple: no, you [...]]]></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%2F08%2Fcan-you-pass-an-anonymous-type-across-functions%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>One of the biggest questions with Anonymous Types is &#8220;can I pass them around?&#8221; If not, why not? Can you do something like this, for example:</p>
<pre class="code"><font color="#0000ff">var</font> GetAnonymousValue() {
  <span style="color: blue">return new </span>{ Name = <span style="color: #a31515">"Richard Bushnell" </span>};
}

<span style="color: blue">void </span>Main() {
  <span style="color: blue">var </span>value = GetAnonymousValue();
  <span style="color: blue">var </span>name = value.Name;}</pre>
<p>The answer is simple: no, you can&#8217;t pass anonymous types across functions. var is not a dynamic variable, like in JavaScript. The CLR knows nothing about &#8220;var&#8221;, as the compiler just uses it to infer types when a variable is initialized.</p>
<p>At least, that was the answer until now. Using a simple extension method and generics, <a href="http://blogs.msdn.com/alexj/archive/2007/11/22/t-castbyexample-t-object-o-t-example.aspx" target="_blank">Alex James</a> just showed a nice way to pass them around on <a href="http://blogs.msdn.com/alexj/archive/2007/11/22/t-castbyexample-t-object-o-t-example.aspx" target="_blank">his blog</a>.</p>
<p>The trick is to use an example of the anonymous type you expect.</p>
<pre class="code"><span style="color: blue">object </span>GetAnonymousValue() {
  <span style="color: blue">return new </span>{ Name = <span style="color: #a31515">"Richard Bushnell" </span>};
}

<span style="color: blue">void </span>Main() {
  <span style="color: blue">var </span>value = GetAnonymousValue().CastByExample(<span style="color: blue">new </span>{ Name = <span style="color: #a31515">"" </span>});
  <span style="color: blue">var </span>name = value.Name;
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>While this might be a little dangerous, especially if you&#8217;re not testing your code regularly, this could be the solution to a few problems I can already think of. </p>
<p>Watch out for casting exceptions at runtime though! If you make a mistake anywhere, you&#8217;ll won&#8217;t get a compile-time exception, but a nasty runtime exception instead.</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%2F08%2Fcan-you-pass-an-anonymous-type-across-functions%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/08/can-you-pass-an-anonymous-type-across-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refactoring C# Series: Use Automatic Property</title>
		<link>http://www.richardbushnell.net/2007/12/28/refactoring-c-sharp-series-use-automatic-property/</link>
		<comments>http://www.richardbushnell.net/2007/12/28/refactoring-c-sharp-series-use-automatic-property/#comments</comments>
		<pubDate>Thu, 27 Dec 2007 22:00:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C# 2.0]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C# automatic properties refactoring]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2007/12/28/refactoring-c-sharp-series-use-automatic-property/</guid>
		<description><![CDATA[Name Use Automatic Property Summary You have a property in a class which just wraps a field of the same type, and simply returns or sets that field. private string _field1; public string Field1 { get { return _field1; } set { _field1 = value; } } Becomes: public string Field1 { get; set; } [...]]]></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%2F2007%2F12%2F28%2Frefactoring-c-sharp-series-use-automatic-property%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><h2>Name</h2>
<p>Use Automatic Property</p>
<h2>Summary</h2>
<p>You have a property in a class which just wraps a field of the same type, and simply returns or sets that field.</p>
<pre class="code"><span style="color: blue">private string </span>_field1;
<span style="color: blue">public string </span>Field1
{
  <span style="color: blue">get </span>{ <span style="color: blue">return </span>_field1; }
  <span style="color: blue">set </span>{ _field1 = <span style="color: blue">value</span>; }
}</pre>
<p>Becomes:</p>
<pre class="code"><span style="color: blue">public string </span>Field1 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</pre>
<h2>C# Version</h2>
<p>3.0</p>
<h2>Motivation</h2>
<p>Encapsulation is quite possibly <em>the</em> key principle of object-oriented design. It is common practice in C# to encapsulate fields by wrapping them in a property. </p>
<p>When a class has many properties, much of the class is taken up by the same coding pattern for a property:</p>
<pre class="code"><span style="color: blue">private string </span>_field1;
<span style="color: blue">public string </span>Field1
{
  <span style="color: blue">get </span>{ <span style="color: blue">return </span>_field1; }
  <span style="color: blue">set </span>{ _field1 = <span style="color: blue">value</span>; }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>In C# 3.0 this block of code can be removed by using automatic properties. The compiler will do the same thing that you would have done before if you just define the property name and the getter and setter.</p>
<pre class="code"><span style="color: blue">public string </span>Field1 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Reducing the property code like this makes it much easier to understand the code later, as only the necessary details are defined. Even if you use a terse syntax formatting, as in the previous example, you are saving 5 lines of code per property. The way I usually format my code with extra linefeeds, I save 9 lines for each one. When there are a lot of properties in a class, that is a large amount of code which can be removed.</p>
<p>Removing code isn&#8217;t just good for making it easier to understand; it makes it easier to test too. You wouldn&#8217;t have to test properties to see if they are simply setting and getting the correct values with this syntax, as the compiler is doing the work for you. So if you have unit tests, you might be able to remove lots of property testing code.</p>
<p>Of course, if the property does not just simply set or get a field value, you must use the previous C# 1.0 syntax for properties. In addition, you cannot specify get or set alone, but you can include scope identifiers to make a set private, for example:</p>
<pre class="code"><span style="color: green">// The following are not valid:
// Automatically implemented properties must define both get and set accessors
</span><span style="color: blue">public string </span>GetOnly { <span style="color: blue">get</span>; } <span style="color: green">// Not valid
</span><span style="color: blue">public string </span>SetOnly { <span style="color: blue">set</span>; } <span style="color: green">// Not valid either

// But this is okay
</span><span style="color: blue">public string </span>GetWithPrivateSet { <span style="color: blue">get</span>; <span style="color: blue">private set</span>; }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<h2><a href="http://11011.net/software/vspaste"></a>Mechanics</h2>
<ul>
<li>Remove the body of the property, replacing the code between the get and set blocks with a semicolon &#8220;;&#8221; .
<li>Compile.
<li>If there is a compiler warning that the field is no longer being used, you can now simply remove the field which the property was wrapping.
<li>If there is no compiler warning, other methods or properties are using the field directly. You can remove the field and recompile anyway, which will give you the location in the code where the field is being used. Replace each reference with a reference to the property instead.
<li>Compile. </li>
</ul>
<p>Repeat for each property.</p>
<p>If the field was a protected field, not private, then you might have subclasses which access the field. They will have to be changed to access the property instead of directly accessing the field.</p>
<p><strong>Tip</strong>: For new code, you can simply use the code snippet &#8220;prop&#8221; in Visual Studio 2008 to get an automatic property.</p>
<h2>Examples</h2>
<p>I&#8217;ll just do an example with one property, even though it looks a lot better with a longer class.</p>
<pre class="code"><span style="color: blue">class </span><span style="color: #2b91af">Account
</span>{
  <span style="color: blue">private long </span>_id;
  <span style="color: blue">public long </span>ID
  {
    <span style="color: blue">get </span>{ <span style="color: blue">return </span>_id; }
    <span style="color: blue">set </span>{ _id = <span style="color: blue">value</span>; }
  }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>First, remove the body of the property getter and setter (and apply a bit of reformatting too, if you like):</p>
<pre class="code"><span style="color: blue">class </span><span style="color: #2b91af">Account
</span>{
  <span style="color: blue">private long </span>_id;
  <span style="color: blue">public long </span>ID { <span style="color: blue">get </span>; <span style="color: blue">set </span>; }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Compile, to make sure the code is happy, then remove the field:</p>
<pre class="code"><span style="color: blue">class </span><span style="color: #2b91af">Account
</span>{
  <span style="color: blue">public long </span>ID { <span style="color: blue">get </span>; <span style="color: blue">set </span>; }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></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%2F2007%2F12%2F28%2Frefactoring-c-sharp-series-use-automatic-property%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/2007/12/28/refactoring-c-sharp-series-use-automatic-property/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A not-so-simple Mixin with C# 3.0</title>
		<link>http://www.richardbushnell.net/2007/12/26/a-not-so-simple-mixin-with-c-30/</link>
		<comments>http://www.richardbushnell.net/2007/12/26/a-not-so-simple-mixin-with-c-30/#comments</comments>
		<pubDate>Wed, 26 Dec 2007 08:34:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C# mixin multiple inheritance]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2007/12/26/a-not-sp-simple-mixin-with-c-30/</guid>
		<description><![CDATA[My last post gave a simple idea of how to do a Mixin with C#. Rather than repeating what someone else has already done, if you want to see a more complex example of what can be done, check out Create Mixins with Interfaces and Extension Methods by Bill Wagner at MSDN.com.]]></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%2F2007%2F12%2F26%2Fa-not-so-simple-mixin-with-c-30%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>My last post gave a simple idea of how to do a Mixin with C#. Rather than repeating what someone else has already done, if you want to see a more complex example of what can be done, check out <a href="http://msdn2.microsoft.com/en-us/vcsharp/bb625996.aspx" target="_blank">Create Mixins with Interfaces and Extension Methods</a> by <a href="http://srtsolutions.com/blogs/default.aspx" target="_blank">Bill Wagner</a> at <a href="http://msdn.com" target="_blank">MSDN.com</a>.</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%2F2007%2F12%2F26%2Fa-not-so-simple-mixin-with-c-30%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/2007/12/26/a-not-so-simple-mixin-with-c-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New series: Refactoring C# 1.0 code to C# 3.0</title>
		<link>http://www.richardbushnell.net/2007/12/25/refactoring-c-10-code-to-c-30/</link>
		<comments>http://www.richardbushnell.net/2007/12/25/refactoring-c-10-code-to-c-30/#comments</comments>
		<pubDate>Tue, 25 Dec 2007 16:58:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C# 2.0]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C# 3.0 migration upgrade refactor]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2007/12/25/refactoring-c-10-code-to-c-30/</guid>
		<description><![CDATA[I really like Scott Hanselmann&#8217;s idea to write an indefinite series of posts about reading code to be a better developer. I&#8217;m going to copy his idea, and write a series of my own. Since its first version, C# has evolved from being a Java clone to something much more dynamic. I&#8217;ve noticed that developers [...]]]></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%2F2007%2F12%2F25%2Frefactoring-c-10-code-to-c-30%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 really like <a href="http://www.hanselman.com/blog/" target="_blank">Scott Hanselmann&#8217;s</a> idea to write an indefinite series of posts about <a href="http://www.hanselman.com/blog/ReadingToBeABetterDeveloperTheCoding4FunDevKit.aspx" target="_blank">reading code to be a better developer</a>. I&#8217;m going to copy his idea, and write a series of my own.</p>
<p>Since its first version, C# has evolved from being a Java clone to something much more dynamic. I&#8217;ve noticed that developers often find themselves stuck long projects, and its sometimes hard to keep up with all the changes. I know a lot of developers who are still using .Net 1.1 because the project they are working on forces them too. For them, C# is still very much like Java. </p>
<p>So for all those who want to know what has changed since the first version, I&#8217;ve decided to make a new series of posts called &#8220;Refactoring from C# 1.0 to C# 3.0&#8243;. I will show through examples how you can make your code easier to understand and maintain by using the new features in C#. I&#8217;m not necessarily going to do it in historical order &#8211; I won&#8217;t show any preference for C# 2.0 Generics over C# 3.0 Extension Methods, for example. And C# 2.0 anonymous methods will take second place to C# 3.0 lambda expressions, which generally replaces them. I&#8217;m going to try to show how things have changed, and when you should or should not use the new features.</p>
<p>Some of the things I&#8217;ll cover are:</p>
<ul>
<li>Anonymous types</li>
<li>Anonymous methods and lambda expressions</li>
<li>Extension Methods</li>
<li>Yield statements and iterators</li>
<li>Generics</li>
<li>List comprehensions (ala LINQ)</li>
<li>Mixins</li>
<li>Partial types</li>
<li>Type and Array inference</li>
<li>Property visibility</li>
<li>Automatic properties</li>
<li>Static classes</li>
<li>The Global namespace</li>
<li>Object, Collection and Dictionary initializers</li>
</ul>
<p>I&#8217;ll try to treat each one as a refactoring opportunity, and not as a &#8220;must&#8221; or &#8220;must-not&#8221;. The idea is to write more maintainable code using the new features, not just go along with the trends.</p>
<p><em>Note</em>: I&#8217;m not going to treat the .Net base library at all. Just the C# language.</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%2F2007%2F12%2F25%2Frefactoring-c-10-code-to-c-30%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/2007/12/25/refactoring-c-10-code-to-c-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

