Why is split: implemented in the separator rather than the string?

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

Why is split: implemented in the separator rather than the string?

Andy Burnett
I keep getting this wrong, which makes me wonder why we send split: to the separator rather than the thing to be split. Is there a benefit to doing

$- split: '1969-07-20'

rather than

'1969-07-20' split: $-  (which somehow seems more natural to me).

Cheers
Andy
Reply | Threaded
Open this post in threaded view
|

Re: Why is split: implemented in the separator rather than the string?

Peter Uhnak


On Thu, May 19, 2016 at 8:48 PM, Andy Burnett <[hidden email]> wrote:
I keep getting this wrong, which makes me wonder why we send split: to the separator rather than the thing to be split. Is there a benefit to doing

$- split: '1969-07-20'

Because you are telling the receiver that he should split the argument.

"Hey dash, can you split this for me?"

 

rather than

'1969-07-20' split: $-  (which somehow seems more natural to me).

Try instead '1969-07-20' splitOn: $-

"Hey collection, can you split on this?"

Peter
Reply | Threaded
Open this post in threaded view
|

Re: Why is split: implemented in the separator rather than the string?

John Pfersich
In reply to this post by Andy Burnett
If you want to do it reversed, do it like this:

'1969-07-20' splitOn: '-'


> On May 19, 2016, at 11:48, Andy Burnett <[hidden email]> wrote:
>
> I keep getting this wrong, which makes me wonder why we send split: to the separator rather than the thing to be split. Is there a benefit to doing
>
> $- split: '1969-07-20'
>
> rather than
>
> '1969-07-20' split: $-  (which somehow seems more natural to me).
>
> Cheers
> Andy