Archive for December, 2002

Uncle to be

Tuesday, December 31st, 2002

I found out at Christmas that I am to become an Uncle in July. Scary. Congratulations to Patrick (my brother) and Sonja. I guess one good thing about being in London is that I won’t have to change nappies :-)

NUnit ExpectException Attribute is an AntiPattern

Wednesday, December 18th, 2002

Consider the following test:

[Test]
[ExpectException(ExceptionType)]
public void ExceptionThrownByVerifier() {
doSomeSetup();
doSomeProcessing();
callSomethingThatThrowsTheException();
}

This is intended to test that callSomethingThatThrowsTheException() throws an excption. And lets say it passes.

The test is right - yeah? Wrong

If doSomesetup() throws an Exception then this is testing nothing - I’ll never know - and the test won’t tell me that it is useless.

The correct way to do this test is uglier, but actually works:

[Test]
public void ExceptionThrownByVerifier() {
doSomeSetup();
doSomeProcessing();
try {
callSomethingThatThrowsTheException();
fail("Expected Exception");
}
catch (ExceptionType e) {
//expected
}
}

If doSomeSetup() throws an Exception, then the test will fail, and tell me why.

MessageFormat

Thursday, December 12th, 2002

One of the nicest classes in C# is the StringFormatter. I’ve always wanted one in Java. And I just found where they got the idea from. As with the rest of C#: Java. In fact java.text.MessageFormat. D’oh

try {
...
} catch (FileNotFoundException e) {
System.err.println(
MessageFormat.format(
"Could not find file {0} ({1})",
new Object[] {file, e.getMessage()} ) );
}

Nice things coming in java 1.5

Tuesday, December 10th, 2002

This slashdot article about generics points to JSR-201. This contains some concrete proposals for enumerations, autoboxing, enhanced for loop and static import. I hadn’t seen these before, and they make for interesting reading.

    My comments would be:

  • Why introduce a new syntax for ‘foreach’ given that the c# one is so widespread?
  • I’d prefer blocks to foreach - but I guess its harder to implement.
  • I like covariant return types a lot (actually from generics aka JSR-014).
  • static import is nice syntactical sugar
  • boxing/unboxing is nice syntactical sugar
  • enum is really nice - basically syntactical sugar for the typesafe enum pattern - and I want to be able to do for (Day d : Day.monday .. Day.friday)

Woman jump starts car with cyber-infant

Tuesday, December 3rd, 2002

The Register
Gotta love it.

webmin

Monday, December 2nd, 2002

Ah the joys of webmin. If you run a Unix server and haven’t yet discovered it, ake a look. A two second install gives you instant access to a web control panel for your server, with things like one-click web analysis reports and emailing you when a service goes down. Really really cool.