Rants, rambles, news and notes from another geek

Cool (New?) Google Tip

Did you know you could type a celebrity’s name followed by “dob” and it will tell you when they were born? Pretty cool.

A Very Funny Star Wars Ep. 3 Review

After reading this, I think perhaps Eric agrees with me on the “new” Star Wars trilogy.

Just keep reading, the punchline is coming…

Use of Generics to Eliminate Casting

This post is really more of a question than something educational, so please if you have an opinion on this, post a comment.

Suppose you are creating a new class that implements an older, pre-Whibey interface. For sake of argument, lets suppose you are implementing System.ComponentModel.IServiceProvider.

1
2
3
4
public interface IServiceProvider
{
   Object GetService(Type serviceType);
}

Because IServiceProvider.GetService() returns an Object, you have to cast it before you can use it, resulting in the kind of ugly code shown here:

1
2
3
4
public void Foo()
{
   IMyService service = (IMyService) provider.GetService(typeof(IMyService));
}

Of course, if this interface were being created today, we may defined it like this to avoid all that nastiness:

1
2
3
4
public interface IServiceProvider
{
   T GetService<T>();
}

That’s not too bad eh? Now we can call it with much nicer code like this:

1
2
3
4
public void Foo()
{
   IMyService service = provider.GetService<IMyService>();
}

Now here’s the question for all of you…

Given that this older interface exists, and will not likely be updated to have the kind of generics support I show here, should we use the generics form of GetService anyway? In other words, if you were creating a new class that implemented IServiceProvider, would you provide not only the required interface for use by people who expect you to be an IServiceProvider, but also provide the new generic method for people who know about it?

There is a part of my that likes it, but there is another part of me that thinks the interface clutter created by doing this isn’t worth it. We all know that behind the scenes the new implementation is just doing this…

1
2
3
4
public T GetService<T>()
{
   return (T) GetService(typeof(T));
}

…so it isn’t like this is saving me a cast or anything.

What do you think? Is this kind of thing good or bad?

SubText - .TEXT Forked!

I’ve been wondering how long this was gonna take to happen. Like many others, I didn’t jump on the Community Server Bandwagon. .TEXT was a good engine. It was BSD licensed. All was well.

Community Server is a commercial product.

As Phil Haack says:

Another reason is that Community Server has become sort of the Team System of blogging engines. By virtue of it going commercial, it’s being targetted to a different market than your average hobbyist and blogger. While I’m sure many are looking forward to the tight integration with forums and photo gallery, that’s just not something I personally need.

So Phil and a few others have forked the project into a new one called SubText. (Great name, btw.) They are running the project over on SourceForge - http://sourceforge.net/projects/subtext/.

Congrats guys!

Maybe now someone will rewrite the templating engine. I detest the way it works now. Too many damn files and user controls to make a skin. It just isn’t that hard.

Or maybe I will. Hmmmm. We’ll see.

Now playing: Nelly - Utha Side

Geek Notes 2005-05-09

I’ve said it before. I’ll say it again. When you have little kids you will be sick more often that any other time in your life (except perhaps when you were a little kid).

But before I got whatever my kids had last week, I did have├é a good weekend with them. On Saturday the whole family volunteered at her school. We put in├é a “Butterfly Garden” which is basically a ton of flowers and stuff in new beds. It was fun. Yesterday, of course, was mother’s day and we (me and Hadley) tried our best to pamper Emily all day. I think we only partially succeeded, but that’s about the best you can do with a 3 year old accomplish and a hollering 10 month old.

At least we tried.

  • Busy Box - A very cool alternative for a progress bar on a website. Looks to be very well done and feature rich. Check it out. [via Jeff Atwood]
  • More Super Cool Ruby - John Lam seems to be playing with Ruby this year too. Like him I discovered the cool WIN32OLE class. However, I hadn’t yet thought of how to wrap those objects to add new functionality. Then he takes it one further and shows how to do a better “using” statement than C# has. Damn I love that dynamic languages can do things like that. (Now that we have IronPython, where is Ruby for .NET??)
  • The Entomologist, The Redhead and The Dog - YesΓǪ my wife has posted more pictures of our family on her blog.
  • Where Does Unit Testing Fail - Mike Gunderloy interviews Mike Clark for ADT Magazine. Mr. Clark gives a great answer to this question that confuses people all the time. [via Darrell Norton]
  • Ada for .NET - The Deprartment of Computer Science at the USAFA has ported Ada to the .NET platform. Very cool. I think I first heard about this project a few years ago but they put out a new version last fall. They’re looking for someone to help them write a VSIP package for VS.NET if you just love Ada and want to help out. ├é [via The Daily Grind #615]

Now playing: Nelly - Utha Side

MSBuild Custom Metadata

Before coming to MS, I wrote a bunch of general purpose NAnt scripts to help people do things like automate their builds, set up CC.NET and other fun things.

Of course, you have to imagine that I couldn’t just sit here and not explore MSBuild a bit here and there.

So while putting together a bootstrap MSBuild file for our build server, I discovered a cool feature I wish NAnt had had “back in the day”: Custom Metadata.

Suppose I want to create a target called UnitTest that called NUnit-Console.exe on a number of assemblies. Also assume that for various reasons, I can’t use wildcards to figure out which assemblies to use. I have to specify which specific assemblies I want it to run against.

One more thing, I want the tests to run with the current working directory set to the bin\Debug directory for that test assembly.

In NAnt, I would have had to use and a number of other nasty property constructs, but in MSBuild it is a simple as this. (Please note the line numbers… I have manually wrapped some lines to make them fit on the page better.)

   1:  <?xml version="1.0" encoding="utf-8" ?>

   2:  <Project DefaultTargets="BuildAll" 

               xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

   3:      <PropertyGroup>

   4:          <NUnitExe>&quot;C:\Program Files\NUnit V2.1\bin\nunit-console.exe&quot;</NUnitExe>

   5:          <NUnitArgs>/nologo</NUnitArgs>

   6:      </PropertyGroup>

   7:  &nbsp_place_holder;

   8:      <PropertyGroup Condition="!Exists('$(Configuration)')">

   9:          <Configuration>Debug</Configuration>

  10:      </PropertyGroup>

  11:  &nbsp_place_holder;

  12:      <ItemGroup>

  13:          <TestAssembly Include="Microsoft.Practices.ComponentModel.Tests.dll">

  14:              <WorkingDirectory>$(MSBuildProjectDirectory)\UnitTests\ComponentModel

                       \bin\$(Configuration)</WorkingDirectory>

  15:          </TestAssembly>

  16:          <TestAssembly Include="Microsoft.ApplicationBlocks.CompositeUI.Tests.dll">

  17:              <WorkingDirectory>$(MSBuildProjectDirectory)\UnitTests

                       \CompositeUI\bin\$(Configuration)</WorkingDirectory>

  18:          </TestAssembly>

  19:      </ItemGroup>

  20:      

  21:      <Target Name="BuildAll" DependsOnTargets="Clean;Compile;UnitTest" />

  22:  &nbsp_place_holder;

  23:      <Target Name="Clean">

  24:          <MSBuild Projects="CompositeUI-CS.sln" Properties="Configuration=$(Configuration)"

                   Targets="Clean" />

  25:      </Target>

  26:  &nbsp_place_holder;

  27:      <Target Name="Compile">

  28:          <MSBuild Projects="CompositeUI-CS.sln" Properties="Configuration=$(Configuration)" />

  29:      </Target>

  30:  &nbsp_place_holder;

  31:      <Target Name="UnitTest" DependsOnTargets="Compile">

  32:          <Exec ContinueOnError='true' Command='$(NUnitEXE) $(NUnitArgs) @(TestAssembly)'

                   WorkingDirectory='%(WorkingDirectory)' />

  33:      </Target>

  34:  </Project>

Pretty cool, eh?

The “trick” is in the UnitTest target. The @(TestAssembly) tells MSBuild to do that task once for each item named “TestAssembly” in the above . The %(WorkingDirectory) says to pull the WorkingDirectory metadata element from the specific TestAssembly item that is being used for that task.

That is very cool. I think I may be able to find all kinds of interesting uses for this kind of custom metadata. I certainly don’t think I could have written the same funtionality in NAnt with a script this short.

Also, there is a bunch of built-in, so called “Well Known Metadata” documented over in MSDN. Check it out.

TDD Webcast on Thursday

Brian Button, Scott Densmore, Brad Wilson and myself are putting on a webcast about TDD this Thursday. Here is a link to the webcast if you want to attend.

One thing to note: this was originally scheduled to be a talk by Jim Newkirk about TDD in VSTS, but he is unavailable so we are doing one on TDD in general. So the title and description are not really correct.

The title should be:

**Test-Driven Development
**A gentle introduction to TDD from a bunch of patterns & practices zealots.

If you are interested in hearing war stories from us, please come and listen in.

UPDATE: Apparently there is some confusion around the time. It is at 11:00am Pacific time. See you then!

My New Mouse + Keyboard

This week I gave up on my Microsoft Natural Wireless Keyboard and Mouse. I was given it by the Visual Studio Team System group for particpating in some focus groups at Tech Ed last year. (Thanks again guys.)

But the whole split keyboard thing just wasn’t working for me. I am now a touch typer, but switching between that and my laptop keyboard was just too difficult. But luckily for me Brad wanted&nbsp_place_holder;a Natural, so I took him over to the company store, had him buy the one I wanted and then we traded.

MS_Wireless_DesktopWhat I got was the Microsoft Wireless Optical Desktop Elite. A nice straight keyboard, fancy leather-like palm rest, wireless mouse with tilt wheel, and all the other doodads.

In general I’m happy with it. The keyboard feels nice under my fingers. I’m faster on it than I am on either the laptop keyboard or the old Natural. And this one remembers the F-Lock state between shutdowns. I don’t know if it is new drivers or what, but that alone makes this thing worth the money.

There are a few interesting annoyances…

  • The software regularly pops up a modal dialog box claiming the mouse had a dead battery. It does not.
  • They Play/Pause media button works with iTunes () but seems to send double keypresses (). This&nbsp_place_holder;could be a bug in iTunes, but I’m not sure.
  • Who decided that the Function keys should be grouped into blocks of three instead of blocks of four?
  • I still think the idea to get rid of the Insert key was wrong. I miss that key.

Another thing that I would like to see, that I haven’t seem on any keyboard is one with a little “eraser head” mouse pointer in betweeen the G-H-B keys. That would be nice. Then, for relatively simple mousing activities I wouldn’t have to leave the home row.

&nbsp_place_holder;

I Want a New Add-in - Class Organizer

I’m looking for an add-in for Visual Studio 2005. Or not. I guess I don’t need it to be an addin, if it ran against a C# source file, that would be fine.

Here’s what it would doΓǪ

  1. I launch the tool on a file and it presents a dialog that looks something like this

ClassOrganizer

  1. Once I have the parts organized the way I like them, it organizes my class file as indicated, and sorts the items in each section alphabetically.

That’s it! I can’t believe no one has written this already. If I can’t find one soon, I’ll have to write it myself.

Geek Notes 2005-04-23

Today was a wonderful Saturday home with the family. We all got up in good moods and decided that since it was a nice day we should go downtown. We walked around the Seattle Center for a while and then ended up going in to the Childrens Museum. Hadley had a blast playing with all the crap and Finn loved watching all the kids from his perch on my back. At lunch we retired to the food court upstairs where there was some kind of Japanese cultural fair going on or something. There was music, dancing, singing, geisha, booths and all kinds of stuff. It was a good day.

  • Underwhelmed by VSTS Test - My good friend Brian Button spent a day trying to use VSTS Test instead of NUnit and came away slightly less than happy. Brian is one off the best TDD guys I’ve worked with so take his observations and critiques seriously.
  • Seattle Gas Prices - This is cool. Everyday folks like you and me can report gas prices in their neighborhood and this site helps you find the cheapest place to buy. Also available for a number of other cities. Check it out.
  • Kyle Stacy RC Helicopter Savant - Holy shit. I’ve logged a few hours in an RC heli simulator, but never flown a real one. I have no idea how this 9 year old kid does the tricks he does in these videos. Amazing.
  • Nintendo Controllers as Musical Instruments - This is way cool. The ex-MIDI music geek tinkerer is drooling. Now if I can only find my soldering iron amid all the Fisher Price children’s toysΓǪ
  • Cleaning Up MSN Messenger Worm - An ex-coworker recently got nailed by one of those IM worms and has posted his experience getting rid of it. I don’t know if his removal steps are complete or not, so comment on his post if he missed something.
  • Fixed Price Contracts in Agile Projects - I’ve had to deal with this one a number of times before joining MS. I was generally successul in getting customers to understand why fixed price projects weren’t good, but sometimes you have to do what you have to do.
  • Virtual PC Command Line Reference - Nice stuff if you use VPC for development. (You do, don’t you?) [via The Daily Grind 606]