On Tue, 25 Oct 2005, Juerd wrote:
> For comparison, here is the same code snippet again. First with, and
> then without explicit $_.
>
> With:
>
>     given ($subject) -> $_ {
>         $_ ~~ s/foo/bar/;
>         $_++;
>         $_ x= 2;
>         $_ ~= "!";
>     }
>
> Without:
>
>     given ($subject) {
>         s/foo/bar/;
>         ++;
>         x= 2;
>         ~= "!";
>     }
>
> I think the latter is more elegant, without reducing legability or
> maintainability. I also think that the code is immediately obvious, even
> to people coming from Perl 5, who never read this thread.

I don't really agree with your method of addressing the issue. When I have
been annoyed by this issue it is because I can write $x = $x * 2 as

    $x *= 2;

which is elegant, but $x = $x * 2 + 1 requires two statements when using
meta-operator-equals:

    $x *= 2;
    $x += 1;

which is probably less elegant than the original $x = $x ... form.

One could cascade those with extra parens...

    ($x *=2) += 1;
    (($_ += 1) x= 2) ~= "!";

If one were to change the associativity of the meta operators such that
the parens were not needed the result would be very similar to your
example, minus a few semicolons.

    $_ += 1
       x= 2
       ~= "!";

however, I would definitely want someone other than myself to ponder the
implications of mucking with associativity like that.

But IMHO the reduction in typing for this relatively minor issue is not
really worth the surprise to newbies at seeing operandless operators.

~ John Williams


Reply via email to