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

Re: Revisiting trim

Thread Previous | Thread Next
From:
Ben Bullock
Date:
May 27, 2021 21:54
Subject:
Re: Revisiting trim
Message ID:
CAN5Y6m8rL6koNFOGyuLLN_WbG2R6=B8GAj3FxuRAHeDAxgaWxA@mail.gmail.com
On Fri, 28 May 2021 at 01:36, Scott Baker <scott@perturb.org> wrote:

> Personally I'd prefer *trim()* instead of *trimmed()* just for
> consistency with other languages:
>
>    - PHP = trim() <https://www.php.net/manual/en/function.trim.php>
>    - Javascript = trim()
>    <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim>
>
> In Javascript it's actually a method on a string so "   string  ".trim()

https://www.w3schools.com/jsref/jsref_trim_string.asp


>
>    - Raku = trim() <https://docs.raku.org/routine/trim>
>    - Go = trim()
>    <https://www.geeksforgeeks.org/how-to-trim-a-string-in-golang/>
>
> There is strings.Trim but it is not equivalent. The equivalent to your
Perl proposal is strings.TrimSpace:

https://golang.org/pkg/strings/#TrimSpace

>
>    - Vimscript = trim()
>    <https://github.com/vim/vim/commit/295ac5ab5e840af6051bed5ec9d9acc3c73445de>
>    - PowerShell = trim()
>    <https://devblogs.microsoft.com/scripting/trim-your-strings-with-powershell/>
>    - VBA = trim() <https://trumpexcel.com/vba-trim/>
>
> It's actually called Trim (with a capital letter) in VBA. There is also
LTrim and RTrim.


>
>    - C# = trim()
>    <https://www.c-sharpcorner.com/uploadfile/mahesh/trim-string-in-C-Sharp/>
>    - String::Util = trim()
>    <https://metacpan.org/pod/String::Util#trim($string),-ltrim($string),-rtrim($string)>
>    - Text::Trim = trim() <https://metacpan.org/pod/Text::Trim>
>    - Lisp = string_trim() <http://clhs.lisp.se/Body/f_stg_tr.htm>
>
>
Lisp doesn't usually use underscores to separate words and it doesn't use
final brackets for arguments to functions either so this cannot be right.


>
>    -
>    - Python = strip()
>    <https://www.journaldev.com/23625/python-trim-string-rstrip-lstrip-strip>
>    - Ruby = strip()
>    <https://ruby-doc.org/core-2.7.1/String.html#method-i-strip>
>
> This does scotch the argument that "trim" is the most familiar form for
othe programming languages.


>
>
> If we go with *trimmed()* we'll definitely be an outlier.
>
Perl is already an outlier, who else uses "next" and "last" instead of
"break" and "continue", or uses -> for members rather than .?

> Since the PSC has agreed this is a valuable feature, and should be
> included in core (bike shedding is done), the only thing left to debate
> before we have a final implementation is the name.
>
To avoid over-lengthy discussions, in my opinion the person who does the
implementation should basically have the right to choose the name at the
experimental stage. Then, if the name causes a problem in practice, it can
be changed. But a lot of these discussions on this mailing list have
involved imaginary people with imagined problems.

> I'd like to being work in earnest next Monday on this feature. Can we
> debate the best name here for a couple days so I can begin work on the
> final feature? I have a large rebase on the PR to do, and some other
> tweaking.
>
The very best possible name for this function is "trim". Or whatever you
want to call it.

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