develooper Front page | perl.perl5.porters | Postings from March 2021

Re: Let's talk about trim() so more

Thread Previous | Thread Next
From:
Darren Duncan
Date:
March 26, 2021 22:40
Subject:
Re: Let's talk about trim() so more
Message ID:
017e1f1b-76ef-cc40-e9cf-f8ff55089137@darrenduncan.net
I know I wasn't following this issue in detail but I was always assuming that a 
trim() would NOT modify its argument and would return the trimmed value.  This 
is what everyone would reasonably expect.  This is the only version that is 
actually useful.  Adding a trim() that alters its argument would be worse than 
not having the function at all.  Stuff like chomp() is a bad example to follow. 
-- Darren Duncan

On 2021-03-26 2:28 p.m., Scott Baker wrote:
> Per the email from PSC I'm starting a conversation about the trim() 
> implementation I'd like to land in core.
> 
> To get yourself up to speed: Issue <https://github.com/Perl/perl5/issues/17952> 
> and Pull Request <https://github.com/Perl/perl5/pull/17999>
> 
> --------------------------------------------------------------------------------
> 
> As a starting point I'm going to repost my last comment as I think it's sums up 
> my position as main author and proponent of this feature:
> 
>> Per my original comment in #17952 <https://github.com/Perl/perl5/issues/17952> 
>> there are many other languages that implement |trim()| and *all* of them 
>> implement it as a return value. Also, the vast majority of CPAN modules, and 
>> darkcpan implementations do so as a return value. People /expect/ |trim()| to 
>> return a value just from broader experience in other languages, and modules.
>>
>> I can count on two fingers the number of times I've used |chomp()|, so copying 
>> it's model is not my first choice. Every time I've needed |chomp()| I've opted 
>> instead for my homegrown |trim()| instead.
>>
>> Personally I don't see a use case for in-place, but if we're requiring an 
>> implementation that operates in-place it should *not* be called |trim()|. I 
>> would instead propose something like:
>>
>>  1. |trim()| returns the value
>>  2. |trimi()| (i for in-place), |trimmer()|, or as Mithaldu joked |tromp()|
>>     would operate in-place.
>>
>> This will keep us consistent with other languages, while also offering a 
>> chomp-like implementation. Awaiting further guidance from PSC as to next steps.
>>
> 


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About