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

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

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
March 27, 2021 04:07
Subject:
Re: Let's talk about trim() so more
Message ID:
CAHAeAG51_uiMxkJwWxwN9=Pd=MA5u1iMFqNji_n9h_06LYnMvA@mail.gmail.com
On Sat, Mar 27, 2021 at 4:47 AM Eirik Berg Hanssen <
Eirik-Berg.Hanssen@allverden.no> wrote:

> On Sat, Mar 27, 2021 at 4:35 AM Darren Duncan <darren@darrenduncan.net>
> wrote:
>
>> So which of these is considered better code?
>>
>> Functional design:
>>
>>    my $result1 = op2(op1($input1));
>>
>>    my $result2 = [map { op2(op1($_)) } @{$input2}];
>>
>> Procedural design:
>>
>>    my $result1 = $input1;
>>    op1($result1);
>>    op2($result1);
>>
>>    my $result2 = [];
>>    foreach $elem (@{$input2})
>>    {
>>      op1($elem);
>>      op2($elem);
>>      push(@{$result2}, $elem);
>>    }
>>
>
>   I don't think anyone is arguing for the latter.  Try this instead:
>
> Chomp-like design:
>
> op2(op1(my $result1 = $input1));
>
> op2(op1(my @result2 = @input2));
>

  Err, except if it is truly chomp-like, it won't chain … oops?

op1(my $result1 = $input1);
op2 $result1;

op1(my @result2 = @input2);
op2 @result2;

  Hmm … depending on the input record separator, I could see myself doing
this:

chomp(my @result = <>);
trim @result;

  … and chomp being what it is, I cannot see it being written any easier
with a functional trim …

  But I'm missing the point, aren't I?  It's not how it chains or not with
the existing chomp that's in question, but rather how it chains with user
defined functions or procedures?


Eirik

Eirik

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