asSortedCollection always copies?

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

asSortedCollection always copies?

Ralph Boland
I am using Squeak 10.2 and haven't checked 4.2 so apologies if this doesn't
apply to 4.2.  I checked 4.1 though and the problem is in 4.1 also.

Method asSet returns self for sets and method asArray returns self for arrays
but asSortedCollection returns a copy of the sortedCollection for
SortedCollections.

This inconsistency constitutes a bug to my mind.
Unless someone disagrees I will generate a bug report.
Pointing out that the this is fixed in 4.2 constitutes disagreement.
(If you fix the bug for 4.3 and then post that it is fixed saves me
generating the bug report; of course you shouldn't do this).

Regards,

Ralph Boland

Reply | Threaded
Open this post in threaded view
|

Re: asSortedCollection always copies?

Frank Shearar
On 2011/05/06 21:50, Ralph Boland wrote:

> I am using Squeak 10.2 and haven't checked 4.2 so apologies if this doesn't
> apply to 4.2.  I checked 4.1 though and the problem is in 4.1 also.
>
> Method asSet returns self for sets and method asArray returns self for arrays
> but asSortedCollection returns a copy of the sortedCollection for
> SortedCollections.
>
> This inconsistency constitutes a bug to my mind.
> Unless someone disagrees I will generate a bug report.
> Pointing out that the this is fixed in 4.2 constitutes disagreement.
> (If you fix the bug for 4.3 and then post that it is fixed saves me
> generating the bug report; of course you shouldn't do this).

Mm, SortedCollection behaves the same as OrderedCollection, in returning
a copy (via #newFrom:), for what it's worth.

frank


Reply | Threaded
Open this post in threaded view
|

Re: asSortedCollection always copies?

Nicolas Cellier
In reply to this post by Ralph Boland
However, you will have a difference depending on whether you copy or not:

((1 to: 3) asSortedCollection: [:a :b | a >= b]) asSortedCollection.

Nicolas

2011/5/6 Ralph Boland <[hidden email]>:

> I am using Squeak 10.2 and haven't checked 4.2 so apologies if this doesn't
> apply to 4.2.  I checked 4.1 though and the problem is in 4.1 also.
>
> Method asSet returns self for sets and method asArray returns self for arrays
> but asSortedCollection returns a copy of the sortedCollection for
> SortedCollections.
>
> This inconsistency constitutes a bug to my mind.
> Unless someone disagrees I will generate a bug report.
> Pointing out that the this is fixed in 4.2 constitutes disagreement.
> (If you fix the bug for 4.3 and then post that it is fixed saves me
> generating the bug report; of course you shouldn't do this).
>
> Regards,
>
> Ralph Boland
>
>

Reply | Threaded
Open this post in threaded view
|

asSortedCollection always copies?

Louis LaBrunda
In reply to this post by Ralph Boland
Hi Ralph,

I'm not disagreeing with you but the latest version of VA Smalltalk also
answers a copy for SortedCollection and OrderedCollection.  I don't know
why but there must be a reason?  Below is their code from SortedCollection.


asSortedCollection
        "Answer a new instance of SortedCollection
         whose elements are the elements of the
         receiver.  The sort order is the same as the
         receivers sort order."

        ^self copyAndGrowBy: 0
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:[hidden email] http://www.Keystone-Software.com


Reply | Threaded
Open this post in threaded view
|

Re: asSortedCollection always copies?

Nicolas Cellier
Which is a different behaviour than VW/Squeak/Pharo which all will
reset sort order to default.

Nicolas

2011/5/6 Louis LaBrunda <[hidden email]>:

> Hi Ralph,
>
> I'm not disagreeing with you but the latest version of VA Smalltalk also
> answers a copy for SortedCollection and OrderedCollection.  I don't know
> why but there must be a reason?  Below is their code from SortedCollection.
>
>
> asSortedCollection
>        "Answer a new instance of SortedCollection
>         whose elements are the elements of the
>         receiver.  The sort order is the same as the
>         receivers sort order."
>
>        ^self copyAndGrowBy: 0
> -----------------------------------------------------------
> Louis LaBrunda
> Keystone Software Corp.
> SkypeMe callto://PhotonDemon
> mailto:[hidden email] http://www.Keystone-Software.com
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: asSortedCollection always copies?

Levente Uzonyi-2
In reply to this post by Ralph Boland
On Fri, 6 May 2011, Ralph Boland wrote:

> I am using Squeak 10.2 and haven't checked 4.2 so apologies if this doesn't
> apply to 4.2.  I checked 4.1 though and the problem is in 4.1 also.
>
> Method asSet returns self for sets and method asArray returns self for arrays
> but asSortedCollection returns a copy of the sortedCollection for
> SortedCollections.
>
> This inconsistency constitutes a bug to my mind.
> Unless someone disagrees I will generate a bug report.
> Pointing out that the this is fixed in 4.2 constitutes disagreement.
> (If you fix the bug for 4.3 and then post that it is fixed saves me
> generating the bug report; of course you shouldn't do this).

I'd call it a design flaw. IMHO it's pretty hard to change, because some
code may rely on copying. But it's on my todo list since the early days of
the new community developement model.
For the note: #asOrderedCollection and #asCharacterSet are also creating
copies no matter what the receiver is.

The case of #asSortedCollection has a simple solution: don't use it.
There's 99.9% chance that you don't need a SortedCollection. If you
want to sort a Collection, then use #sort, #sorted, #sort: or #sorted:.

I have a plan for fixing SortedCollection, but it has really-really low
priority on my todo list, because we already have something better. :)


Levente

>
> Regards,
>
> Ralph Boland
>
>