And another thing

I actually prefer a unit test to a type system hierarchy. That’s the tester coming out for sure.

If a foo can do something with a object of type bar or baz but not a quux, how do test that:

class Foo
{
//…
public Fooible get() { return lookupAndInstantiate(“object_id”); }
}
class Bar implements Fooible {}
class Baz implements Fooible {}
class Quuz {} //does not implement Fooible

assert(foo.get(id_of_a_bar) instanceof Fooible);
assert(foo.get(id_of_a_baz) instanceof Foobile);
assert(! foo.get(id_of_a_quux) instanceof Foobile);

I want to do this, but my compiler prevents me from testing it. I could cast, but that’d be pointless. I could build an ugly mock that has no point other than to get around the type system, but still not good.

I’m going to score 1 for dynamic languages, because in the real world, you end up getting Quuxes, especially if you want to use something like ActiveRecord; and you’ll write a lot of code to prevent it and a lot of code to get around those compiler checks, otherwise.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s