Archives / 2008 / October
  • Named and Optional Arguments in C# 4.0

    Many interesting news is coming from PDC this week.  Part of the announcements was around Visual Studio 2010 and the .NET Framework 4.0 CTP.  Microsoft has made available, a Virtual PC Image preloaded with Visual Studio.


  • KaizenConf - Functional Programming – Is it a game changer?

    Next week at the "Continuous Improvement in Software Development Conference" (KaizenConf), I will be giving a session called "Functional Programming - Is it a game changer?".  In this discussion, I'll cover the basics of functional programming, moving from an imperative style to a functional style, and what benefits you get from it.


  • DC ALT.NET 10/2008 Recap - A Look at Kanban Software Development

    Thanks to everyone who came out to the DC ALT.NET meeting on "A Look at Kanban Software Development" with Linda Cook.  This was a great discussion about Kanban and continuous improvement with Lean Software Development techniques.  Linda shared her experiences while working with her current customer about implementing Kanban.  Continuous improvement was important and readily noticeable from the evolution of the Kanban boards.  Her teams are using it with success and refining the processes to eliminate waste.  It was really refreshing to hear about real stories in action.  Topics such as these are important to DC ALT.NET as we talk about some of the challenges we face as software engineers, and how we find ways to improve.


  • Reminder - DC ALT.NET - 10/21/2008 - A Look at Kanban Software Development

    Just as a reminder, the October meeting for DC ALT.NET will be on October 21st, 2008 from 7-9PM.  Check the DC ALT.NET site and our mailing list for continuing updates and future meetings.  This month, Linda Cook will be presenting "A Look at Kanban Software Development".  I've been exploring a lot of Lean Software Development and Kanban, and this is an opportunity to explore the topic in depth with an established Lean/Agile coach.  My CodeBetter compatriot, Dave Laribee had introduced Kanban to XClaim Software and has some really good information on the topic.


  • Functional .NET - Fighting Friction in the BCL with Directory.GetFiles

    Very recently on a project, I was having significant issues with System.IO.Directory.GetFiles, in which I was getting an access denied message which prevented further crawling of certain directories.  The performance issue was another issue that was detrimental.  I wasn't happy either with the design of this API.  Instead, I set out to fix some of these issues and come up with a design that I felt better addressed some of my concerns with some techniques from functional programming.


  • Functional .NET - LINQ or Language Integrated Monads?

    As part of my talk at the Richmond Code Camp earlier in October, I had the opportunity to talk about how to implement functional aspects in C# 3.0.  This talk revolved around such concepts as from mutable to immutable, from inheritance to functional composition, and the mind shift that is required.  Part of this discussion involved very briefly a talk about monads.  It's a very misunderstood part of computer science and one of the most powerful concepts to learn.  Much like continuation passing style, this style is often maligned as a result.  But, let's work to change that.


  • Richmond Code Camp 2008.2 - Functional C# Recap

    Thanks to everyone who attended my session "Functional C# or how I lost the foreach and learned to love LINQ".  This is still an ongoing passion of mine that I hope to expand upon in the upcoming posts.  Some of these topics include favoring functional composition over inheritance and implementing patterns such as the Specification Pattern using these techniques.  I'll be posting all code snippets from the functional posts up to date on the MSDN Code Gallery Functional C# Project.

    Here are some resources that will be helpful in covering functional programming aspects as well as other topics covered:

    Functional Programming


  • ASP.NET MVC with NHaml - F# Edition

    As part of some of my adventures with F#, I've seen a lot of interesting things coming from others with regards to SharePoint, ASP.NET and other technologies.  This had me thinking of any possibilities and ramifications of using F# with ASP.NET MVC.  Was it possible, and better question, what might make someone use this over their existing toolsets.  Those are some of the questions to explore.  But, in the mean time, let's take the journey of F# and ASP.NET MVC.


  • DC ALT.NET - 10/21/2008 - A Look at Kanban Software Development

    The October meeting for DC ALT.NET will be on October 21st, 2008 from 7-9PM.  Check the DC ALT.NET site and our mailing list for continuing updates and future meetings.  This month, Linda Cook will be presenting "A Look at Kanban Software Development".  I've been exploring a lot of Lean Software Development and Kanban, and this is an opportunity to explore the topic in depth with an established Lean/Agile coach.  My CodeBetter compatriot, Dave Laribee had introduced Kanban to XClaim Software and has some really good information on the topic.


  • Upcoming Events - Richmond, Ruby DCamp and more

    The next couple of months are pretty busy for me.  There are several items worth noting whether I'm speaking or just plain attending.  This is a great season for community events and chances for continuous improvement.

    Richmond Code Camp - October 4, 2008

    This weekend, I'm going to be attending the Richmond Code Camp in Richmond, Virginia.  I have the privilege of presenting "Approaching Functional Programming in C# or How I Lost the ForEach and Learned to Love LINQ" in which I discuss many of the topics around functional programming aspects while using C#.  This discussion will include functional programming concepts, where C# fits, where it doesn't along with things you need to keep in mind.  Amanda Laucher will also be in attendance presenting some functional programming concepts, so a good time will be had by all.

    As part of the discussion, my sample code as always is available on MSDN Code Gallery at the Functional C# Project.  I'll post my slides shortly after the discussion as well.  Hope to see a great crowd there.

    Ruby DCamp - October 11-12, 2008

    Another great event coming to the Washington, DC area is Ruby DCamp.  Up until very recently, many Ruby conferences have followed the traditional paid speaker and audience mold.  Instead, this is an Open Spaces event for Rubyists from all areas to converge on our nation's capital to decide the agenda.  I've found the Ruby community to be filled with some very bright people, especially in the Washington DC area with the DC Ruby Users Group (DCRUG) and Northern Virginia Ruby Users Group (NOVARUG).

    RubyDCamp will be held at the Holiday Inn in Arlington, VA.  Best of all, it's metro accessible as well.  Visit for more details.  Register today at Eventbrite!

    KaizenConf - October 30 - November 2, 2008

    The Continuous Improvement in Software Development Conference will be held at the end of October over Halloween and into early November.  This looks to be a great event for sharing ideas on how we advance our craft through continuous improvement.  I will be leading a workshop on Functional Programming Concepts and more in particular F#.

    But, what is it all about anyways?  Some of the questions that we need to consider are:

    • How do we improve?
    • How do we recognize new improvements?
    • What improvements in the past led us to where we are now?
    • How do we decide which improvements to make?
    • What values drive our decisions for improvement?
    • What improvements can we be making right now?
    • What obstructions impede improvement?
    • What improvements are on the horizon?
    • How can we adapt easier to the changes that improvements bring?
    • What are the practices and processes that enable improvement?

    Getting to share ideas on continuous improvement are quite important to me, and getting to share them with the likes of Mary and Tom Poppendieck will be wonderful.

    QCon San Francisco - November 19 - 21, 2008

    The second annual San Francisco enterprise software development conference, QCon will be held in mid-November.  The names of participants is literally a who's who in software development today.  Names such as Martin Fowler, Kent Beck, Eric Evans, Erik Meijer, Don Syme, and even my CodeBetter compatriots Dave Laribee, Greg Young and Jeremy Miller fill the ranks.  Tracks include Alternatives in the .NET Space (ALT.NET), Agile Development, Domain Driven Design, Functional Programming and more.  Visit and register today!

    kick it on


  • Emulating Java Enums in .NET - F# Edition

    I'm not usually one to follow up replies from another's blog in my own, but some challenges need further analysis.  Ayende posted earlier about emulating the behavior of Java Enums in .NET.  Since the inception of C#, there has been a lot of back and forth between Java and C# in terms of features such as generics, attributes (annotations), foreach statements, and lastly enums.  There are significant differences between the two, but let's see if we can bridge that gap.

    Enter Java Enums

    Previous to Java 5.0, Java had a standard way of delcaring an enumerated type as a constant.  This was neither type safe, brittle and rather uninformative (what does 3 mean anyways?).  Finally, come 5.0, this feature was added to have simple enums such as we've had in C# all along.  But, unlike C#, these were not capable of being cast to an integer, unsigned or otherwise.  A simple enum could look something like this.

    public enum PriorityLevel { Low, Medium, High }

    Not only can they hold the value just as C/C++/C# enums can, they can also hold behavior and data.  Let's expand our PriorityLevel to hold an integer level equivalent.

    public final enum PriorityLevel 
         Low("Low Priority"),
         Medium("Medium Priority"),
         High("High Priority");
         private static final Map<String,Status> lookup = getLookup();    
         private static HashMap<String, PriorityLevel> getLookup()
              HashMap<String, PriorityLevel> l = 
                   new HashMap<String,PriorityLevel>();
              for(PriorityLevel p : EnumSet.allOf(PriorityLevel.class))
                   l.put(p.getLevel(), p);
              return l;
         private String level;
         private PriorityLevel(String level) 
              this.level = level;
         public String getLevel() { return level; }
         public static PriorityLevel get(String level) 
              return lookup.get(level); 

    This gives us the ability to define a string equivalent for our given enum value.  This can be a powerful concept that the data is not just limited to integers.  So, this had me thinking about the possibilities of this in .NET.

    Enter C# 3.0 and Extension Methods

    Given that the ability of the Java enum has the ability to map itself to another data type's equivalent quite easily, it was a matter of time before we tried something like that in C#.  With the birth of extension methods, we have the ability to add features onto given types, such as enums.  An example of taking the above example and using extension methods might look like this.

    public enum PriorityLevel

    public static class Extensions
        public static string GetLevel(this PriorityLevel level)
                case PriorityLevel.High :
                    return "High Priority";
                case PriorityLevel.Medium :
                    return "Medium Priority";
                case PriorityLevel.Low :
                    return "Low Priority";
                default :
                    throw new NotSupportedException();

    It's not the best solution, but it certainly works.  Instead, let's look at another language, and yes, one that I've been talking a bit about recently in regards to F#.

    Enter F#

    When I was looking over Ayende's post, it struck me that people were using Java enums in such a way that it looked like discriminated unions.  This is the ability to create a set of discriminators to use with pattern matching.  Each discriminator may hold different data types as well, which makes them extra powerful.  Let's look at an equivalent of the above examples in F#.


    type PriorityLevel =
      | Low
      | Medium
      | High
    with member x.GetLevel() =
          match x with
          | Low -> "Low Priority"
          | Medium -> "Medium Priority"
          | High -> "High Priority"

    This is just a simple example of being able to add on behaviors to our discriminated union.  It could be expanded on to include more behaviors, but I think the point is well made.

    The Challenge

    Back to the challenge at hand, Ayende posted a quick code snippet of Java enum code that he wanted to transform into .NET.  Let's first look at the Java code and then the F# code sample that I put as an equivalent.

    private static enum Layer {
        public boolean isRightLayer(WorkType type) {
            if (this == FIRST && type != WorkType.COLLECTION)
                return true;
            return this == SECOND && type == WorkType.COLLECTION;

    Now using the techniques I used above, let's give a more complete code sample of what that might look like using F#.  I'll use discriminated unions and pattern matching once again to get the message across.


    type WorkType =
      | Collection
      | NonCollection

    type Layer =
      | First
      | Second
    with member x.IsRightLayer(workType) =
          match (x, workType) with
          | l, w when l = First && w <> Collection -> true
          | l, w -> l = Second && w = Collection

    I was able to pattern match against not just the discriminator, but also the WorkType discriminated union as a tuple, so that they are treated as one.  From there, I can pattern match against it rather easily.  Any questions?

    Wrapping It Up

    Java enums are definitely powerful ways of holding and describing data, but as you can see, discriminated unions using F# and pattern matching can do a pretty adequate job as well to express the data.  Using these concepts can get you most of the way there with replicating the behavior, but it's not a 100% solution by any means.  But, what I hope it does do is get you to look beyond C# to the polyglot lifestyle.  Now back to your regular programming.

    kick it on