Monthly Archives: April 2009

Ramblings About Scrum

Over the past few of months, Scrum has taunted me.

It started with two excellent Thirsty Developer Podcasts –  The Thirsty Developer 14 with Ed Chaltry talking about “an Agile process” that can be used to manage and control complex software and product development using iterative, incremental practices Agile Software Development with Scrum (Series in Agile Software Development)and then The Thirsty Developer 28 with Sean McCormack talking about how Scrum and Agile principles can be applied to the enterprise. These podcasts provided such a detailed overview of Scrum that I couldn’t help but get excited.

Next, a co-worker did an excellent presentation on Scrum after successfully introducing Scrum into an organization where he was consulting.  The presentation both piqued my interest and left me questioning the merits of Scrum. Actually, it had a lot of folks in my group asking questions.  Maybe-not-so-coincidentally this was right around the time Martin Fowler’s Flaccid Scrum article was published.

Shortly thereafter we started using Rally Software to help manage a couple of our in-house projects and I found myself in the role of Scrum Master.  The Rally tools are great.  Scrum or no scrum, I’d recommend the product.

Since I was now a “Scrum Master” and under-qualified, I figured I should learn more about the role so I finished up Agile Software Development with Scrum (Series in Agile Software Development) by Ken Schwaber and Mike Beedle which I had been working on for a couple of months.  I also read Head First Software Development by O’Reilly Media.  Though it is an awesome resource which touches upon a number of Scrum-like processes and I recommend it to any developer (especially a junior developer on their first week on the job) it mostly through me off track as it didn’t truly define Scrum. 

Head First Software Development

Which brings us to last week….last week I watched Uncle Bob Martin’s presentation at Chicago ALT.NET on XP: After 10 years why are we still talking about it?  Though Uncle Bob paces in and out of camera throughout the entire one hour presentation, he’s one heck of a speaker and the presentation is a gem.  He provides a really nice overview of why Scrum has hit the mainstream whereas XP certainly has not.  He talks about Scrum being a subset of XP – Scrum took all the project management aspects of XP and left all the technical processes like continuous integration and TDD behind – and why this, Flaccid Scrum, ultimately fails over time.  The heart of Uncle Bob’s talk is craftsmanship which is a powerful message in it’s own right but it really brought my learning of Scrum full circle.

I had my half-yearly review last week.  Under the goals I listed for the next evaluation period, I included my desire to become Scrum Master certified. I’m not sure there’s much merit in this certification; however it certainly is a means to better learn the Scrum way of doing things.  Perhaps surprisingly, Scrum certification was one of the easier goals for the next six months. I think I’m going to be busy. Wish me luck.

Functional Programming – Part 1

I mentioned my Functional Programming Presentation a while back and promised to provide more detail. In response, I’m sharing my slide deck in a quick series of posts.  Without further ado, the first part of the series.

























In part 2 of the functional programming series, we’ll find out why functional programming has gain recent popularity.

I am going to be a little obnoxious about listing my functional programming references with every part of this series – mostly because the references, in their own right, are awesome.

.NET MailMessage, LinkedResources, AlternateViews and Exceptions

It doesn’t take much to hack together email functionality using the .NET framework.  In most cases you can new-up a MailMessage reference, assign sender and recipient addresses, provide a subject and a message body, configure your SMTP settings and then send.  Done and done.

But let’s say you need to provide both plain text and HTML versions of your message body.  Or maybe you would like to embed an image or two within the message body.  Or, what if, for some reason, you actually want to handle exceptions appropriately.  Well, there’s more to it then.

There are a numerous ways to better organize the following code.  In fact, we just went through an exercise at work where we refactored the heck out of the core email functionality and produce a really clean usable component which can be easily mocked, configured and leverages email templates.  It’s pretty cool.  That being said, I believe the following sample demonstrates the aforementioned core features of .NET emailing. 

I hope it helps. Let me know if I missed anything or it the example could be more clear.

    // Assign a sender, recipient and subject to new mail message
    MailAddress sender =
        new MailAddress("", "Sender");

    MailAddress recipient =
        new MailAddress("", "Recipient");

    MailMessage m = new MailMessage(sender, recipient);
    m.Subject = "Test Message";

    // Define the plain text alternate view and add to message
    string plainTextBody =
        "You must use an email client that supports HTML messages";

    AlternateView plainTextView =
            plainTextBody, null, MediaTypeNames.Text.Plain);


    // Define the html alternate view with embedded image and 
    // add to message. To reference images attached as linked 
    // resources from your HTML message body, use "cid:contentID" 
    // in the <img> tag...
    string htmlBody =
        "<html><body><h1>Picture</h1><br>" +
        "<img src=\"cid:SampleImage\"></body></html>";

    AlternateView htmlView =
            htmlBody, null, MediaTypeNames.Text.Html);

    // ...and then define the actual LinkedResource matching the 
    // ContentID property as found in the image tag. In this case, 
    // the HTML message includes the tag 
    // <img src=\"cid:SampleImage\"> and the following 
    // LinkedResource.ContentId is set to "SampleImage"  
    LinkedResource sampleImage =
        new LinkedResource("sample.jpg", 
    sampleImage.ContentId = "SampleImage";


    // Finally, configure smtp or alternatively use the 
    // mailSettings
    SmtpClient smtp = new SmtpClient
              Host = "",
              UseDefaultCredentials = false,
              Credentials =
                  new NetworkCredential("username", "password")

    //    <mailSettings>
    //        <smtp deliveryMethod="Network">
    //            <network host="" 
    //              port="25" defaultCredentials="true"/>
    //        </smtp>
    //    </mailSettings>

catch (ArgumentException)
    throw new
        ArgumentException("Undefined sender and/or recipient.");
catch (FormatException)
    throw new
        FormatException("Invalid sender and/or recipient.");
catch (InvalidOperationException)
    throw new
        InvalidOperationException("Undefined SMTP server.");
catch (SmtpFailedRecipientException)
    throw new SmtpFailedRecipientException(
        "The mail server says that there is no mailbox for recipient");
catch (SmtpException ex)
    // Invalid hostnames result in a WebException InnerException that 
    // provides a more descriptive error, so get the base exception
    Exception inner = ex.GetBaseException();
    throw new SmtpException("Could not send message: " + inner.Message);

15 Random Things I’ve Learned from Jeffrey Richter

I read through Jeffrey Richter’s CLR via C# not too long ago.  This evening I cracked it open again and jotted down a few notes on what I personally took away from the book. Of course, if I spent the time to write down everything I learned, I might still be busy writing.  I’ve thrown in the towel and though I’m probably not doing the book justice, here are 15 random things I have learned from Jeffrey Richter:CLR Via C# by Richter Richter: Book Cover

Page 3 – Way more than I ever wanted to know about the CLR’s execution model.  That is, everything about Managed Modules, Assemblies, Intermediate Language (IL), Framework Class Library (FCL), Common Type System (CTS) and Common Language Specification (CLS.) 

Page 56 – How to properly version your assemblies – including a breakdown of the assembly version resource information, how/when to increment the major, minor, build and revision numbers, and the distinction between AssemblyFileVersion, AssemblyInfomationVersion and AssemblyVersion numbers.

Page 144 – Best practices on how to write code to compare objects.  Here, Richter drills into object equality, identity and hash codes.

Page 177 – How the compiler handles constants – their values are embedded inside the IL code at compile time. 

Page 185 – Why one must beware of code explosion with initializing fields within classes with multiple constructors.  Key points: Any fields that the constructor doesn’t explicitly overwrite are guaranteed to have a value of 0 or null.  The compiler embeds, at the beginning of all constructor methods, field initialization code.  You should consider not initializing the default field value at the point of field declaration and instead perform the common initialization in a single constructor and have all other constructors explicitly call the common initialization constructor before overriding varying defaults. 

internal sealed class SomeType
    // Do not explicitly initialize the fields here
    private Int32 x;
    private String y;
    private Double z;

    // Sets all fields to their default
    // All constructors explicitly invoke this constructor
    public SomeType()
        x = 5;
        y = "Ben";
        z = 3.14159;

    // Sets all fields to their default, then changes x
    public SomeType(Int32 x) : this()
        this.x = x;        

    // Sets all fields to their default, then changes y
    public SomeType(String y) : this()
        this.y = y;

    // Sets all fields to their default, then changes x, y
    public SomeType(Int32 x, String y) : this()
        this.x = x;
        this.y = y;

Page 254 – The power of string interning and string  pooling.

Page 309 – How to perform unsafe array access and fixed-sized arrays.

Page 322 – How to implement multiple interfaces that have the same method name and signature and…

Page 325 – Why you need to be really careful when using explicit interface method implementations.

Page 365 – A quick introduction into Wintellect’s Power Collections library which extends the .NET Framework’s Class Library with an assortment of collection classes. The Power Collections library, documentation, and licensing information is available on CodePlex.

Page 411 – How the CLR provides special support for Nullable value types.

Page 431 – A little background on System.Exception, System.SystemException and System.ApplicationException and how Microsoft through the basic principles out the window.

Page 457 – Way more information than any single person should know about Garbage Collection (GC).

Page 562 – How to build a system which support add-ins.

Though it wasn’t mentioned in the book, Richter’s Power Threading library (DLL) contains many classes to help with threading and asynchronous programming for the .NET Framework, Silverlight, and the .NET Compact Framework. Jeffrey has described many of the classes contained in the library by way of his MSDN Magazine Concurrent Affairs columns and I found his Channel 9 overview on the AsyncEnumerator class (which uses Yield to simplify multithreading) absolutely fascinating.  The Power Threading Library is available for download here.

That’s fifteen.  I should probably drill into a couple of these with code samples…or you could just get a copy of the book. 🙂

Random closing thought: When I was flipping through the book today I found a spider smashed between pages 72 and 73.  Ironic?

ASP.NET MVC – Where Convention Really Matters

I am just going to come out and say it.  Occasionally I break the rules when it comes to conventions. Sometimes it is even on purpose.  In a recent peer code review, I was dinged on two counts of improper naming conventions:

  1. The first charge was my use of ALL_CAPS_WITH_UNDERSCORES when naming C# constants. Sure, Pascal casing is recommended, but old habits are hard to kick.  I’ve now conformed to the new, 8-or-so-year-old standard, but boy do I miss the way ALL CAPS made me feel like my code was yelling at me. 
  2. My second offense was another ALL CAPS thing.  Despite the standard convention which states all caps should only be used for identifiers that consist of two or fewer letters, if I were doing work for A Big Company, my namespaces would probably read like ABC.Web.UI rather than Abc.Web.UI. I’m not sure when the 3+ letter acronym rule was introduced, but my favorite language (far beyond that of C#) is English and I like the English  rule of capitalizing EVERY SINGLE LETTER in an acronym so I may just stick with it.  I’m bad news. I know.

Conventions have changed as our tools and languages have evolved.  IntelliSense and hover-over help text alone are changing the world one convention at a time.  Hungarian notation is now laughable — although I still use an abridged form when naming my UI elements (e.g. UserLabel, UserTextBox.)  The point is it is hard to not be just a little flippant about things that are constantly changing.  I’m pretty sure that’s why I’m personally a little loose when it comes to the casing of my constants and namespaces.  In the grand scheme of things, these details just don’t matter. 

Where conventions do matter, however, is within opinionated frameworks like ASP.NET MVC.  In ASP.NET MVC, the view (really the ActionResult) returned by the controller is implied per the method name if the view isn’t explicitly called out.  In the example below, the implied view (Delete) is returned if a dinner is found.  Otherwise, we explicitly return the “NotFound” view.

public ActionResult Delete(int id)
    Dinner dinner = dinnerRepository.GetDinner(id);
    if (dinner == null)
        return View("NotFound");
        return View(dinner);


Unless you are familiar with this convention and you adhere to it, the code can be a little confusing.  If you ask me, conventions within ASP.NET MVC (along with other MVC frameworks like Ruby on Rails and Maverick.NET) are very powerful, convenient and must be respected.  This is a case where conventions really matter.

Another ASP.NET MVC convention dictates where views must be located if they are to be used by the controller.  Working off of the prior example, the DinnersController.cs finds the Delete or NotFound view within the predictable Views\Dinners\ folder and the filenames map directly to the name of the views.

These are somewhat trivial examples of how conventions (over configuration) are used in ASP.NET MVC.  The main idea is that some conventions are handy, purposeful and necessary.  Other conventions don’t really carry that much weight. 

If you are interested in reading more about how conventions and standards, check out one of my older articles about compile coding standards and the devil being in the details.

If you are interested in learning more about ASP.NET MVC, this write up is leveraging code and screen shots from NerdDinner ASP.NET MVC tutorial. You can download the free end-to-end tutorial chapter in PDF form and download the source code + unit tests for the completed application. I spent a couple of days working through the documentation and sample project.  It is truly an excellent introduction into ASP.NET MVC.

Migrating to IIS7

It wasn’t until recently (December) that I started giving IIS7 any attention.  I suspect its because I don’t have to do much inside of IIS when I’m developing .NET applications on my Vista Machine and I haven’t deployed to many Windows Server 2008 machines yet.  Though there’s a impressive amount of information on the IIS Site and I’ve read and heard numerous accounts of how easy it is to migrate to IIS7, my experiences haven’t been effortless.

I first wrestled with IIS7 when I attempted to get SubText to run in Integrated Pipeline Mode:

Out of the box, SubText is unable to run under IIS7’s Integrated Pipeline Mode. Unfortunately, it goes beyond "migrating" the web.config to match the required format. For example, moving httpModules and httpHandlers to their new location within. As it turns out, Request is not available at Application_Start when running in Integrated mode and this causes SubText to fail too.

If we weren’t adding blog functionality to an existing, GoDaddy-hosted ASP.NET web site, we would be left with two options: Update the SubText codebase to not use the request context (plus fix whatever else surfaces) OR simply run SubText in classic mode.

Unfortunately, our current GoDaddy account is limiting as only a single app pool is available to us. Since the main site is configured for Integrated Pipeline Mode, we don’t have the freedom to change the IIS mode without impacting (read: breaking) the main site.

Short of switching to a more flexible host, the current plan is to modify the main site to run in classic mode. It’s a simple site and reverting the web.config to the classic mode format should not be a big deal. Alternatively, I’m toying with the idea of updating the SubText codebase to not use the request context at Application_Start. I haven’t heard on anyone running SubText in Integrated Mode and it might be a nice problem to solve — assuming there’s an end to the necessary updates.

Assuming there are about 8 more hours allocated to this effort, what’s the best approach? Am I missing any other options?

Ultimately, we settled and opted to run the Subtext in IIS7 but in Classic Mode:

As a follow up, we quickly commented out the Application_Start code which referenced the Request context. This experiment resulted in further exceptions. We’re currently moving forward with medications to the main site to run in classic mode.

Since my IIS7 initiation, I’ve started to get the swing of things.  Sure one needs to jump through a few hoops to get things running, but in retrospect it is all reasonable and once your get some of the basic steps down, it is pretty darn easy.  Hence, I offer three simple tips:

1 – Pretty much everything in IIS7 is locked down by default.  I’m pretty sure you can serve up an HTML page out of the box, but you need to enable even the most basic options like ASP.NET Services and Windows Authentication. Along those lines, here are two of the better articles I found on installing IIS7 on Windows Server 2008 and setting up IIS7 applications.

2 – Another big gotcha is related to configuration locking.  Basically, you need to unlock your web.config modules and handles sections before they can be formatted per IIS7 compliance. Execute the following at the command prompt and you are good to go:

%systemroot%\system32\inetsrv\APPCMD.EXE unlock config -section:system.webServer/modules

%systemroot%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/handlers

3 – Finally, let AppCmd.exe do your heavy lifting and make your web.config to IIS7 compliant by executing a like migration command:

%systemroot%\system32\inetsrv\APPCMD.EXE migrate config "Default Web Site/Application"

That’s it. Easy, right? By the way, if you are interested in learning more about IIS7, I highly recommend Jeff Brand’s Spaghetti Code Podcast on IIS7 with Robert Boedigheimer and I again suggest you check out the IIS Site.

Upgrade to SQL Server 2008 with SQL Server Management Studio (SSMS) 2008

I have installed SQL Server 2008 and SQL Server Management Studio 2008 a number of times and it has always been a snap*..until yesterday.

As it turns out, previous installations were always applied to machines (mostly VMs) which weren’t running early versions of the SQL Server and associated tools.  Yesterday, I performed my first upgrade from SQL Server 2008 and SQL Server Management Studio 2005 and it took a painfully long time to get everything in place.

There seems to be general discontent with the SQL Server 2008 installation/upgrade experience – particularly when it comes to SQL Server Management Studio. After yesterday’s debacle, I can understand why.  In retrospect, an upgrade to 2008 is simple if you follow the right steps.  If not, you’re bound to get frustrated and waste a couple of hours. 

If I knew then what I know now…

  • You cannot manage SQL Server 2008 with 2005 Management Tools. Go ahead and try it. SQL Server Management Studio 2005 will bark at you.
  • A stand-alone SQL Server Management Studio 2008 installer does not exist.  The Management Tools must be installed as a features available via the main SQL Server2008 installer. The Microsoft download for SQL Server Management Studio 2008, as far as I am concern is a hoax.  It is merely the SQL Server 2008 installer given a different file name. Seriously.
  • You cannot run SQL Server Management Studio 2005 and SQL Server Management Studio 2008 side by side. An attempt to install SSMS 2008 will fail if you have yet to uninstall SSMS 2005.

Save yourself some trouble.  Before kicking off your SQL Server 2008 / SQL Server Management Studio 2008 installation or upgrade, uninstall SQL Server Management Studio 2005.  If you imagedon’t, you will be able to successfully install SQL Server 2008, but the Management Tools installation will fail (gracefully.) If, per chance, you find yourself in this failure condition, continue with the SQL Server Management Studio 2005 uninstall, rerun the SQL Server 2008 installer and reattempt the Management Tools installation.  This can be done by following the “New SQL Server stand-alone installation of add features to an existing installation” option under the Installation view.  This time around select the Management Tools when the available features are presented and you should be all set.  You may find the management tools take a surprisingly long time to install, but, believe me, this is nothing compared to the time you might waste if you didn’t know the right steps to follow in the first place.

* Relatively standard installation instructions which work consistently well for me:

  • Run Setup.exe
  • Installation > Select “New SQL Server stand-alone installation or add features to an existing installation.”
  • Select the following Features:
    • Database Engine Services
    • Reporting Services
    • Client Tools Connectivity
    • Management Tools – Basic (If SSMS 2005 isn’t installed)
    • Management Tools – Complete (If SSMS 2005 isn’t installed)
  • Select the Named Instance/Instance ID based on established naming convention. For example, BGHOMESQL01
  • Set the following Service Startup Types:
    • SQL Server Agent – Automatic
    • SQL Server Database Engine – Automatic
    • SQL Server Reporting Services – Automatic
  • Use the same account for all SQL Server Services and provide account. On local machine, I suggest using the Current User.
  • Set the Authentication Mode:
    • Mixed Mode (SQL Server Authentication and Windows Authentication)
  • Provide the built-in SQL Server admin account. On local machine, I suggest using the Current User.
  • Configure Reporting Services:
    • Install the native mode default configuration

Learn Functional Programming

After completing a ridiculous amount of research over the past couple of month, I presented on functional programming early last week.  Even though I’ve playing with F# quite a bit lately, I didn’t focus on any specific functional or multi-paradigm language.  Instead my presentation included an overview of functional programming in general. 




Update 4/28/2009: I’ve posted my slide deck.  Check out Part 1 of the Functional Programming Series.

I compiled a good number of references during my research. If you are interested in learning more about functional programming, I suggest you consult any of the references below. Or you may just wish to wait for me to publish my slide deck.  

1..NET Rocks – Show 377: Ted Neward and Amanda Laucher on F#

2..NET Rocks – Show 310: Simon Peyton Jones on Haskell and Functional Programming

3..NET Rocks – Show 293: F# Moves Forward

4..NET Rocks – Show 266: Jon Harrop Makes Us F#

5.Deep Fried Bytes – Episode 24: Chatting about F# with Chris Smith and Dustin Campbell

6.Deep Fried Bytes – Episode 23: Functional Programming in C# with Oliver Sturm

7.Software Engineering Radio – Episode 108: Simon Peyton Jones on Functional Programming and Haskell

8.Software Engineering Radio – Episode 89: Joe Armstrong on Erlang

9.Software Engineering Radio – Episode 84: Dick Gabriel on Lisp

10.Software Engineering Radio – Episode 62: Martin Odersky on Scala

11.Herding Code – Episode 18: Matt Podwysocki on F# and Functional Programming

12.Pragmatic Podcast – Episode 24: Stuart Halloway on Programming Clojure

13.Elegant Code Codecast – Episode 24: Matt Podwysocki on Functional Programming

14.Matthew Podwysocki’s Blog


16.Real World Functional programming in .NET, Petricek

17.Functional Programming for the Rest of Us, Slava Akhmechet

18.Why Functional Programming Matters, John Hughes

19.Functional Programming HOW TO

20.Expert F#, Syme, Granicz and Cisternino

21.Foundations of F#, Pickering

22.An Introduction to Microsoft F#

23.F# Eye for the C# Guy, Leon Bambrick