<?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>Jason Rowe &#187; .Net</title>
	<atom:link href="http://jasonrowe.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonrowe.com</link>
	<description>enjoying the web</description>
	<lastBuildDate>Sun, 13 May 2012 14:05:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Shiny New Toys, Visitor Pattern, and Real World Functional Programming</title>
		<link>http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shiny-new-toys-visitor-pattern-and-real-world-functional-programming</link>
		<comments>http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 04:21:41 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Commentary]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1333</guid>
		<description><![CDATA[&#160; Last week in the office I thought to my self, “Holiday weekend coming! I’ll have time to play with WP7 or maybe I’ll play with HTML5”. Then I saw this tweet on twitter. We as developers spend too much &#8230; <a href="http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p> <p>Last week in the office I thought to my self, “Holiday weekend coming! I’ll have time to play with WP7 or maybe I’ll play with HTML5”. Then I saw this <a href="http://twitter.com/jeremydmiller/status/22798775378">tweet</a> on twitter.</p> <blockquote> <p>We as developers spend too much time playing with baubles and shiny new tools and not enough time on core skills and fundamentals</p></blockquote> <p>I thought well, instead of using some free time this holiday weekend to build something why not do a little research. I happened to have a problem at work which someone suggested using the Visitor Pattern. So I spent some time looking over a few resources and <a href="http://en.wikipedia.org/wiki/Visitor_pattern">Wikipedia</a> has a great explanation. I won’t try to repeat that. One area I was stuck on though was the concept of double dispatch. I found this <a href="http://bit.ly/bZRM74">example</a> on <a href="http://stackoverflow.com/questions/479923/is-c-a-single-dispatch-or-multiple-dispatch-language">StackOverflow.com</a> which solidified the concept. For some reason <a href="http://bit.ly/bZRM74">learning by spaceship and rebel alliance</a> works for me.</p> <p>So now that I had a good understand all I needed to was implement it right? I thought about it and figured that could wait. Now is an opportunity to work on my fundamentals. The Wikipedia article mentioned Common Lisp and how the Visitor Pattern simplified when using dynamic languages. This got me to thinking what would this look like in F# or a functional language? </p> <p>While looking into functional languages I came across this Stack Overflow question “<a href="http://stackoverflow.com/questions/3642328/i-am-a-c-developer-should-i-start-looking-more-on-f-closed">I am a C# developer, Should I start looking more on F# [closed]</a>”.&nbsp; Jon Skeet’s answer influenced me and I figured I would pick up a book <a href="http://manning.com/petricek">Real World Functional Programming</a>. It fits into the category of fundamentals because it’s using C# and F# to teach functional programming. Which I haven’t used in many years.</p> <p>So I start reading with the goal in mind that I would make a quick example of the visitor pattern in F#. Don’t think I am a super geek (not that you would be confused because of my skills). I did take time to drink a few of <a href="http://www.surlybrewing.com/beer/year-round-beers.html">these</a> and go to the Crowded House concert this weekend. By the fourth chapter or so things started to sink in with F# and functional programming. </p> <p>If I were using a declarative functional style of programming, I wouldn’t even need the visitor pattern at all!&nbsp; I don’t have objects that would need to be separated from the algorithm. I would only have types and could use pattern matching and discriminated unions to perform my algorithm. The visitor pattern is needed in my current project because I’m using an implicit OO coding approach.</p> <p>It was really shocking to me that this wasn’t obvious right away. I’ve been doing OO for so long now I’ve completely become accustomed to dealing with objects and state. A programming world without objects had completely slipped from my mind. Glad I took the time to get started on this book as it’s already giving me new ideas and techniques I can use in my daily C# and OO programming. Now to start working on some of the other <a href="http://www.indiangeek.net/wp-content/uploads/Programmer%20competency%20matrix.htm">programmer competencies</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 5 Features of Code First Entity Framework CTP4</title>
		<link>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=top-5-features-of-code-first-entity-framework-ctp4</link>
		<comments>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 16:19:26 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/</guid>
		<description><![CDATA[&#160; The latest release of Entity Framework CTP4 has some nice but unexpected changes. They introduced DbContext and DbSet to simplify model caching, database provisioning, schema creation and connection management. Here are my top 5 favorite features of the release. &#8230; <a href="http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>  <p>The latest release of Entity Framework CTP4 has some nice but unexpected changes. They introduced DbContext and DbSet to simplify model caching, database provisioning, schema creation and connection management. Here are my top 5 favorite features of the release.</p>  <ol>   <li><strong><em>Less code and fewer Concepts.</em></strong> The coolest part is the use of convention over configuration. See the <a href="http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4piwalkthrough.aspx">Productivity Improvements</a> walk through and <a href="http://blogs.msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx">Conventions for code first</a>. I like the extra touch that DbContext&#160; will create the database for you if you want. No code to write. Just use the default CreateDatabaseOnlyIfNotExists. </li>    <li><em><strong>Simplified Database Experience.</strong></em> With the introduction of DbContext and DbSet. EF now takes care of database provisioning, schema creation and connection management. Nice! My favorite part is the Interface IDbConnectionFactory to allow creation of your own conventions. </li>    <li><strong>Backwards Compatible.</strong> Yes, this is a feature when it comes to CTP’s and Betas. Some projects might just throw stuff away or completely change things on you. EF allows you to still use ObjectContext or <a href="http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx">Data Annotations</a> for advanced scenarios where common conventions don’t work for you. </li>    <li><strong>Simplified Configuration Experience.</strong> As I mentioned you can use annotations for this but you also have another cool option. DbContext includes a virtual method that can be overridden to do configuration right in the class. This means no need for separate configuration classes now. I definitely like having it all in one place. Much cleaner and easy to read. </li>    <li><strong>Testability </strong>IDbSet&lt;TEntity&gt; allows you to define an interface that can be implemented by your derived context. This allows the context to be replaced with an in-memory test double for testing. </li> </ol>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursive LINQ Query Example</title>
		<link>http://jasonrowe.com/2009/09/19/recursive-linq-query-example/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=recursive-linq-query-example</link>
		<comments>http://jasonrowe.com/2009/09/19/recursive-linq-query-example/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 05:31:22 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=699</guid>
		<description><![CDATA[I found this Traverse extension post on MSDN while searching for a good recursion example in Linq. I know it&#8217;s a little dated but Hey! We all learn at our own pace and mine is a little sloooower when it comes &#8230; <a href="http://jasonrowe.com/2009/09/19/recursive-linq-query-example/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I found this <a href="http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/fe3d441d-1e49-4855-8ae8-60068b3ef741/">Traverse extension post</a> on MSDN while searching for a good recursion example in Linq. I know it&#8217;s a little dated but Hey! We all learn at our own pace and mine is a little sloooower when it comes to Linq</p>

<p>I really got a lot out of this code snippet in terms of patterns and syntax. It makes use of some goodies like Delegates, Linq, and IEnumerable. The most interesting part for me though was the recursive call inside the Traverse extension and what it was being used for.</p>

<p>It shows a good pattern for getting values out of nested objects or flatting. Here is a quick sample app using the Traverse extension. Below this I&#8217;ve posted some other sources with similar selection patterns. </p>


<p><a href="http://codepaste.net/gf3q5a" >Link to code with syntax highlighting</a></p>

<br />

<pre>
class Program
{
static void Main()
{
    var list = new List<MyClass> {new MyClass(10), new MyClass(20)};

    foreach(var l in list)
    {
        l.MyList = new List<MyClass> {new MyClass(10)};
    }
    
    var total = list.Traverse(x => x.MyList).Sum(x => x.Val);

    Console.WriteLine(total);
    Console.ReadLine();
}
}
public static class MyExtensions
{
//The Traverse extension can be added to types of IEnumerable<T>.
//Returns T
//Input Param
//"fnRecurse" - delegate with one parameter T and returns IEnumerable<T>

public static IEnumerable<T> Traverse<T>
       (this IEnumerable<T> source, Func<T, IEnumerable<T>> fnRecurse)
{
    foreach (T item in source)
    {
        yield return item;

        var seqRecurse = fnRecurse(item);

        if (seqRecurse != null)
        {

//Making Recursive call to Traverse using 
//results from the lambda expression 
            foreach (T itemRecurse in Traverse(seqRecurse, fnRecurse))
            {
                yield return itemRecurse;
            }
        }
    }
}
}

public class MyClass
{
public MyClass(int val)
{
    Val = val;
}

public int Val;
public List<MyClass> MyList = new List<MyClass>();
}</pre>
<br />
<p><b>Here are some more posts on the same topic: </b></p>

<ul>
<li><a href="http://www.pluralsight.com/community/blogs/jeffsch/archive/2006/08/18/33631.aspx">a recursive Linq Extentions</a> </li>
<li><a href="http://j832.com/workBlogFiles/2008-01-16_SelectRecursive.htm">Select Recursive</a> </li>
<li><a href="http://mutable.net/blog/archive/2008/05/23/using-linq-to-objects-for-recursion.aspx">Descendants extension</a> </li>
</ul>

<br />

]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2009/09/19/recursive-linq-query-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

