develooper Front page | perl.perl5.porters | Postings from February 2022

Re: trim vs trimmed revisited

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
February 24, 2022 11:37
Subject:
Re: trim vs trimmed revisited
Message ID:
20220224113655.085ad5a5@shy.leonerd.org.uk
On Wed, 23 Feb 2022 20:43:41 -0700
Karl Williamson <public@khwilliamson.com> wrote:

> I believe using 'trimmed' is a mistake, and this email is a last
> ditch effort to make that case.

I think it *may* have been me who first suggested "trimmed", by analogy
to Python's sort() [which mutates inplace] vs. sorted() [which returns
a new value]. This was back when it was still being suggested that our
new "trim" should mutate inplace. I think I recall it as a response to
someone who suggested that trim() in void context ought to mutate, vs
trim() in scalar context should return a value, and I suggested this
would be a terrible abuse of context.

Given I think we are now all agreed that mutate-in-place is a terrible
idea, I don't think this naming distinction needs to remain.

I also find myself quite swayed by Karl's argument that the other past
participle function names all return booleans telling you whether some
notion of their thing had previously happened to their argument
(defined, blessed, tied). If we did add a `trimmed` function, I could
imagine that it tells me whether the value had previously been trimmed -
i.e. whether it lacks blanks at both start and end. Maybe if it were
written in pureperl it could be defined

  sub trimmed($s = $_) { return not($s =~ m/^\s/ or $s =~ m/\s$/) }

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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