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

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


To be absolutely thorough, also consider how the new: message is associated
to basicNew:  or super new: and initialize: for variable subclasses - or
eventually just initialize: for those quaking like a variable subclass...

Le jeu. 5 sept. 2019 à 00:27, Thiede, Christoph <
Christoph.Thiede at student.hpi.uni-potsdam.de> a écrit :

> Okay, thank you for the really comprehensive clarification :)
>
>
> I was already aware of the "basic" meaning of #basicNew, but I also met a
> pattern that told me to only use super to call the same-named base method.
> It feels like breaking with the law of encapsulation when you can
> always refer to the base version of a method that has been explicitly
> changed in the current class.
>
>
> But I guess in this case, it is more important to deal with possible logic
> that could be introduced in (Proto)Object>>#initialize.
>
>
> Christoph
> ------------------------------
> *Von:* Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im
> Auftrag von tim Rowledge <tim at rowledge.org>
> *Gesendet:* Mittwoch, 4. September 2019 23:43:22
> *An:* The general-purpose Squeak developers list
> *Betreff:* Re: [squeak-dev] The Trunk: Collections-mt.851.mcz
>
> Well, to try to explain this mostly to Christoph, #basicNew should do only
> the primitive creation of the chunk of object memory, hence the 'basic'
> (and that does include some hacks for certain classes likeBoxedFloat etc).
> #new and other initial creation methods can do further things, like
> setting initial values of some instance variables, registering external
> resources, etc.
>
> So they do not in general work equivalently, deliberately. At the most
> basic level, #new sends #basicNew to create the memory and then #initialize
> to do the ... initialisation. If that initialize does stuff your specific
> needs would prefer to avoid, use #basicNew and your own initialisation
> sequence.
>
> As an example, consider WriteStream>on:from:to: which uses `self
> basicNew`. It could use #new without any difference in effect because there
> is no implementation of #initialize for WriteStreams until you get to the
> null version in ProtoObject.
>
> In contrast, imagine a class where the normal use needs a load of instance
> variable to be set up just so, but you have a need for a quite different
> setup and it would waste a lot of cycles to do the typical init and then
> overwrite almost all of it. That might justify a separate creation method
> that uses #basicNew and a specialised init method.
>
> There's also the question of self vs super in your original question.
> Remember, super is for case where you need to skip up the class tree
> starting in the superclass of *the class in which the method you are
> running* lives. This is *not* always the super class of the object
> executing the method. Lots of people get this wrong.
>
> There are good explanations of the real effects of this crucial point in
> the Blue Book etc and you really need an example class tree with at least 4
> level and it's too long to type here. Suffice to say that the practical
> difference between `self basicNew` and `super new` can be significant.
>
> > On 2019-09-04, at 2:07 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?
> >
> >
> >
> >
> >
> >
>
>
> tim
> --
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> Computing Dictionary: LOOP: (go to LOOP)
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190905/bbad3db5/attachment-0001.html>


More information about the Squeak-dev mailing list