Since I’ll be in Austin for the ALT.NET Open Space Conference early next month, my friend, Jeffrey Palermo, asked me to give a talk at the Austin .NET User Group while I was in town. So without further ado…

How does NHibernate enable a persistence ignorant domain model? Why would you want a persistence ignorant domain model? Why does the NHibernate Mafia feel so strongly about persistence ignorant domain models? And who are the NHibernate Mafia anyway? This session will answer all these questions and more.

Date/time: Monday, October 8, 2007 starting at 5:30pm
Location: Microsoft MTC

My good friend and fellow plumber, John Bristowe, is on the road again, this time with the third installment of Microsoft Canada’s DNIC Tour. He’ll be in Calgary talking about how to incorporate the .NET Framework into your existing applications.

Date: Thursday, September 27, 2007 from 5:30 PM – 7:30 PM
Location: Nexen Conference Centre Theatre, +15 Level
Registration: http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032353126

 

Developer Night in Canada

Developer Night in Canada (DNIC) III – Bringing the Power of the .NET Framework to Your Existing Application

For the past few years, you’ve heard a lot about the .NET Framework and the development platform it provides to foster innovation. Meanwhile, you’re still managing applications written with thousands of line of VB 6.0 code and you’d give anything to move to a more modern development environment and platform.  In this event, we’ll walk you through real-world tips & tricks that you can use to bring your solution to the .NET Framework. Specifically, you’ll learn how to tackle the issues of integration and migration when dealing with legacy applications. We’ll also feature folks from the Canadian developer community to provide you their experiences and insights.

I was recently asked, “What is the real story behind the name of C#?” Let’s take a quick stroll down memory lane and on the way we’ll answer that question…

In the beginning – around 1997 – there was Project Lightning. I was also known as Project 42 because DevDiv (Microsoft’s Developer Division) lived (and still lives) in Building 42 on the Redmond Campus. (I’ve always thought that was an awesome building number for DevDiv with the little hat tip to Douglas Adams’ Hitchhikers Guide to the Galaxy. I’ve always wondered if it was intentional.) Early press announcements referred to it as “Next Generation Windows Services”. Eventually Project Lightning was dubbed Microsoft .NET, though some code names have been forever baked into the system.

Marketing was thinking of calling it COM+ 2.0 or the Universal Runtime (URT). Another idea was the COM Object Runtime (COR). Hence mscorlib.dll, which is still the assembly that holds the CLR’s main types and is the one assembly that must be loaded in every .NET app domain. (System.dll is often loaded, but need not be. Mscorlib.dll contains the code for System.String, System.Int32, etc. You honestly can’t do anything without mscorlib.dll loaded.)

Another code name that lives on today is in the Assembly Binding Log Viewer – fuslogvw.exe – which allows you to monitor the loading of assemblies into app domain – successes as well as failures. (If you’re ever having problems figuring out why the wrong assembly is being loaded, where a particular assembly is being loaded from, or why assembly loading fails, the Assembly Binding Log Viewer is the tool to use. It ships with the .NET SDK.) Now why is it called fuslogvw.exe? Fusion was the codename of the CLR Loader, which is responsible for loading assemblies into app domains. I still think that Fusion is a most appropriate name for a loader.

So back to the original question of the origins of C#. The codename of C# was Project Cool, which was rumoured to be a clean-room implementation of Java. This was back in the days when Sun was suing Microsoft over bastardizing the Java language. As I recall, Sun didn’t like the Microsoft-specific extensions in J++, which allowed it to interoperate with COM. So where did the name C# come from?

C# name was musically inspired. It is a C-style language that is a step above C/C++, where sharp (#) means a semi-tone above the note. (Being a musician myself, I think this is awfully fun.) Back when .NET made its debut, an amusing quip from the Linux crowd was to refer to C# as Db (D-flat), which is the same note as C#, but has different connotations. Two MS Research languages also bear musically-related names: Polyphonic C# and F#.

I hope you enjoyed this trip down C#/.NET memory lane.

Why do I do what I do? To make a difference in the lives of other developers. I was delighted to receive the following email recently.

Hi James,

I’m writing you because I just wanted to thank you!

It was about two months ago and I attended TechEd/Orlando. I have to say that it was the first time for me and it really was an honor to be the one and only chosen from approximately 300 software developers working in my company to go to Orlando. I was very impressed about the good quality of the sessions, especially on the architecture track, but your tiny little discussion on Tuesday evening really opened my mind. At that time I had been working as a software developer for 7 years with about 5 years experience in software design and project management and 5 years of .NET experience. I was fighting with a 400,000 LOC .NET legacy monster that’s used by public safety agencies around the world in security related areas. I have a team of 12 developers and we were trying really hard to keep this beast up and running and extend it with new features. I think you can imagine that most of the time we were using the trial and error approach to get new features in (just hack it in and prepare for long debugging sessions hunting weird bugs in parts of the application you never expected to be affected by the new feature…). The main problem was – guess what – the dependencies. There were about 50 classes (all singleton “Managers”), and every single manager was tied to at least 10 other managers – no interfaces at all – and that’s just one of several layers of the app… We knew that dependencies were our problem, but we had no clue how to solve it – there was this chicken/egg problem – I want to decouple my system, which needs a lot of refactoring. To ensure that I don’t break anything I’d need unit tests but I can’t use them because my system is so highly coupled 😉 We have tried TypeMock, but my feeling was that this went in the wrong direction. Needless to say that this attempt failed.

During the discussion after your session you gave me some quite useful hints:

1. Read Applying Domain Driven Design and Patterns by Jimmy Nilsson
2. Read Working Effectively with Legacy Code by Michael Feathers
3. Use ReSharper (especially for Refactoring)
4. Use a Mock-Framework (preferably RhinoMocks)
5. Use a Dependency Injection Framework like Spring.NET

I bought Jimmy Nilsson’s book in the conference store and read it cover to cover on my flight back to Vienna. Then I bought the second book and read it within one week. I started to use ReSharper more extensively to apply some of the patterns from Michael Feathers’ book to get some unit tests in place. I extracted a lot of interfaces, brought Spring.NET into action and used RhinoMocks and the VS2005 built in UnitTest-Framework to write some useful unit tests. I also used the built in code coverage functionality in combination with the unit tests. In addition we already started Design for a messaging based service application that we want to develop in a very TDDish style.

As you can see there’s a lot going on since I attended your session. It was really this discussion about agile principles that gave me sort of a boost.

So again – thanks for opening my mind and keep on doing this great work!

Regards,
Karl

All I can say is wow! Karl, you did the really hard work of tackling and taming a 400 KLOC legacy monster. Kudos to you and your team.

I would like to comment on a few points…

TypeMock vs. RhinoMocks

Karl’s team tried using TypeMock to, presumably, introduce unit tests into their code. Unfortunately TypeMock too easily takes you down the wrong path. TypeMock uses the Profiling API and allows you to mock anything in the .NET Framework. Want to mock out System.String? Go right ahead. Unfortunately mocking out framework types does not get you any closer to your real goal, which is to lower the coupling and break dependencies in your system. There has been much discussion of whether TypeMock is too powerful. I wouldn’t say that it’s too powerful, but more that it encourages you to do things that aren’t necessarily a good idea – like mocking types in the .NET Framework.

RhinoMocks uses Dynamic Proxy 2 to perform its magic. In order to generate a proxy, you must mock out interfaces or abstract classes (with virtual methods). This forces you to confront your coupling and dependencies head-on. You could do the same thing with TypeMock, but it takes discipline. RhinoMocks forces you to improve your design in order to make it testable.

If you’re wondering how to retrofit unit tests into an existing code base safely, I would highly recommend checking out Michael Feather’s Working Effectively with Legacy Code mentioned above. Oren Eini (aka Ayende Rahien), the creator of RhinoMocks, wrote RhinoMocks after being inspired by this book.

Singletons and the Single Dev

As Karl mentioned, they originally had a lot of singleton managers. The code probably looked something like this:

CustomerManager.Instance.Save(customer);

The singleton is the most-overused Gang of Four (GoF) pattern in existence, probably because it is so easy to implement. It also leads you down the dangerous path of essentially global variables, which OOP tried to get rid of. Rather than a global string variable, we now have a static instance to which everyone couples – the “Instance”. (Hey, don’t feel bad. I once overused singletons too! Live and learn.)

Why is this bad? Because any class that uses the CustomerManager is now tightly coupled to CustomerManager. And as Karl found out, when you’ve got 50 managers, they quickly become coupled to every other manager. If you try to test any small part of your system, you end up pulling in a large fraction of the 50 managers and likely they bring along most of the rest of the system. You end up with a tangled morass of virtually untestable code. Your codebase ends up being relatively fragile because a change in one manager often ripples to every other part of the system. So making small localized changes is difficult.

The solution is to move toward interfaces and dependency injection. I’ll be writing more about this in the future, but for now, go back and read this for a refresher. Once you have dependency injection in place with unit tests and mocks, you can introduce an Inversion of Control (IoC) framework and take things to the next level. Which brings us to…

Inversion of Control (IoC) Containers

Karl and his team chose to use Spring.NET, which is a good IoC framework. There are many options for Inversion of Control containers, including Spring.NET, Castle Windsor, and StructureMap. I have personally been working with Castle Windsor and am pleased with the functionality and integration that it offers. I would encourage readers to investigate all three and make a decision for themselves. I’ve got some blogposts and screencasts coming in the next few months on the importance of IoC and how to get started with it.

VstsUnit vs. NUnit

Karl mentions using VstsUnit (aka mstest.exe) for unit testing. Even though I wrote the VstsUnit Plugin for ReSharper, I would personally recommend using NUnit or MbUnit as both are more TDD-friendly than VstsUnit. Many improvements are being made to VstsUnit in the VS 2008 release, which will make it more TDD-friendly, but for now, stick with NUnit or MbUnit.

Code Coverage

For code coverage, I would recommend using NCover and Grant Drake’s NCoverExplorer combined with NUnit or MbUnit. NCoverExplorer provides nice UI navigation of NCover results. If you want easy integration between all these tools, I would recommend checking out Jamie Cansdale’s excellent TestDriven.NET add-in for Visual Studio.

ReSharper

What can I say? I love JetBrain’s ReSharper. If you haven’t seen it before, it’s an add-in for Visual Studio geared toward refactoring and TDD. Doing TDD without ReSharper installed is like coding Windows Forms in Notepad. It can be done, but it’s painful. To give you another analogy… Vanilla Visual Studio is good for production line assembly of code. ReSharper turns you into an artist sculpting code to be aesthetically beautiful. JetBrain’s tagline is “Develop with pleasure!” and ReSharper definitely lives up to that. If you haven’t checked it out, I would definitely recommend downloading it and checking it out.

Conclusion

Karl, I am so glad that my session inspired you. I am delighted that you took the initiative to tame a 400 KLOC monster into something that’s a pleasure to work with. Thanks for taking the time to write and making my day. That’s why I do what I do.

Thanks to everyone who came out for the session to listen to tales of the NHibernate Mafia and how persistence ignorance can improve your domain model. Here is a list of recommended resources:

You can download the code here. NHibernatingNorthwind is adapted from code by Oren Eini. I haven’t included the NHibernate binaries. Download and extract NHibernate 1.2 into ..\tools\NHibernate.

If you have any questions, please don’t hesitate to email me or leave a comment.

The website is now live and accepting registrations. We’re accepting 100 lucky participants to take part in this unique event. Sign up now at http://www.altnetconf.com. If you don’t know what I’m talking about, go back and read this. Hope to see you there!!!

Coming to an Edmonton library near you… One night only…

How does NHibernate enable a persistence ignorant domain model? Why would you want a persistence ignorant domain model? Why does the NHibernate Mafia feel so strongly about persistence ignorant domain models? And who are the NHibernate Mafia anyway? This session will answer all these questions and more.

Date/time: Thursday, August 23, 2007 starting at 5:30pm
Location: Stanley A. Milner library (7 Sir Winston Churchill Square)

You can sign up on the EDMUG website.

You’ve encountered a dreaded <Colour> Screen of Death (where Colour = Blue, Black, Yellow, Fuschia, etc.) or similar problem. After googling the error message, you come across a blog post (maybe one of mine) referring you to some Microsoft Knowledge Base Article for a hotfix. The good news is you’ve done all the legwork and you know exactly the hotfix you need. The bad news… hotfixes require you to call Microsoft Product Support (PS).

Now the folks in PS are really nice, helpful people. It’s not that I mind talking to them. It’s just that I have to go through the whole hotfix song-and-dance. Yes, I need the hotfix mentioned in KB 123456. Yes, I am experiencing the problems described in that KB article. Yes, I know that the hotfix hasn’t undergone rigorous testing in the way service packs do. Yes, I understand that the hotfix could cause unspeakable evil if used incorrectly.

No longer! You can now fill in this online form to receive the hotfix instead. Simply submit your country, the KB article number, platform (x86, x64, ia64), language, and email address. Then you’ll receive a download link via email within 8 business hours.

Let me freely admit that my main purpose for this blogpost is so that I can find the download link easily the next time I need a hotfix because Microsoft doesn’t place that link in any obvious place on the Microsoft Help and Support site. The only reason I found it is because of a link in the Daily Grind!

After my DNIC video interview, John just wanted to know more about agile development. So we did it again, this time podcast-style. You can check out the audio interview here.

Coming to Austin, TX… October 5-7, 2007… Brought to you by the NHibernate Mafia themselves… 3 days of ALT.NET mayhem… See behaviours twisted, tests tortured, dependencies injected, object-relations mapped, and DSLs like you’ve never seen them before…

More seriously, what exactly is ALT.NET? David Laribee coined the term to describe developers who look outside the “official gospel” for ideas of how to develop software better.

  1. You’re the type of developer who uses what works while keeping an eye out for a better way.
  2. You reach outside the mainstream to adopt the best of any community: Open Source, Agile, Java, Ruby, etc.
  3. You’re not content with the status quo. Things can always be better expressed, more elegant and simple, more mutable, higher quality, etc.
  4. You know tools are great, but they only take you so far. It’s the principles and knowledge that really matter. The best tools are those that embed the knowledge and encourage the principles (e.g. ReSharper.)

Scott Bellware has assembled an all-star organizing committee, including:

The conference will be run in an open space format, which is very agile in nature and execution. Fundamentally OpenSpace is a conference with self-organizing sessions. If you have an idea for a session, you post it on the schedule. If you see a session that interests you, you show up. If that session sparks an idea you’d like to talk about, post your new session on the schedule. Lather, rinse, repeat… This will be my first time participating in an OpenSpace conference, but I’m excited by the concept.

You can expect topics covering:

  • Software design
  • Testing strategies and continuous integration
  • Test-Driven Development (TDD)
  • Behaviour-Driven Development (BDD)
  • Domain-Driven Development (DDD)
  • Domain-specific languages (DSLs)
  • Object-relational mapping (OR/M) using NHibernate
  • Dependency injection with Castle Windsor
  • Web development with MonoRail
  • Agile team practices, such as XP and Scrum
  • Plus anything else that attendees want to discuss

The Important Stuff

Cost: FREE! (except for the cost of airfare and accommodations)
Location: St. Edwards University Professional Education Center, Austin, TX
Date: Friday, October 5th, 2007 @ 5pm to Sunday, October 8th, 2007 @ noon
Attendance: 100 (max)
Registration: http://www.altnetconf.com

If you are interested in attending the event or would like to know more, please don’t hesitate to contact me or one of the other organizers.