On Mon, 2005-03-07 at 10:57, David wrote:

> >     - A rather nasty problem I sometimes pose is to print the answer
> > to:
> >             $> perl -e '$x=1; $y=$x+++1; print "x=$x, y=$y\n"'
> ...
> > [Correct answer: x=2, y=2]
> 
> I'd posit that the correct answer is: "rewrite it."
> 
> And adding a space between $x++ and +1 is nowhere near enough.

Why not?

        $y = $x++ + 1;

is quite readable, and very clear in its intent if you know know what
"postfix:++" and "infix:+" do (and you'd better). You don't even have to
know precedence, as it is implied by the (now correct) use of
whitespace.

Granted, if I ever saw:

        $x+++1

in someone's code, I would assume that they were the kind of knucklehead
who sacrifices clarity for (their idea of) coolness. But, that doesn't,
IMHO, taint the combination of ++ and +, just the improper use of
whitespace.

This is also not a Perl-specific issue:

        python
        >>> x = 1
        >>> y = x+++1
        >>> print y
        2

Personally, I think the Python way of doing things demands that that be
invalid, but I'm not enough of a Python head to be sure.


 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to