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

Re: RFC? pre-RFC? Return of the Jedi^W err/dor

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
August 11, 2021 15:28
Subject:
Re: RFC? pre-RFC? Return of the Jedi^W err/dor
Message ID:
20210811172716.11e02cf2@pc09
On Wed, 11 Aug 2021 10:41:58 -0400, James E Keenan <jkeenan@pobox.com>
wrote:

> Since the last time this came up was several years ago, would it be
> possible to provide a one-paragraph explanation for the rationale for
> the feature?

Consistency.  Essentially, when // was introduced, the low-level
operator was forgotten.

In my life as perl user I have never ever needed or used xor, but I
have used err while it was defined many many times. It is about making
easy (but ugly) things even easier and more consistent.

Low-level precedence operators enable coders to use less line noise.

  foreach my $value (get_values ($foo)) {
      my $v = convert_value ($value) dor next; # "" and 0 are ok
      # ...
      }

  sub foo {
      my $v = shift dor return;
      # ...
      }

There are two camps in using and/if or/unless

 warn "Blah" if $error;
vs
 $error and warn "Blah";

I am *firmly* in the second, as that fits how I think.

I also am a strong proponent of using early return instead of the (in
my perception very stupid) only-one-return.

 sub foo {
     if (defined $foo) {
         # 50 lines of code
         }
     else {
         die "foo was not defined";
         }
     }

vs

 sub foo {
     defined $foo or return;

     # 50 lines of code
     }

with dor next to and and or, the code stay clean, readable,
maintainable and more consistent. In the if/else example I would
not care, as the code already looks like a mess (to me).

-- 
H.Merijn Brand  https://tux.nl   Perl Monger   http://amsterdam.pm.org/
using perl5.00307 .. 5.33        porting perl5 on HP-UX, AIX, and Linux
https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.org
                           

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