Learn VisualBasic.NET with Me: type lists, cool (kinda)

I didn’t hack today. Too much stuff going on, so, I did a lot of hanging out and stuff. I did manage to get a little reading done, and found a neat little feature.

A Type List is a way to let your class operate on different data types. For example, if you created a Tree class, a type list could specify that it’s a tree of Oranges, or a tree of Integers. Of course, if you just made it a tree of variants, and used variants everywhere, then it wouldn’t matter.

In fully dynamic languages, types don’t matter, so there’s no need for a type list. VB isn’t totally dynamic, so this feature is useful for being a little more flexible about types, but not too flexible.

Perhaps that’s good. I’m not certain. For example, I can’t recall a situation where I really care about the type of an array. If I want it to be an array of integers, then, I’ll fill it with integers. If I really want it to be filled with integers, I’ll do a type check, and maybe a coercion, on the data before it’s added to the array. I usually check when I’m importing data from a file stream — having strong typing wouldn’t help there, because the incomind data is always characters.

That said, if this Type List feature can be used to eliminate this run time type checking, it’s a really cool feature. It would, at the very least, be a great hack if using type lists caused vb to build and link a new class, with the new type signature, when the object is instantiated from that class. Maybe it does.