[squeak-dev] Review Request: Bag printString

David T. Lewis lewis at mail.msen.com
Sat Feb 26 22:07:57 UTC 2022


This seems easier to read for the case of a Bag containing
many copies of the same entry, and harder to read for the
case of a Bag containing mostly different entries. I am not
sure which is the more common scenario.

The original printString hides the implementation, which seems
like a good thing.

Either approach would be fine for me, although I think I slightly
prefer the original version.

Dave

On Sat, Feb 26, 2022 at 08:49:48PM +0100, christoph.thiede at student.hpi.uni-potsdam.de wrote:
> =============== Summary ===============
> 
> Change Set:????????Bag printString
> Date:????????????26 February 2022
> Author:????????????Christoph Thiede
> 
> This changeset customizes the Bag printString to no longer emit every occurence of each element repeatedly.
> 
> Example:
> ????{10 @ 10. 10 @ 10. 20 @ 20. 20 @ 20. 20 @ 20. 30 @ 30. 30 @ 30. 40 @ 40} asBag. 'a Bag(10 at 10->2 20 at 20->3 30 at 30->2 40 at 40->1)'.
> 
> Thanks to Robert (rhi) for the hint!
> 
> =============== Diff ===============
> 
> Bag>>printElementsOn: {printing} ? ct 2/26/2022 20:26
> + printElementsOn: aStream
> + 
> + ????contents printElementsOn: aStream.
> 
> BagTest>>testPrintString {tests} ? ct 2/26/2022 20:25
> + testPrintString
> + 
> + ????| bag |
> + ????bag := Bag new.
> + ????bag add: '1' withOccurrences: 5.
> + ????bag add: '2' withOccurrences: 1.
> + ????bag add: '3' withOccurrences: 3.
> + ????
> + ????self assert: 'a Bag(''1''->5 ''2''->1 ''3''->3)' equals: bag printString.
> 
> Dictionary>>printElementsOn: {printing} ? ct 2/26/2022 20:28 (changed)
> printElementsOn: aStream 
> ????aStream nextPut: $(.
> ????self size > 100
> ????????ifTrue: [aStream nextPutAll: 'size '.
> ????????????self size printOn: aStream]
> ????????ifFalse: [self keysInOrder
> ????????????????do: [:key | aStream print: key;
> ???????????????????????? nextPutAll: '->';????????????????
> - ???????????????????????? print: (self at: key);
> - ???????????????????????? space]].
> + ???????????????????????? print: (self at: key)]
> + ????????????????separatedBy: [aStream space]].
> ????aStream nextPut: $)
> 
> ---
> Sent from Squeak Inbox Talk
> ["Bag printString.1.cs"]

> 



More information about the Squeak-dev mailing list