The Inbox: Collections-ct.827.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-ct.827.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.827.mcz

==================== Summary ====================

Name: Collections-ct.827
Author: ct
Time: 31 May 2019, 1:49:32.006053 pm
UUID: fe89c3e0-5003-aa40-8f1f-cd356ae17716
Ancestors: Collections-cmm.826

Add convenience method for joining strings (Collection>>asStringByDelimiter:)

=============== Diff against Collections-cmm.826 ===============

Item was added:
+ ----- Method: Collection>>asStringByDelimiter: (in category 'printing') -----
+ asStringByDelimiter: aDelimiter
+
+ ^String streamContents: [:s | self asStringOn: s delimiter: aDelimiter]!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

marcel.taeumel
Is #joinSeparatedBy: what you are looking for?

#(1 2 3) joinSeparatedBy: '-'

Best,
Marcel

Am 31.05.2019 13:49:41 schrieb [hidden email] <[hidden email]>:

A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.827.mcz

==================== Summary ====================

Name: Collections-ct.827
Author: ct
Time: 31 May 2019, 1:49:32.006053 pm
UUID: fe89c3e0-5003-aa40-8f1f-cd356ae17716
Ancestors: Collections-cmm.826

Add convenience method for joining strings (Collection>>asStringByDelimiter:)

=============== Diff against Collections-cmm.826 ===============

Item was added:
+ ----- Method: Collection>>asStringByDelimiter: (in category 'printing') -----
+ asStringByDelimiter: aDelimiter
+
+ ^String streamContents: [:s | self asStringOn: s delimiter: aDelimiter]!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Christoph Thiede
Hello Marcel,

#joinSeparatedBy: looks well, unfortunately it is only available for
SequencableCollections. I would like some convenience method for other
species of Collections as well:

#(1 2 3) asSet joinSeparatedBy: '-'

Could we rename my proposed method into #asStringByDelimiter: and add it to
Collection?

Best,
Christoph



--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html

Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Chris Muller-3
Hi Christoph,

It would be preferable to move #joinSeparatedBy: to Collection than
increase the existing API with a new, differently-named method that
does the same thing.

Just in case you weren't aware -- if its the same implementation and
you wish to preserve original author and timestamp information
(recommended), you can use drag-and-drop to move the method!   Open
two windows side-by-side, one on Collection, the other on
SequenceableCollection.   Select joinSeparatedBy: and drag it to that
category in Collection.  Done.  No new tests needed either, since they
already exist.


 - Chris

On Fri, May 31, 2019 at 7:34 AM Christoph Thiede
<[hidden email]> wrote:

>
> Hello Marcel,
>
> #joinSeparatedBy: looks well, unfortunately it is only available for
> SequencableCollections. I would like some convenience method for other
> species of Collections as well:
>
> #(1 2 3) asSet joinSeparatedBy: '-'
>
> Could we rename my proposed method into #asStringByDelimiter: and add it to
> Collection?
>
> Best,
> Christoph
>
>
>
> --
> Sent from: http://forum.world.st/Squeak-Dev-f45488.html
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

David T. Lewis
Hi Chris,

On Fri, May 31, 2019 at 04:53:41PM -0500, Chris Muller wrote:

> Hi Christoph,
>
> It would be preferable to move #joinSeparatedBy: to Collection than
> increase the existing API with a new, differently-named method that
> does the same thing.
>
> Just in case you weren't aware -- if its the same implementation and
> you wish to preserve original author and timestamp information
> (recommended), you can use drag-and-drop to move the method!   Open
> two windows side-by-side, one on Collection, the other on
> SequenceableCollection.   Select joinSeparatedBy: and drag it to that
> category in Collection.  Done.  No new tests needed either, since they
> already exist.

Thanks for that tip. Sometimes I'm amazed by my own ignorance. For years,
I have been in the habit of preserving timestamp information by filing
something out, editing the fileout file with a unix vi editor to hack
it to the new destination class/category, and then filing it back in.

Boy am I dumb :-)

Thanks,
Dave


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Christoph Thiede
In reply to this post by Chris Muller-3
Hi Chris,

thanks for the tip! I applied your recommendations in Collections-ct.828 and
CollectionsTests-ct.312. Is this what you meant?

Best,
Christoph



--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html

Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

K K Subbu
In reply to this post by Christoph Thiede
On 31/05/19 6:04 PM, Christoph Thiede wrote:
> #(1 2 3) asSet joinSeparatedBy: '-
What is the expected answer for joining set members by '-'?

If I have a set with members #daa, #dee, #dum, the output could be any
of 'daa-dee-dum', 'daa-dum-dee', 'dum-dee-daa', ....

Squeak 5.2alpha shows the order as 'dee-daa-dum'

Regards .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Tobias Pape

> On 01.06.2019, at 16:51, K K Subbu <[hidden email]> wrote:
>
> On 31/05/19 6:04 PM, Christoph Thiede wrote:
>> #(1 2 3) asSet joinSeparatedBy: '-
> What is the expected answer for joining set members by '-'?
>
> If I have a set with members #daa, #dee, #dum, the output could be any of 'daa-dee-dum', 'daa-dum-dee', 'dum-dee-daa', ....
>
> Squeak 5.2alpha shows the order as 'dee-daa-dum'

I think that's why #joinSeparatedBy: was initially only on sequenceable collection.
I mean, it is also unclear what joinSeparatedBy: would mean on a Bag with multiple occurrences, or a Matrix, or a Bitset…

On the other hand, you can always do things like
        myCollection asArray joinSeparatedBy: 'fnord'
or
        myBag cumulativeCounts joinSeparatedBy: ', '
or
        (mySet sorted: [:a :b | a >= b])  joinSeparatedBy: ' is more than '

and be explicit on what you expect to establish the sequence.



Best regards
        -Tobias


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Chris Muller-3
> > On 31/05/19 6:04 PM, Christoph Thiede wrote:
> >> #(1 2 3) asSet joinSeparatedBy: '-
> > What is the expected answer for joining set members by '-'?
> >
> > If I have a set with members #daa, #dee, #dum, the output could be any of 'daa-dee-dum', 'daa-dum-dee', 'dum-dee-daa', ....
> >
> > Squeak 5.2alpha shows the order as 'dee-daa-dum'
>
> I think that's why #joinSeparatedBy: was initially only on sequenceable collection.

It can be good to start out behaviors in the most-restrictive place
possible, because it's easier to relax something later if necessary,
than to tighten it.

> I mean, it is also unclear what joinSeparatedBy: would mean on a Bag with multiple occurrences, or a Matrix, or a Bitset…

The method only uses #do:, which is required of all Collections, so
it's not any less clear than #do: on those objects.

> On the other hand, you can always do things like
>         myCollection asArray joinSeparatedBy: 'fnord'
> or
>         myBag cumulativeCounts joinSeparatedBy: ', '
> or
>         (mySet sorted: [:a :b | a >= b])  joinSeparatedBy: ' is more than '
>
> and be explicit on what you expect to establish the sequence.

It sounds like Christoph has a use case to join objects without caring
about the order.  I don't find that surprising, the method is a very
abstract behavior, with many different uses across different domains.
The existing implementation works in the context of any Collection,
and those things you mentioned above can all still be done.

Regards,
  Chris

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

K K Subbu
On 02/06/19 12:25 AM, Chris Muller wrote:
> The method only uses #do:, which is required of all Collections, so
> it's not any less clear than #do: on those objects.

Chris,

#do: does yield a sequence but the order is not guaranteed to be same
from one send to another.

The provided test case for #joinSeparatedBy: assumed a particular
sequence. When Christoph proposed to relax it for all Collections, the
existing test cases will also have to change to avoid false fails.

Regards .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Nicolas Cellier
I agree with Tobias and Subbu, random order makes the feature questionable. Please try to write a TestCase to illustrate the expectations in case of non sequenceable collections.

Le dim. 2 juin 2019 à 07:58, K K Subbu <[hidden email]> a écrit :
On 02/06/19 12:25 AM, Chris Muller wrote:
> The method only uses #do:, which is required of all Collections, so
> it's not any less clear than #do: on those objects.

Chris,

#do: does yield a sequence but the order is not guaranteed to be same
from one send to another.

The provided test case for #joinSeparatedBy: assumed a particular
sequence. When Christoph proposed to relax it for all Collections, the
existing test cases will also have to change to avoid false fails.

Regards .. Subbu



Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

marcel.taeumel
Hi, there.

I think that, in this case, " someCollection asArray joinSeparatedBy: '-' " would produce more readable code. Even better, sort the collection explicitely: " someCollection sorted: [:a :b | ...]) joinSeparatedBy: '-' ".

-1 (for moving #joinSeparatedBy: into Collection)

Also, I think we should deprecate #asStringByDelimiter: and friends. Looking at the sends, there is not much to do in Trunk.

Best,
Marcel

Am 03.06.2019 07:32:15 schrieb Nicolas Cellier <[hidden email]>:

I agree with Tobias and Subbu, random order makes the feature questionable. Please try to write a TestCase to illustrate the expectations in case of non sequenceable collections.

Le dim. 2 juin 2019 à 07:58, K K Subbu <[hidden email]> a écrit :
On 02/06/19 12:25 AM, Chris Muller wrote:
> The method only uses #do:, which is required of all Collections, so
> it's not any less clear than #do: on those objects.

Chris,

#do: does yield a sequence but the order is not guaranteed to be same
from one send to another.

The provided test case for #joinSeparatedBy: assumed a particular
sequence. When Christoph proposed to relax it for all Collections, the
existing test cases will also have to change to avoid false fails.

Regards .. Subbu



Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Stéphane Rollandin
In reply to this post by Nicolas Cellier
> I agree with Tobias and Subbu, random order makes the feature
> questionable.

+1

Stef

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Christoph Thiede
In reply to this post by marcel.taeumel
My use case was about concatenating strings in order to build a filter string
(where order does not matter), but I agree this can be achieved using
asArray as well.

My desire was to make #asCommaString and #joinByDelimiter: consistent, so
why not move asCommaStringWithAnd etc. down to OrderedCollection and rename
it to joinWithComma etc.?

Best,
Christoph



--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html

Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

marcel.taeumel
+1

Am 04.06.2019 10:03:00 schrieb Christoph Thiede <[hidden email]>:

My use case was about concatenating strings in order to build a filter string
(where order does not matter), but I agree this can be achieved using
asArray as well.

My desire was to make #asCommaString and #joinByDelimiter: consistent, so
why not move asCommaStringWithAnd etc. down to OrderedCollection and rename
it to joinWithComma etc.?

Best,
Christoph



--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html



Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Chris Muller-3
In reply to this post by Christoph Thiede
> My use case was about concatenating strings in order to build a filter string
> (where order does not matter), but I agree this can be achieved using
> asArray as well.

Sending #asArray would introduce the unnecessary creation of an
interim collection for every single query, even while making the code
unnecessarily wordy and harder to read.

> My desire was to make #asCommaString and #joinByDelimiter: consistent, so
> why not move asCommaStringWithAnd etc. down to OrderedCollection and rename
> it to joinWithComma etc.?

Goran had a mini-family of methods that does this same thing in
Collection since 2005.  Adding all of the above up, it seems very
clear that the 2015 addition of #joinSeparatedBy: must not have
noticed all of the above, so was inserted into a different place while
duplicating the existing implementation.

Your use case disproved the theory that "it doesn't make sense".  It
makes perfect sense.  We should just move it to Collection, and remove
asCommaString and change senders to use this method.

 - Chris

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

David T. Lewis
In reply to this post by Stéphane Rollandin
On Mon, Jun 03, 2019 at 10:52:47AM +0200, St??phane Rollandin wrote:
> >I agree with Tobias and Subbu, random order makes the feature
> >questionable.
>
> +1
>
> Stef
>

+1

I agree with Tobias and Subbu and Stef. Random order makes the feature
questionable.

I also find the "aSet asArray" idiom to be quite comfortable. In a unix
shell I often find myself doing "cat aFile | sort | uniq" and I rather
prefer the Smalltalk idiom of "aCollection asSet asArray".

Dave
 

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

marcel.taeumel
In reply to this post by Chris Muller-3
Hi Chris,

> Sending #asArray would introduce the unnecessary creation of an
> interim collection for every single query, even while making the code
> unnecessarily wordy and harder to read.

You assume that it would be a common case to join non-seq collections. I
argue that this is not the case. In those situations where you do have a
non-seq collection, it would help readability to make the order explicit.
Your concern about performance issues remains to be evaluated; it cannot be
part of this decision here.

Code readability first.
Performance improvements later, after benchmarked.

Just my two cents. ;-)

Best,
Marcel



--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.827.mcz

Stéphane Rollandin
>> Sending #asArray would introduce the unnecessary creation of an
>> interim collection for every single query, even while making the code
>> unnecessarily wordy and harder to read.
>
> You assume that it would be a common case to join non-seq collections. I
> argue that this is not the case. In those situations where you do have a
> non-seq collection, it would help readability to make the order explicit.

+1

Stef