Sunday, February 12, 2006

Playing a bit around with the .Net 2.0 framework.

Generics in .Net works nicely. Its nice to see casting and custom validation can be removed from one's code.

I have written about my problem with the naming convention of interfaces in .Net and now I'm going to write a bit more about it. In the System.Collections.Generics namespace, they have renamed a class compared to the old Collections namespace.

The ArrayList is now... TADA! List ???

I'll give you an example of why I think this is a bad name.
IList list = new List();

You want a list. So you create a variable of the type IList. Now you want an instance. But List doesn't make sense as a class name. It doesn't tell the user anything about it's behavior. Does it work like a linked list, an arraylist or maybe an array? You can't tell by the name.
ICar car = new Car();

This example is thought up, but equally weird.
customer: Hello! I would like to buy an ICar.
dealer: and which type would you like?
customer: I would like the Car...

Car car = new Porche911(); makes more sense just like List list = new ArrayList();

To me this looks like a lack of understanding of interfaces. It however makes perfectly sense in the VB6 world where interfaces don't exist:
List list = new List();

At work we have decided to drop the use of I. :)

1 comment:

  1. Hmm, I don't really use .Net, but yes, renaming ArrayList to List seems daft!
    Maybe its because ArrayList is used the most (I use it 91% of the time), so they wanted to help programmers like me save the time of writing Array. :-)

    Oh, about not prefixing with I...

    Car car = new Lupo();

    If one can't see that Car is an Interface (or abstract class), they are dumb. Well unless they use List in .Net.

    List list = new List();

    List... class or interface? :-P