in reply to Re: Avoiding the == blues
in thread Avoiding the == blues
rather than:foo.equals(0)
Despite the fact that Ruby considers 0 to be a Real Object, I suspect that even Ruby programmers will prefer the first form to the second, because that's how our brains are wired.0.equals(foo)
The solution to all this in Perl 6 will be that assignment to an existing variable in boolean context will produce a warning under strictures, but assignment to a my declaration will not. The typical use for assignment in a boolean context is actually not the if statement but the while statement:
and in most cases this is probably better written as:while $item = shift(@foo) {...}
or even better:while my $item = shift(@foo) {...}
Likewise,for @foo -> $item {...}
can turn intoif $x = long_expression() {...}
I suppose we might also allow the gcc-like workaround of putting extra parens when you want to hide the assignment from the boolean context.given long_expression -> $x {...}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Avoiding the == blues
by Anonymous Monk on Jan 01, 2005 at 19:16 UTC | |
by Baz (Friar) on Jan 01, 2005 at 20:25 UTC |