Steve Howell <[email protected]> writes:
> In languages like Ruby/Perl the inverted if statement is also a useful
> idiom to emphasize concisely that code is exceptional in nature:
>
> def quotient(m, n)
> # guard code
> return None if n == 0
>
> # happy path
> return m / n
> end
Still, in Perl I prefer:
sub quotient {
my ( $m, $n ) = @_;
$n != 0 or return;
return $m / $n;
}
but I guess it depends a lot on what you're used to read.
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
--
http://mail.python.org/mailman/listinfo/python-list