Re: [Pharo-dev] newFrom: vs. withAll:
stepharo wrote > Hi guys > > I was looking at the Collection chapter and I stumbled upon newFrom: and > I wonder what is the real > difference between newFrom: and withAll:. > I have the impression that there is not much difference. There are only > 47 senders of newFrom: in the default Pharo image. > > Dictionary class>>withAll: interprets its argument as a collection of > values, > whereas Dictionary class>>newFrom: expects a collection of associations. > > I would really deprecate newFrom: in the future. > > Stef Absent a compelling argument for deviating from the ANSI standard, it would be best to adhere to the standard. #withAll: doesn't make sense to treat the argument as supplying the values, as there is nothing to define the keys. suggests the only protocol needed for the argument would be #keysAndValuesDo: (but it /isn't/ specified as such). ANSI specifies #withAll: as having an effect "the same as evaluating Dictionary new addAll: newElements; yourself." #addAll: is shown with "dictionary" for the argument name and typed as . -- View this message in context: http://forum.world.st/newFrom-vs-withAll-tp4876589p4876674.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Re: [Pharo-dev] newFrom: vs. withAll:
Hi guys I was looking at the Collection chapter and I stumbled upon newFrom: and I wonder what is the real difference between newFrom: and withAll:. I have the impression that there is not much difference. There are only 47 senders of newFrom: in the default Pharo image. Dictionary class>>withAll: interprets its argument as a collection of values, whereas Dictionary class>>newFrom: expects a collection of associations. I would really deprecate newFrom: in the future. Stef I can understand using anObject newFrom: anotherObject 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 copySameFrom: otherObject "Copy to myself all instance variables named the same in otherObject. This ignores otherObject's control over its own inst vars." | myInstVars otherInstVars | myInstVars := self class allInstVarNames. otherInstVars := otherObject class allInstVarNames. myInstVars doWithIndex: [:each :index | | match | (match := otherInstVars indexOf: each) > 0 ifTrue: [self instVarAt: index put: (otherObject instVarAt: match)]]. 1 to: (self basicSize min: otherObject basicSize) do: [:i | self basicAt: i put: (otherObject basicAt: i)]. but I do not see the point to use this protocol over withAll: for collection. And in general I would prefer to call it cloneFrom: Stef
[Pharo-dev] newFrom: vs. withAll:
Hi guys I was looking at the Collection chapter and I stumbled upon newFrom: and I wonder what is the real difference between newFrom: and withAll:. I have the impression that there is not much difference. There are only 47 senders of newFrom: in the default Pharo image. Dictionary class>>withAll: interprets its argument as a collection of values, whereas Dictionary class>>newFrom: expects a collection of associations. I would really deprecate newFrom: in the future. Stef