> >We already have a trailing if statement, so this argument is edgy, at
> >best.
> 
> Your brain/eye can look one statement.  It's evil and wrong to make
> it look infinite statements forward.  How can you pretend those are
> the same?

Well, I think trailing statements already have only limited usefulness.
Consider these examples:

   die "Bad stuff: $?" if (system "mkdir -p /usr/bin");
   @data = get_some_data(\*FILE, @args) unless (@data);

Blech, personally. I only like trailing statements when I'm decently
sure they're going to be true. So, a trailing {}if can be useful in some
situations:

   $tmpdir = generate_tmpdir;
   {  mkdir $tmpdir;
      chown $uid, $gid, $tmpdir;
      chmod 0700, $tmpdir; } unless -d $tmpdir;
 
This reads better than a leading if. Why? Because we're pretty certain
that the $tmpdir is not going to exist. So putting the statements first
- which will probably get executed - makes sense, and reduces clutter.
It is still easily readable, too, and not far at all from what a
trailing statement is used for currently.

*NOTE*: Just for the record, I would never advocate trailing if's on
long conditions, like the one you demonstrated. It's garbage, I agree.
But that's a style issue.

Anyways, I think this should be RFC'ed. It's not a revolutionary idea
that's going to destroy Perl. If Larry decides he still doesn't like it,
it doesn't make it in. No biggie.

> >Granted, the do {} is misleading. A do {} block is always executed, at
> >least once.
> 
> No, it's not.
> 
>     do { .... } if 0;
> 
> never executes.  Nay, not even once.

I know. I agree. If you read my email, that's why I said:

Nathan Wiger wrote:
> 
>We should drop the do {} if we have a trailing condition:
> 
>    {
>       stuff;
>       otherstuff;
>       morestuff;
>    } if $x > y;

Reply via email to