what is newFrom:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

what is newFrom:

Stéphane Ducasse
Hi 

I’m spotting real inconsistency in the specification and use of newFrom: 

In Pharo and Object we have 

newFrom: aSimilarObject
"Create an object that has similar contents to aSimilarObject. If the classes have any instance variables with the same names, copy them across. If this is bad for a class, override this method."

^ (self isVariable
ifTrue: [self basicNew: aSimilarObject basicSize]
ifFalse: [self basicNew]) copySameFrom: aSimilarObject

The ANSI standard does not define newFrom: 

Now in Pharo some classes such dictionary expect as argument a dictionary but OrderedDictionary expects a like of association!

Set expects a collection, 
Bag too and many others.
CompiledMethod expects a compiledMethod

I think that it would be good to strengthen this method and we could define newFromSibling: but it looks like a copy to me. 

S
--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Aurore Dalle 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France

Reply | Threaded
Open this post in threaded view
|

Re: what is newFrom:

Sean P. DeNigris
Administrator
Stéphane Ducasse wrote
> I’m spotting real inconsistency in the specification and use of newFrom:

I recently thought something similar when working with ArrayedCollection. As
you say, here is yet another inconsistency because it doesn't return a
"similar object", but just copies the elements of the collection argument
into an instance of itself with the same size. There is also
ArrayedCollection class >> #withAll: which seems to do the same, but neither
delegates to the other and they have different implementations.



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: what is newFrom:

Pharo Smalltalk Developers mailing list
I have seen #newFrom: in many places while working Smalltalk. I have never assumed it would be a ‘similar’ object.

Also, what is the meaning of ‘similar’?

Since all objects have same ancestor, Object, one could argue any returned object is similar.

Regards,

Reg

Sent from my iPhone

> On Jul 23, 2020, at 10:09 AM, Sean P. DeNigris <[hidden email]> wrote:
>
> Stéphane Ducasse wrote
>> I’m spotting real inconsistency in the specification and use of newFrom:
>
> I recently thought something similar when working with ArrayedCollection. As
> you say, here is yet another inconsistency because it doesn't return a
> "similar object", but just copies the elements of the collection argument
> into an instance of itself with the same size. There is also
> ArrayedCollection class >> #withAll: which seems to do the same, but neither
> delegates to the other and they have different implementations.
>
>
>
> -----
> Cheers,
> Sean
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
>