Paul Seamons schreef:

> In the samples you gave I had to read the entire line to see
> what the outcome of the code is.

I was not addressing reading skills, but just your "you'd either have
... or ...". One always needs to read the full line, but one doesn't
have to do that linearly or just from left to right.

Read Perl's "or" as "skip if the previous was true", and speed-reading
such
constructs is in your bag.


There are plenty of cases where you too want the conditions up front.

A. $strong_objection1 or $strong_objection2 or
     $half_a_reason1 and $half_a_reason2 and $weight *= 1.00001 ;

B.  $no_way > 0.8 or $you_must_be_crazy > 0.9 or
     $let_s_try > 0.6 and $you_never_know > 0.5 and $weight *= 1.00001 ;

C. $weight *= 1.00001 if $let_s_try > 0.6 and $you_never_know > 0.5
                      unless $no_way > 0.8 or $you_must_be_crazy > 0.9 ;

D.  unless $no_way > 0.8 or $you_must_be_crazy > 0.9
   {
       if $let_s_try > 0.6 and $you_never_know > 0.5
       {
           $weight *= 1.00001
       }
   }

E.  unless $no_way > 0.8 or $you_must_be_crazy > 0.9
   {
       $weight *= 1.00001  if $let_s_try > 0.6 and $you_never_know > 0.5
   }


Assuming all variants are alternatives, I prefer E.

A-E aren't alternatives if the value of the (last) evaluated expression
counts:

F. $strong_objection1 or $strong_objection2 !!
   $half_a_reason1 and $half_a_reason2      ?? ($weight *= 1.00001)
                                            :: weight
                                            :: weight ;

G. $strong_objection1 or $strong_objection2 ?? weight
                                            ::
   $half_a_reason1 and $half_a_reason2      !! weight
                                            :: ($weight *= 1.00001) ;

H. $strong_objection1 or $strong_objection2 ?? weight
                                            ::
   $half_a_reason1 and $half_a_reason2      ?? ($weight *= 1.00001)
                                            :: weight ;


> Allowing for multiple nested modifiers allows the action to retain its
> significance.  After I sent the last email I came across a statement
> in the code I was working on that would have phrased better if I
> could use both an if and an unless.  These things do come up - we
> Perl 5 coders have just trained ourselves to do things another ways.

Or use a block. I am all for multiple nested modifiers, but not because
I need the action up front, I just happen to like the lean look.

  $weight *= 1.00001 if $half_a_reason1 and $half_a_reason2
                     unless $strong_objection1 or $ $strong_objection2 ;


  unless $strong_objection1 or $ $strong_objection2
  {
      $weight *= 1.00001
        if $half_a_reason1 and $half_a_reason2 ;
  } ;


> The biggest setback I see to nested modifiers is that the order of
> lexical scopes visually read on the screen are reversed in execution.
> But that is already a problem with a single level statement modifier.
> I don't think multiple levels introduces any more problem than is
> already there.

It's just the same thing. Some people don't have problems using them,
many do.


> Plus - if there are multiple modifiers then Perl poetry can get even
> better. And everybody wins if Perl poetry is better. :)
>
> say "I'm ok"
> if $i_am_ok
> if $you_are_ok
> while $the_world_is_ok;

You can't even get near natural language. For example: in natural
language a double negation is often used to emphasize the negation.

-- 
Affijn, Ruud

"Gewoon is een tijger."



Reply via email to