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
Darren Duncan
March 27, 2021 03:58
Naming the trim() variants (was Re: Let's talk about trim() so more)
Message ID:
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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About