Archive for April, 2006

Handling nullable value types in .NET 1.x

One of the great new features in .NET 2.0 is support for nullable types – especially important when dealing with value types such as Int or DateTime values coming from a database. Previously you were forced to either set and track another binary flag or to use a “special” value to represent null that sooner or later would turn up in real data.

In C# 2.0 thanks to a bit of syntactic sugar we can do this;

int? nullable1 = 1;
if (nullable1 == null) nullable1 = 2;

Which the C# compiler actually turns into the following:

Nullable<int> nullable1 = new Nullable<int>(1);
if (!nullable1.HasValue) nullable1 = new Nullable<int>(2);

This makes use of the new Nullable<T> generic structure to wrap the value with an additional boolean HasValue property.

That looks surprisingly similar to the syntax of the open-source NullableTypes project you can use with .NET 1.1 (or 2.0):

NullableInt32 nullable1 = new NullableInt32(1);
if (nullable1.IsNull) nullable1 = new NullableInt(2);

Disclaimer: I’ve worked on the NullableTypes project specifically implementing the IXmlSerializable, NullableGuid & NullableTimeSpan.

[)amien

Great Windows, Firefox and Web finds

Getting a new machine often spurs me to go out and find some new tools and utilities. Here’s some recent finds:

Windows

DiskMon – see disk activity
One of the great tools from SysInternals that provides low level disk i/o information but more importantly can minimize to the system tray and provide you with a disk activity in the absence of an LED.

John’s Background Switcher – brighten your desktop
Another desktop wallpaper changer but this one can head off to Flickr to grab the images. As Flickr contains photos of just about anything you might want to specify a couple of tags to get the sort of things you like. GrinGod suggests HDR as a good starting tag and I’m inclined to agree.

Firefox

Gmail Manager – don’t miss a message
This Firefox extension is essential if you want to use Gmail as your primary system. It provides the ability to switch between accounts as well as putting an unread count in the status bar and fixing all the mailto: links to head to Gmail compose. It can also pop up Outlook style new mail notifications trumping a sound of your choice if your co-workers don’t mind your laptop making odd sounds throughout the day.

Adblock Filterset.G Updater – keep ads at bay
Adblock is an essential tool to keep the distracting annoying advertisement pollution at bay. Setting up the rules however can be a boring and long affair but Filterset.G Updater will do that for you by downing a master list off the net. Nice.

Web sites

Rojo
I’ve been looking for an on-line news reader for some time and have been generally unimpressed with Google’s offering. Bloglines didn’t appeal to me but Rojo however looks pretty cool. Create an account, find the blogs you want (it knows about many of them already), tag them into categories if you like and off you go.

You can also Add Mojo to blog posts to get them noticed by others and tag individual stories if you like. The interface is pretty clear and easy to use and very Ajax.

Pandora
I’ve actually known about this for some time but never got round to mentioning it here. Pandora is like a personalised radio station – you tell it the names of a few bands you like and it uses it’s human-crafted database of artist techniques/styles/traits to build you a radio station of like music. At any point you can say you don’t want any more from this band or add additional artists in and the station will intelligently adjust again.

[)amien

Bad programming advice &#8211; don&#8217;t use exceptions

Kristian Dupont Knudsen has written a top 10 of programming advice not to follow with his rationalisation for each one. Being a programmer I thought I’d chip in with my 2 bits.

Joel recommends not using exceptions because they are “invisible in the source code” and that they create “too many possible exit points”.

His recommendation is to return error values when thing go wrong just like C does. This solves neither of the two problems he mentions and creates some new ones;

  • Passing an extra ‘error’ parameter to a function or use part of its return value
  • Keep track of the various error codes and what they mean
  • Newer libraries may return new errors that your code wasn’t written to handle and so your code will continue ignorantly
  • Forget an error and you’ll continue as if nothing went wrong…

I have to agree with Kristian on this one – Joel’s advice just makes no sense. Exceptions are a much superior solution to a difficult problem.

While I think Java went overboard in each method declaring what it might throw and needing to ensure you accept that C#’s balance seems just right.

Throw exceptions when your method can’t do what it says on the tin but exceptions should be just that – the exception. Don’t ever throw them to signify some additional or inconsequential condition.

[)amien

What are the unknown devices in XP on the MacBook Pro?

This article was written when Boot Camp had limited device driver support and is now therefore out of date.

Apple’s BootCamp provides the majority of drivers required including the elusive ATI Mobility Radeon X1600 driver however there are a few devices without official drivers. These are;

Apple Remote/IR Receiver

Described as: USB Human Interface Device
Identification: USB\VID_05AC&PID_8240\5&11730951&0&2 (05AC 8240)
Attached to: Intel 82801G USB Universal Host Controller – 27CA > USB Root Hub
Status: Seems unlikely Apple will deliver a driver but should be easy for a third party.

Apple iSight Camera

Described as: USB Human Interface Device
Identification: USB\VID_05AC&PID_8300\5&7A1792C&0&4 (05AC 8300)
Attached to: Intel 82801G USB2 Enhanced Host Controller – 27CC > USB Root Hub
Status: Apple will probably deliver a driver but if not should be a standard imaging chip (Micron).

Trusted Platform Module

Described as: Unknown device
Identification: ACPI\IFX0101\1 (IFX0101)
Attached to: Intel 82801GBM LPC Interface Controller – 27B9
Status: You can grab the Infineon TPM package from Intel’s web site – but who wants it?

Intel Hardware Monitoring

Described as: PCI Device
Identification: PCI\VEN_8086&DEV_27A3&SUBSYS_00000000&REV_03\3&B1BFB68&0&38 (8086 27A3)
Attached to: PCI bus 0, device 7, function 0
Status: Either Intel or Apple should deliver a driver but probably simple for a third party.

Keyboard back light?

Described as: Unknown device
Identification: ACPI\APP0002\A (APP0002)
Attached to: ACPI
Status: Apple might deliver a device but again if not a third party shouldn’t find it that tricky.

[)amien