<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
                                        Hi Levente.<div><br></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">> It would be great to change OrderedCollection class >> #new: to return a</span><br style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">> non-empty collection, and create a new method, e.g. #newWithCapacity: to</span><br style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">> create an empty collection with the given capacity, but I don't think it's</span><br style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">> possible to do that without breaking almost all existing programs out</span><br style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">> there.</span><br></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">I agree, given that most implementations of #new: cover array-like structures and thus expose the idea of "capacity" in client code. From personal experience, I tried, occasionally, to be clever ^_^ and pre-allocate some capacity in an OrderedCollection via #new:. Yet, I would not generalize this kind of anti-pattern. Maybe such a change would not be as severe as you fear. At least not for OrderedCollection.</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">(Collection allSubclasses</span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><span style="white-space:pre"> </span>sorted: [:a :b | a name <= b name])</span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><span style="white-space:pre">     </span>collect: [:each | each -> ([(each new: 10) size] ifError: [:m | m])]</span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><span style="white-space: pre;">  </span>as: OrderedDictionary.</span></span></div></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><br></span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">Here are the results:</span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><br></span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">21x Error</span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">27x 0</span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">40x 10</span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">1x 100 (Matrix)</span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><br></span></span></div><div style=""><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">So, it looks like that your feeling is right. For Trunk, we could easily check whether the #new: cases cover the "0" or the "10". I suspect the latter because Array.</span></span></div><div><br></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">For MethodDictionary, you added a #newForCapacity: in 2011. :-) </span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">> </span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">So, the question is: should there be #collect:as:separatedBy: too?</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">Yeah, looks like it. I will add it to the inbox.</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">Best,</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">Marcel</span></div><div class="mb_sig"></div>
                                        <blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px">
                        <p style="color: #AAAAAA; margin-top: 10px;">Am 14.04.2021 19:17:55 schrieb Levente Uzonyi <leves@caesar.elte.hu>:</p><div style="font-family:Arial,Helvetica,sans-serif">Hi Marcel,<br><br>Due to the flaw of OrderedCollection >> #new:, the code won't work with <br>OrderedCollections (and its subclasses).<br>This is the same issue Tim found with OrderedCollection and <br>#streamContents: the other day.<br>The current workaround is to use #ofSize: instead of #new: to create a <br>non-empty instance with the given capacity.<br>It would be great to change OrderedCollection class >> #new: to return a <br>non-empty collection, and create a new method, e.g. #newWithCapacity: to <br>create an empty collection with the given capacity, but I don't think it's <br>possible to do that without breaking almost all existing programs out <br>there.<br><br>The code won't work with LinkedList either because of the same reason. So, <br>that class will need its own implementation.<br><br>The code also suffers from #collect:'s problem, which is its reliance on <br>#species. #species is used for way too many things, and a single method <br>cannot fit all those roles.<br>The fix for that is #collect:as:, which lets the user decide what the <br>class of the result should be.<br>So, the question is: should there be #collect:as:separatedBy: too?<br><br><br>Levente<br><br>On Wed, 14 Apr 2021, commits@source.squeak.org wrote:<br><br>> A new version of Collections was added to project The Inbox:<br>> http://source.squeak.org/inbox/Collections-mt.938.mcz<br>><br>> ==================== Summary ====================<br>><br>> Name: Collections-mt.938<br>> Author: mt<br>> Time: 14 April 2021, 2:38:21.265628 pm<br>> UUID: d109bde4-42a6-e840-803c-e4e80b98a74d<br>> Ancestors: Collections-mt.937<br>><br>> Proposal. Add a #joinSeparatedBy: that does not end up as a string.<br>><br>> The current alternative would be #gather<br>> (#(1 2 3 4 5) gather: [:each | {each . $x}]) allButLast.<br>><br>> Not sure whether a non-sequenceable version in Collection makes sense. We have had that discussion about #join etc. being not useful for uncertain output order.<br>><br>> Some benchmarks:<br>><br>> [ ((1 to: 1000) gather: [:num | {num . $x}]) allButLast ] bench.<br>> '22,000 per second. 45.5 microseconds per run. 13.09738 % GC time.'<br>><br>> [ (1 to: 1000) collect: [:num | num] separatedBy: [$x] ] bench.<br>> '26,000 per second. 38.5 microseconds per run. 1.73965 % GC time.'<br>><br>> =============== Diff against Collections-mt.937 ===============<br>><br>> Item was added:<br>> + ----- Method: Collection>>collect:separatedBy: (in category 'enumerating') -----<br>> + collect: elementBlock separatedBy: separatorBlock<br>> +         "Evaluate the elementBlock for all elements in the receiver, and evaluate the separatorBlock between. Collect the resulting values of both blocks into a collection like the receiver. Answer the new collection."<br>> + <br>> +   | newCollection |<br>> +       newCollection := self species new.<br>> +      self<br>> +            do: [:each | newCollection add: (elementBlock value: each)]<br>> +             separatedBy: [:each | newCollection add: separatorBlock value].<br>> +         ^ newCollection!<br>><br>> Item was added:<br>> + ----- Method: SequenceableCollection>>collect:separatedBy: (in category 'enumerating') -----<br>> + collect: elementBlock separatedBy: separatorBlock<br>> +       "Evaluate the elementBlock for all elements in the receiver, and evaluate the separatorBlock between. Collect the resulting values of both blocks into a collection like the receiver. Answer the new collection."<br>> + <br>> +   | newCollection |<br>> +       newCollection := self species new: self size *2 -1.<br>> +     1 to: self size do: [:index |<br>> +           index = 1 ifFalse: [newCollection at: (index-1 *2) put: separatorBlock value].<br>> +          newCollection at: (index-1 *2)+1 put: (elementBlock value: (self at: index))].<br>> +  ^ newCollection!<br><br></div></blockquote></div>