Dont Subclass Ordered Collection

The most natural thing possible in Smalltalk is probably to subclass OrderedCollection or Dictionary. So why shouldn't you do it?

Well, the fact that you might conceivably wish to switch to a Set or Dictionary in future doesn't hold much water. It goes against YAGNI. And it's not like switching superclasses is much effort. Much easier than writing the half dozen bogus methods to forward messages to your inner OrderedCollection.

No, the reason why you shouldn't subclass OrderedCollection is because you'll eventally want to create instance variables for your new class. And you'll want to stick values into those instance variables. And you'll forget that OrderedCollection becomes something else when it needs to grow, wiping out your instance variables. So you'll end up debugging for two hours tracking down the apparently nondeterministic bugs that show up.

Not that I've ever done anything like that.

Actually, if OrderedCollection copied over all additional instance variables, which it could do easily, then there wouldn't be any problems. But then again, that's not the only deficit in VW. Another one is it keeps returning self instead of the value of the last expression.

Unnatural Unexpected Behaviour?


EditText of this page (last edited August 10, 2004) or FindPage with title or text search