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 http://stephane.ducasse.free.fr / http://www.pharo.org 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
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
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 <sean@clipperadams.com> 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
participants (3)
-
Reg Krock -
Sean P. DeNigris -
Stéphane Ducasse