develooper Front page | perl.perl6.language | Postings from September 2005

Re: conditional wrapper blocks

Thread Previous | Thread Next
From:
Stuart Cook
Date:
September 22, 2005 04:04
Subject:
Re: conditional wrapper blocks
Message ID:
49b3510605092204041baebdf8@mail.gmail.com
On 22/09/05, Shane Calimlim <imustdie@gmail.com> wrote:
> How about something like:
>
> if ($condition) {
> pre;
> always { # maybe "uncond" instead of always, or both -- "always" could
> # mean 'ignore all conditions' and "uncond" could mean
> # 'ignore the current block's condition
> mid_section;
> }
> post;
> }

That's quite elegant, but overloading `if` like that is completely
insane and unpredictable, because you can no longer assume that all
the code inside is tied to the conditional.

A more maintenance-programmer-friendly version might look more like this:

  # doesn't really matter what it's called, so long as it's not `if`
  sometimes $condition {
    pre;
    ALWAYS { body; }  # caps help too
    post;
  }

Which is exactly the same, except that by using a different keyword,
we're telling the reader that the rules of `if` don't apply
here--there's going to be some unconditional code in the conditional
block.  This way, `if` always means 'if', rather than 'if, except on a
Tuesday'.

Mind you, this sort of solution is probably implementable purely as a
module, so if people don't think it's useful enough to go in core then
those who do need it won't really miss out.


Stuart

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