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

Klaus D. Witzel klaus.witzel at cobss.com
Wed Jan 24 20:02:26 UTC 2007


Hi Lex,

on Wed, 24 Jan 2007 17:29:49 +0100, you wrote:
> "Ralph Johnson" <johnson at cs.uiuc.edu> 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:
>
>    new
>       ^(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:
>
>    new
>       ^self newIfSubclass
>
>
> Even better, we could set things up so that this would work:
>
>    Collection class>>initialize
>       self abstract

Looks great: can be checked by default handlers and debugger, when need  
arises (and lazyness is at work).

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

Uhm, doesn't really taste good (that the default #new implementation gets  
involved into preventive error handling, I mean).

>
>
> 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.
>
>    new
>      ^(self == Collection) ifTrue: [
>        OrderedCollection new
>      ] ifFalse: [
>        super new ]

IMHO this is as hard to debug for noobs (and for pros as well, between  
02:30 and 03:45 in the morning ;-) as it is with the cause of this thread.

/Klaus

> -Lex
>
>
>
>





More information about the Squeak-dev mailing list