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

Naming the trim() variants (was Re: Let's talk about trim() so more)

Thread Previous | Thread Next
From:
Darren Duncan
Date:
March 27, 2021 03:58
Subject:
Naming the trim() variants (was Re: Let's talk about trim() so more)
Message ID:
a1f929c5-099c-8029-0ac8-41a39571ed34@darrenduncan.net
On 2021-03-26 4:00 p.m., Christian Walde wrote:
> Frankly, we just need someone from PSC to tell Scott to go ahead with the 
> latter, and put out a call figuring out the best combination of names. And i 
> find it ... less than optimal to string him along further like this. 

I have a proposal on the naming which fits my general sensibilities.

Use trim() for the version which modifies its argument, and trimmed() for the 
version that doesn't and returns the result.

The idea here is that the modify-argument is named with a verb, "trim" (short 
for "trim this"), because it "takes some action".

And the non-modifying version is named with a noun or an adjective, "trimmed" 
(short for "trimmed version of this"), because it finds a value corresponding to 
the input sans bounding whitespace, and does not "do" anything.

I would not use something like trimr() to mean returns because that could be 
read as "trim the right side only", and triml() would correspondingly mean "trim 
left side only".

I also recognize there is demand for trimming only one side.  A plain trim() 
should do both as that is the least surprising, but variants such as rtrim() and 
rtrimmed() could do just one side.

-- Darren Duncan

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