Name:
SLICE-Issue-11635-Race-condition-in-SequenceableCollectionshuffle-MaxLeske.2
Author: MaxLeske
Time: 30 October 2013, 1:41:57.198092 pm
UUID: c3d51645-7e81-4997-b74c-545bf7ef60b0
Ancestors:
Dependencies: Collections-Abstract-MaxLeske.231,
Collections-Unordered-MaxLeske.175
made changes as detailed on the mailing list
* shuffle
^ self shuffleBy: Random new
* shuffled
^ self copy shuffle
* removed #shuffledBy:
* Matrix uses #shuffleBy: (on an explicit copy) instead of #shuffledBy:
On 01.10.2013, at 17:06, Henrik Johansen <[email protected]> wrote:
>
> On Sep 28, 2013, at 10:59 , Max Leske <[email protected]> wrote:
>
>> Thanks for the feedback guys.
>>
>> Based on the discussion I propose a different set of changes:
>>
>> 1.
>> shuffle
>> ^ self shuffleBy: Random new
>>
>> 2.
>> shuffled
>> ^ self copy shuffle
>>
>> 3. remove #shuffledBy: (if you're specific enough to use a custom Random
>> instance you can also create a copy of the collection yourself if you want
>> to)
>>
>>
>> I leave the matter of renaming the methods for further discussion.
>> Personally I'm for more intention revealing selectors; I quite like #shuffle
>> and #shuffleInPlace. If we can agree on a different naming scheme we should
>> then apply it to other methods aswell of course (e.g. #sort, #sortInPlace).
>>
>> Also open for discussion is the use of Collection>>randomForPicking and
>> Collection>>mutexForPicking in other methods (such as #atRandom). I think it
>> shouldn't be too big a problem to make those methods use individual Random
>> instances and to remove the two class variables from Collection.
>>
>> Cheers,
>> Max
>
> +1 from me on all three suggestions, as you might guess. :)
>
> As for #atRandom using Random new, the performance hit and seed quality would
> be much greater concerns, as the Random instance would only be used once per
> invocation.
> At this point in time there's no good alternatives to the current approach,
> but renaming the mutex/shared variable to reflect its singular use would be
> one possible improvement, I guess.
>
> Cheers,
> Henry