Sunday, October 30, 2005
Shock and Awe, Halloween 2005 stylee
I posted a couple of pics from the Halloween Party held at NXNW Brewery in Austin. Our good friends from Fatty Monk played a kick-ass set while everyone got plastered... and... well, the pictures speak for themselves
Tuesday, October 18, 2005
Implement XSD-like Choice in C# 2.0
A few weeks back I posted about one feature I'd like to see in C# 3.0 - an XSD-like Choice feature that let me write code like this:
The intention is to have a generic type that is allowed to be one of a specific list of types and no others.
I found there is actually a way to get pretty close to this using a line of code like this in .NET 2.0:
The Choice class is implemented like this:
using System;
using System.Collections.Generic;
using System.Text;
namespace Choice
{
class Choice
where TFirst : class
where TSecond : class
{
public readonly TFirst First;
public readonly TSecond Second;
public Choice( TFirst value )
{
First = value;
Second = null;
}
public Choice( TSecond value )
{
First = null;
Second = value;
}
public static explicit operator TFirst( Choice value )
{
return value.First;
}
public static explicit operator TSecond( Choice value )
{
return value.Second;
}
public static implicit operator Choice( TFirst value )
{
return new Choice( value );
}
public static implicit operator Choice( TSecond value )
{
return new Choice( value );
}
}
} The trick (if you can call it that) is the use of implicit operators, one per choice-type (i.e. Pasta, Lasagna), which does the work of wrapping the wrapping of a choice-type in the Choice class.
I provided explicit operators to allow you to get the choice-type values back out again. I felt this was less ambiguous than using implicit operators. The code below shows code that gets values back out:
You will get back null if the choice is not of that type:
If you don't like the explicit cast, you can also use the First and Second accessors directly (First is the value of the first type passed to Choice, Second if for the second):
One nice feature of generics is that you can make many overloaded version of the class each accepting more and more parameters, but your code is still dealing in Choice<T1,T2,T3...> so once the developer understands the model, they're home free.
Now if only Microsoft would add this to .NET 2.0, and add in the compiler support to convert
List<Pasta or Lasagna> list = new List<Pasta or Lasagna>();list.Add( new Pasta() );list.Add( new Lasagna() );The intention is to have a generic type that is allowed to be one of a specific list of types and no others.
I found there is actually a way to get pretty close to this using a line of code like this in .NET 2.0:
List<Choice<Pasta, Lasagna>> list = new List<Choice<Pasta, Lasagna>>();The Choice class is implemented like this:
I provided explicit operators to allow you to get the choice-type values back out again. I felt this was less ambiguous than using implicit operators. The code below shows code that gets values back out:
List<Pasta or Lasagna> list = new List<Choice<Pasta, Lasagna>>();list.Add( new Pasta() );Pasta p = (Pasta) list[0]; // explicit operator returns the value of type PastaYou will get back null if the choice is not of that type:
Lasagna las = (Lasagna) list[0]; // las will be nullIf you don't like the explicit cast, you can also use the First and Second accessors directly (First is the value of the first type passed to Choice, Second if for the second):
Pasta p = list[0].First;One nice feature of generics is that you can make many overloaded version of the class each accepting more and more parameters, but your code is still dealing in Choice<T1,T2,T3...> so once the developer understands the model, they're home free.
Now if only Microsoft would add this to .NET 2.0, and add in the compiler support to convert
List<Pasta or Lasagna> to List<Choice<Pasta, Lasagna>> and I'll be a happy man.Thursday, October 13, 2005
I recently returned to working on Dell.com, doing a bit of work off on the side of their upcoming project (known as Storm 4.2), and helping with some of the look and feel stuff.
Anyhoo, we just pushed it out live, so check it out!
http://www.dell.com/
Congrats to the Storm team (the team the builds the Dell.com application), the global content team and the cast of thousands (ok, hundreds) that worked their tails off to get this out there.
Now things really start to get interesting. Look for lots more exciting changes to the site in the coming weeks and months ... I know I'm excited.

Anyhoo, we just pushed it out live, so check it out!
http://www.dell.com/
Congrats to the Storm team (the team the builds the Dell.com application), the global content team and the cast of thousands (ok, hundreds) that worked their tails off to get this out there.
Now things really start to get interesting. Look for lots more exciting changes to the site in the coming weeks and months ... I know I'm excited.

Friday, October 07, 2005
I'm officially in the HD-DVD camp
While the HD-DVD vs Blu-Ray debacle continues, it looks like the HD-DVD folks are coming down on the side of dropping region codes on their DVDs, according to a news item posted on Engadget.If true, this is great news, and firmly puts me behind the new format.
Why this total heresy? Well, I'm a British guy with a Japanese wife living in the US. Sometimes a British movie I want to see comes out only in the UK and doesn't get released globally. Likewise, if we want Japanese movies (especially kids movies to help keep our kids interested in learning Japanese), I want to be able to watch those too.
Thankfully sites like http://www.codefreedvd.com/ exist, so I can at least get DVD players today that let me do this. But Blu-Ray will require an Internet connection to ensure that the player can't be hacked, which made me livid when I found it.
Of course, its possible (likely, even) that studios will not back HD-DVD without these controls. Of course, if HD-DVD sells more players the studios may change their minds, but thats not likely unless at least one or two of the majors support HD-DVD, because what use is a DVD player where no movies are available.



