Should every kernel class x provide support for (x new) printString and (x new) hash

Lex Spoon lex at
Wed Jan 24 16:29:49 UTC 2007

"Ralph Johnson" <johnson at> writes:
> Collection is an abstract class, so you should never say "Collection new".

For newbie friendliness, it would help to do one of the following:

Option 1. Make "Collection new" return an error describing the
situation.  For example:

      ^(self == Collection) ifTrue: [
         self error: "Collection is abstract and cannot be implemented"
      ] ifFalse: [
         super new ]

With some thought, this bit of code could be abstracted, so people can
just write something like:

      ^self newIfSubclass

Even better, we could set things up so that this would work:

   Collection class>>initialize
      self abstract

That is, we could directly mark classes as abstract, and the default
"new" implementation would check this flag.

Option 2. Just make it work!  Have the method return some reasonable
default.  This is not an area where the system will collapse if they
get the wrong collection type; their program will simple run slowly.

     ^(self == Collection) ifTrue: [
       OrderedCollection new
     ] ifFalse: [
       super new ]


More information about the Squeak-dev mailing list