Monday, December 10, 2007

I'm afraid I'm a car snob

My car needed its second service today, which coincided with a planned shopping trip which i didn't really want to move. So I've got a courtesy car, and although it's almost brand new, clean, quiet and quite nice looking, there's no power there at all. I'm used to 200 horsepower and a turbo, now I've got an entry level 1.4 litre which is too heavy to ever be called nippy.

But at least it's only temporary, hopefully I'll get mine back tonight or tomorrow.

Thursday, December 06, 2007

UltraMon

If you're lucky enough to be using multiple monitors on one PC then check out UltraMon.

I've been using it for a couple of weeks now, and only just realised I can make Visual Studio span both screens, which means I can dock all the toolbars to one screen, leaving me with a full screen of code :).

Neat Pattern for Cloning with Inheritance

For once I've come across an MSDN forum post which exactly solves a problem I had. I'm not having the same problem as the person who asked the question, but the solution given was spot on for me.

Suppose you have two classes, SuperClass and SubClass, where SubClass inherits from SuperClass. If I want to create a deep copy of SubClass I should really implement a Copy method in SuperClass, and override that in SubClass.

But if I do that I can't really use the Copy method in SuperClass, because I can't cast a SuperClass to a SubClass.

The solution (as described in the above post: I can claim zero credit for this neat pattern), is to instead create a CopyFrom method, in which a SuperClass can be populated from another SuperClass. Then in the SuperClass's Copy method I create a new SuperClass, and call the CopyFrom method on it, passing in "this" (or "Me", if in VB.Net).

Then SubClass can override CopyFrom and call into the base method, adding any further properties that SubClass has. SubClass then overrides the Copy method, creates a new SubClass, and calls CopyFrom before returning it.

This is the code from the post above (credit to "nobugz"):


Class A
Private DataA As String = "Data-A"
Public Sub New()
End Sub
Public Overridable Sub CopyFrom(ByVal obj As A)
Me.DataA = obj.DataA
End Sub
Public Overridable Function Clone() As A
Dim NewA As New A
NewA.CopyFrom(Me)
Return NewA
End Function
End Class

Class B
Inherits A
Private DataB As String = "Data-B"
Public Sub New()
End Sub
Public Overrides Sub CopyFrom(ByVal obj As A)
obj.CopyFrom(Me)
Me.DataB = CType(obj, B).DataB
End Sub
Public Overrides Function Clone() As A
Dim obj As B = New B
obj.CopyFrom(Me)
Return obj
End Function
End Class

Wednesday, December 05, 2007

Divx XBox 360 Dashboard Update December 2007

If you've signed into XBox Live over the past couple of days you'll probably have been prompted to download a console update. I haven't yet found a complete list of everything that's changed, but I can confirm that the rumoured Divx support has been included. Yes, you can now stream Divx videos from a PC (running Windows Media Player 11) through your XBox so you can watch them on TV.

The quality is surprising good from the what I've watched.

Tuesday, December 04, 2007

Bad Smells in Code

If you've read anything by Kent Beck or Martin Fowler you'll probably have come across the concept of Bad Smells in developing computer systems. Not every developer I know has heard of these though, or if they have they're not entirely sure what it means.

In general terms it basically means that something just doesn't feel right in the code. But it can take a few years experience in writing code before you get to the point where you start getting this feeling, so I'm glad that a list of the common bad smells are listed for all to see.

The list is by no means complete, but please check out the most common bad smells.