On 2005-01-30, Anno Siegel <> wrote:
> Not about bad choices. The real problem with brace-less statements under
> "if" is an different one. It happens with nested "if"s and a following
> "else":
>
> if ( $alive ) if ( $well ) get_up() else stay_put();
>
> is essentially ambiguous. You can't indicate if "else" is an alternative
> to the first condition:
In C, the else would get parsed as belonging to the innermost if.
I think that's fairly logical, especially if one indents their code
appropriately, eg:
if ( $alive )
if ( $well )
get_up();
else
stay_put();
Whereas this looks more sketchy, at least to my eye:
/* OMG! it smell like python!

*/
if ( $alive )
if ( $well )
get_up();
else
stay_put();
Though it's understandable that this can generate confusion. And
personally I wouldn't use ambiguous syntax like that. Even in the
first case, my code would be like this:
if ( $alive ) {
if ( $well )
get_up();
else
stay_put();
}
Just because you can do something doesn't mean you have to or should.
I'd really have liked to just be able to write simple code like this w/o
braces:
if ( $alive )
get_up();
else
stay_put();
And although the ?: operator can sometimes fill in the gap, it doesn't
work so well when there is one of more 'elsif' conditions.
But my name's not Larry Wall, and I don't make decisions around here.
So I'll shutup now.