[squeak-dev] Review Request: Bag printString

Marcel Taeumel marcel.taeumel at hpi.de
Mon Feb 28 08:17:04 UTC 2022


Hi Christoph --

I have to agree with Dave. Can we find a threshold when it makes sense to show the counts of each element? Maybe drop the "1" entirely and only show "->n" for n > 1? Maybe don't use "->" but parentheses? And maybe check with objects that have a more complex printString on their own. Hmm...

aBag(10 at 10 (2) 20 at 20 (3) ...)

(Also make sure that the printString is kind of as fast as before. Thanks.)

Best,
Marcel
Am 26.02.2022 23:08:06 schrieb David T. Lewis <lewis at mail.msen.com>:
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"]

>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220228/5e79ee82/attachment.html>


More information about the Squeak-dev mailing list