[squeak-dev] The Trunk: Collections-mt.851.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Wed Sep 4 22:05:52 UTC 2019


The funny thing is that the object class (a Metaclass) is yet another
object than the new instance.
It thus has absolutely no other way to control the construction of this new
instance, than to kindly ask the instance by sending a message initialize.
Even if it may sound more imperative like object setThisTo: 1 andThatTo:
Array new, only the instance knows how it will do it (or just fake).
Somehow the instance is thrown away un-initialized in the world, and we try
to repair ASAP. I wonder how Newspeak resolved this.

Systematic send of initialize in Behavior was a relatively late decision
(not in Smalltalk-80), that's why I was speaking of method age: self
basicNew initialize was the old way to do it indeed, left at discretion of
classes when there were no generic initialize method in Object
(ProtoObject).

We can agree that super new is the canonical way to instantiate when
additional behavior is required, with exceptions when super new or self
initialize won't do the right thing. And instance side initialize should
better super initialize too, generally.

Le mer. 4 sept. 2019 à 23:58, Chris Cunningham <cunningham.cb at gmail.com> a
écrit :

> Non-scientific sampling, there are many places where new sends basicNew
> initialize, so the sender either wasn't aware new already did that, or
> didn't trust Behaviour>>new to keep doing that.  Those can obviously just
> be fixed if desired.  (Monticello code seems rife with this, interestingly).
>
> One specifically called out "Superclasses might [do something wrong]" to
> justify calling #basicNew in #new.  Many callers are class side methods
> that intentionally setup the variables in subsequent calls to the instance
> created by #basicNew, such as DateAndTime.
>
> So, a mishmash of reasons.
>
> -cbc
>
> On Wed, Sep 4, 2019 at 2:08 PM Nicolas Cellier <
> nicolas.cellier.aka.nice at gmail.com> wrote:
>
>> Hmm, I just starred at method 'source with it' in a SpurVMMaker image and
>> got
>> - 252 hits for 'self basicNew';
>> - 109 hits for 'super new'.
>>
>> So it might depend on context... This would deserve more statistics (age
>> of method, initials, whether new is raising an Error or not, whether
>> instance side initialize does nothing or the wrong thing, etc...)
>>
>> Le mer. 4 sept. 2019 à 22:38, tim Rowledge <tim at rowledge.org> a écrit :
>>
>>>
>>>
>>> > On 2019-09-04, at 12:58 PM, Thiede, Christoph <
>>> Christoph.Thiede at student.hpi.uni-potsdam.de> wrote:
>>> >
>>> > Thank you :)
>>> >
>>> > A very minor question: Would you favor [self basicNew] over [super
>>> new]? It will work completely equivalently, but what is the better style?
>>>
>>> ^super new
>>>
>>> `self basicNew` will not always work equivalently. And I can almost
>>> guarantee it will always do the wrong thing just when you feel sure it is
>>> doing the right thing. And you will suffer Debugging Hell.
>>>
>>>
>>> tim
>>> --
>>> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
>>> Why use one word when two polysyllabic agglomerates will do?
>>>
>>>
>>>
>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190905/5f588f5d/attachment.html>


More information about the Squeak-dev mailing list