Is there any particular reason why we don't have OrderedCollection >>
#asOrderedCollection simply return self? Right now (OrderedCollection with: 1) asOrderedCollection calls Collection >> #asOrderedCollection, which calls self as: OrderedCollection, which copies the collection. This would also make OrderedCollection work a bit more like Array - Array >> #asArray simply returns self. frank |
On 18.07.2012, at 14:08, Frank Shearar wrote:
> Is there any particular reason why we don't have OrderedCollection >> > #asOrderedCollection simply return self? > > Right now (OrderedCollection with: 1) asOrderedCollection calls > Collection >> #asOrderedCollection, which calls self as: > OrderedCollection, which copies the collection. > > This would also make OrderedCollection work a bit more like Array - > Array >> #asArray simply returns self. > > frank Here's my guess: The typical use cases for asOrderedCollection and asArray are different. If you send asOrderedCollection you probably want to add more objects to it. If you send asArray you normally won't modify the result. So in a way, you could see asOrderedCollection as the normal "safe" case which ensures the original is unmodified, and the asArray behavior as an optimization. - Bert - |
On 18 July 2012 22:33, Bert Freudenberg <[hidden email]> wrote:
> On 18.07.2012, at 14:08, Frank Shearar wrote: > >> Is there any particular reason why we don't have OrderedCollection >> >> #asOrderedCollection simply return self? >> > >> Right now (OrderedCollection with: 1) asOrderedCollection calls >> Collection >> #asOrderedCollection, which calls self as: >> OrderedCollection, which copies the collection. >> >> This would also make OrderedCollection work a bit more like Array - >> Array >> #asArray simply returns self. >> >> frank > > > Here's my guess: > > The typical use cases for asOrderedCollection and asArray are different. If you send asOrderedCollection you probably want to add more objects to it. If you send asArray you normally won't modify the result. > > So in a way, you could see asOrderedCollection as the normal "safe" case which ensures the original is unmodified, and the asArray behavior as an optimization. That sounds reasonable, I suppose. Neither really fits how I use the SequenceableCollections, mind you. I'd be happier with a purely functional implementation that quietly shared (immutable) structure behind the scenes. frank > - Bert - > > > |
On 18.07.2012, at 14:40, Frank Shearar wrote: > On 18 July 2012 22:33, Bert Freudenberg <[hidden email]> wrote: >> On 18.07.2012, at 14:08, Frank Shearar wrote: >> >>> Is there any particular reason why we don't have OrderedCollection >> >>> #asOrderedCollection simply return self? >>> >> >>> Right now (OrderedCollection with: 1) asOrderedCollection calls >>> Collection >> #asOrderedCollection, which calls self as: >>> OrderedCollection, which copies the collection. >>> >>> This would also make OrderedCollection work a bit more like Array - >>> Array >> #asArray simply returns self. >>> >>> frank >> >> >> Here's my guess: >> >> The typical use cases for asOrderedCollection and asArray are different. If you send asOrderedCollection you probably want to add more objects to it. If you send asArray you normally won't modify the result. >> >> So in a way, you could see asOrderedCollection as the normal "safe" case which ensures the original is unmodified, and the asArray behavior as an optimization. > > That sounds reasonable, I suppose. > > Neither really fits how I use the SequenceableCollections, mind you. > I'd be happier with a purely functional implementation that quietly > shared (immutable) structure behind the scenes. > > frank So optimizations aside, you are happier with the way asOrderedCollection works now, because it ensures the original collection is not affected? - Bert - |
In VA Smalltalk OrderedCollection>asOrderedCollection answers a copy and it looks like it has done so since mid 1996. Lou On Wed, 18 Jul 2012 14:45:44 -0700, Bert Freudenberg <[hidden email]> wrote: > >On 18.07.2012, at 14:40, Frank Shearar wrote: > >> On 18 July 2012 22:33, Bert Freudenberg <[hidden email]> wrote: >>> On 18.07.2012, at 14:08, Frank Shearar wrote: >>> >>>> Is there any particular reason why we don't have OrderedCollection >> >>>> #asOrderedCollection simply return self? >>>> >>> >>>> Right now (OrderedCollection with: 1) asOrderedCollection calls >>>> Collection >> #asOrderedCollection, which calls self as: >>>> OrderedCollection, which copies the collection. >>>> >>>> This would also make OrderedCollection work a bit more like Array - >>>> Array >> #asArray simply returns self. >>>> >>>> frank >>> >>> >>> Here's my guess: >>> >>> The typical use cases for asOrderedCollection and asArray are different. If you send asOrderedCollection you probably want to add more objects to it. If you send asArray you normally won't modify the result. >>> >>> So in a way, you could see asOrderedCollection as the normal "safe" case which ensures the original is unmodified, and the asArray behavior as an optimization. >> >> That sounds reasonable, I suppose. >> >> Neither really fits how I use the SequenceableCollections, mind you. >> I'd be happier with a purely functional implementation that quietly >> shared (immutable) structure behind the scenes. >> >> frank > >So optimizations aside, you are happier with the way asOrderedCollection works now, because it ensures the original collection is not affected? > >- Bert - > > > Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:[hidden email] http://www.Keystone-Software.com |
In reply to this post by Frank Shearar-3
On Wed, 18 Jul 2012, Frank Shearar wrote:
> Is there any particular reason why we don't have OrderedCollection >> > #asOrderedCollection simply return self? There are other as* methods which return a copy. Unifying them would be nice, but I'm sure it'd break lots of packages. Levente > > Right now (OrderedCollection with: 1) asOrderedCollection calls > Collection >> #asOrderedCollection, which calls self as: > OrderedCollection, which copies the collection. > > This would also make OrderedCollection work a bit more like Array - > Array >> #asArray simply returns self. > > frank > > |
In reply to this post by Bert Freudenberg
On Wed, 18 Jul 2012, Bert Freudenberg wrote:
> On 18.07.2012, at 14:08, Frank Shearar wrote: > >> Is there any particular reason why we don't have OrderedCollection >> >> #asOrderedCollection simply return self? >> > >> Right now (OrderedCollection with: 1) asOrderedCollection calls >> Collection >> #asOrderedCollection, which calls self as: >> OrderedCollection, which copies the collection. >> >> This would also make OrderedCollection work a bit more like Array - >> Array >> #asArray simply returns self. >> >> frank > > > Here's my guess: > > The typical use cases for asOrderedCollection and asArray are different. If you send asOrderedCollection you probably want to add more objects to it. If you send asArray you normally won't modify the result. The name "as*" suggests me that the method won't make a copy if the receiver is already what I'm asking for. If I want to modify the returned collection, but leave the original one intact, then I'll send #copy. > > So in a way, you could see asOrderedCollection as the normal "safe" case which ensures the original is unmodified, and the asArray behavior as an optimization. This kind of safety has a huge cost in some cases, for example this is why so many people implement their own network streaming code. The less copies are made the higher throughput can be achieved. Levente > > - Bert - > > > > |
In reply to this post by Bert Freudenberg
On Wed, Jul 18, 2012 at 02:33:23PM -0700, Bert Freudenberg wrote:
> On 18.07.2012, at 14:08, Frank Shearar wrote: > > > Is there any particular reason why we don't have OrderedCollection >> > > #asOrderedCollection simply return self? > > > > > Right now (OrderedCollection with: 1) asOrderedCollection calls > > Collection >> #asOrderedCollection, which calls self as: > > OrderedCollection, which copies the collection. > > > > This would also make OrderedCollection work a bit more like Array - > > Array >> #asArray simply returns self. > > > > frank > > > Here's my guess: > > The typical use cases for asOrderedCollection and asArray are different. If you send asOrderedCollection you probably want to add more objects to it. If you send asArray you normally won't modify the result. > > So in a way, you could see asOrderedCollection as the normal "safe" case which ensures the original is unmodified, and the asArray behavior as an optimization. > > - Bert - > It also ensures that subclasses respond reasonably to #asOrderedCollection. For example, if you send #asOrderedCollection to a WeakOrderedCollection or a SortedCollection, it is probably because you actually want to obtain an OrderedCollection: (WeakOrderedCollection withAll: #(1 2 3 4)) asOrderedCollection ==> an OrderedCollection(1 2 3 4) (SortedCollection withAll: #(4 2 3 1)) asOrderedCollection ==> an OrderedCollection(1 2 3 4) Dave |
On 19 July 2012 00:46, David T. Lewis <[hidden email]> wrote:
> On Wed, Jul 18, 2012 at 02:33:23PM -0700, Bert Freudenberg wrote: >> On 18.07.2012, at 14:08, Frank Shearar wrote: >> >> > Is there any particular reason why we don't have OrderedCollection >> >> > #asOrderedCollection simply return self? >> > >> >> > Right now (OrderedCollection with: 1) asOrderedCollection calls >> > Collection >> #asOrderedCollection, which calls self as: >> > OrderedCollection, which copies the collection. >> > >> > This would also make OrderedCollection work a bit more like Array - >> > Array >> #asArray simply returns self. >> > >> > frank >> >> >> Here's my guess: >> >> The typical use cases for asOrderedCollection and asArray are different. If you send asOrderedCollection you probably want to add more objects to it. If you send asArray you normally won't modify the result. >> >> So in a way, you could see asOrderedCollection as the normal "safe" case which ensures the original is unmodified, and the asArray behavior as an optimization. >> >> - Bert - >> > > It also ensures that subclasses respond reasonably to #asOrderedCollection. > For example, if you send #asOrderedCollection to a WeakOrderedCollection > or a SortedCollection, it is probably because you actually want to obtain > an OrderedCollection: > > (WeakOrderedCollection withAll: #(1 2 3 4)) asOrderedCollection > ==> an OrderedCollection(1 2 3 4) > > (SortedCollection withAll: #(4 2 3 1)) asOrderedCollection > ==> an OrderedCollection(1 2 3 4) OK, but that's neither here nor there, because those could convert themselves with #as:. Levente nailed what surprised me, but that might well be only because I had just read Array >> #asArray. 'as' implies conversion which, in _my_ head means 'only convert if necessary'. But this change does have the potential to break many things in very bad ways, as OCs that were copies (so safe from mutation) suddenly aren't. Those kinds of bugs will be hard to decipher, so maybe it's better just to leave the method unchanged and hold my nose. frank > Dave > > |
In reply to this post by Levente Uzonyi-2
On 7/18/12, Levente Uzonyi <[hidden email]> wrote:
> On Wed, 18 Jul 2012, Bert Freudenberg wrote: > >> On 18.07.2012, at 14:08, Frank Shearar wrote: >> >>> Is there any particular reason why we don't have OrderedCollection >> >>> #asOrderedCollection simply return self? >>> >> >>> Right now (OrderedCollection with: 1) asOrderedCollection calls >>> Collection >> #asOrderedCollection, which calls self as: >>> OrderedCollection, which copies the collection. >>> >>> This would also make OrderedCollection work a bit more like Array - >>> Array >> #asArray simply returns self. >>> >>> frank >> >> >> Here's my guess: >> >> The typical use cases for asOrderedCollection and asArray are different. >> If you send asOrderedCollection you probably want to add more objects to >> it. If you send asArray you normally won't modify the result. > > The name "as*" suggests me that the method won't make a copy if the > receiver is already what I'm asking for. If I want to modify the returned > collection, but leave the original one intact, then I'll send #copy. > +1 This is how I learned Smalltalk. asNNN does a conversion in case it is necessary otherwise if the object is already of type NNN I get back the object as is. --Hannes >> >> So in a way, you could see asOrderedCollection as the normal "safe" case >> which ensures the original is unmodified, and the asArray behavior as an >> optimization. > > This kind of safety has a huge cost in some cases, for example this > is why so many people implement their own network streaming code. The less > copies are made the higher throughput can be achieved. > > > Levente > >> >> - Bert - >> >> >> >> > > |
Free forum by Nabble | Edit this page |