8.0.1 sorted changes lead to different sorting

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

8.0.1 sorted changes lead to different sorting

Postby Michael Keppler » Sun Jun 20, 2010 9:24 pm

Hi all, I experience different sorted collections after migration to 8.0.2, compared to 7.5.1. And I also found the reason in the "sorted" changes for Seaside.

If you need a testcase, just run this code on 8.0.2 and 7.5.1, the order will be different afterwards:
Code: Select all
(OrderedCollection with: '11' with: '12') asSortedCollection: [:a :b |
   (a size ~= b size) ifTrue: [
      a size > b size.
   ]
   ifFalse: [
      true.
   ].
].


The most interesting point is: If you try to debug that test case, it will return the 7.5.1 result. Only when it is executed as a single block, it returns a different result. Therefore I removed my theory of where the bug is located (which you might have seen in the first version of this post).
Michael Keppler
 
Posts: 28
Joined: Wed Feb 27, 2008 4:33 am

Re: 8.0.1 sorted changes lead to different sorting

Postby Michael Keppler » Sun Jun 20, 2010 10:32 pm

I found the reason. The SeaSide "sorted" migration should have replaced all "sorted:" by "isSorted:". This has not happened in
Code: Select all
Collection>>#asSortedCollection:


If the offending line is changed there, everything works fine again.
Michael Keppler
 
Posts: 28
Joined: Wed Feb 27, 2008 4:33 am

Re: 8.0.1 sorted changes lead to different sorting

Postby wembley » Sun Jun 27, 2010 3:06 pm

Michael -

I'm a bit confused. Here is Collection>>#asSortedColection: that is shipped in VA Smalltalk V8.0.2

Code: Select all
asSortedCollection: aBlock

   "Answer a new instance of SortedCollection whose elements are the
    elements of the receiver.  The sort order is defined by the two
    argument block, aBlock.  Each argument of the block represents
    an potential Object within the collection.  The block body contains
    code returning a Boolean which is true if the items need not be
    exchanged in terms of ordering and false if they are to be exchanged.

    Fail if aBlock is not a two-argument Block."

   ^(SortedCollection new: self size)
      sortBlock: aBlock;
      addAll: self;
      yourself

I don't see any reference to #sorted: in the method.
John O'Keefe [|], Principal Smalltalk Architect, Instantiations Inc.
wembley
Moderator
 
Posts: 405
Joined: Mon Oct 16, 2006 3:01 am
Location: Durham, NC

Re: 8.0.1 sorted changes lead to different sorting

Postby Michael Keppler » Mon Jun 28, 2010 2:29 am

Sorry, you are completely right. We introduced a change in that method in 1998. And that change was wrongly included when we merged our existing 7.5.1 application with the new VAST 8.0.2.

Please accept my apologies.
Michael Keppler
 
Posts: 28
Joined: Wed Feb 27, 2008 4:33 am

Re: 8.0.1 sorted changes lead to different sorting

Postby wembley » Mon Jun 28, 2010 3:31 am

Michael -

Don't worry about it -- I'm just glad the issue is resolved.
John O'Keefe [|], Principal Smalltalk Architect, Instantiations Inc.
wembley
Moderator
 
Posts: 405
Joined: Mon Oct 16, 2006 3:01 am
Location: Durham, NC

Re: 8.0.1 sorted changes lead to different sorting

Postby Michael Keppler » Mon Jun 28, 2010 5:49 am

Ok, now it gets even more confusing: If I use clean 7.5.1 or 8.0.x images, the sorting is still wrong. After some debates with colleagues we found that our change _fixed_ the problem for us in all previous versions.

So, if you take my test code from the previous posting, _execute_ it, it will sort the elements in order "12", "11", although they should not change their order.

If you take my code and instead _debug_ it, the sorting will be correct (i.e. the bug not reproducable), because one of the printOn methods modifies the sortedCollection. If you implement SortedCollection>>#printOn: as empty method,then also the debugging will show the wrong sorting.
Michael Keppler
 
Posts: 28
Joined: Wed Feb 27, 2008 4:33 am


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: No registered users and 1 guest