(a==b) ? 'Yes' : 'No'
John Bokma
john at castleamber.com
Sat Apr 3 13:44:42 EDT 2010
Steve Howell <showell30 at yahoo.com> 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
More information about the Python-list
mailing list