(a==b) ? 'Yes' : 'No'

John Bokma john at castleamber.com
Fri Apr 2 22:20:06 CEST 2010


kj <no.email at please.post> writes:

> Anyway, I don't know of any other language that puts the test
> between the alternatives.  No doubt there's one out there, with
> emphasis on "out there"...

Perl has something that has IMO somewhat the same problem:

print "Hello, world!\n" if $some_condition;

I prefer most of the time:

$some_condition and print "Hello, world!\n";

Or even:

$some_condition
    and print "Hello, world!\n";

Moreover, instead of:

$x = 'some value' unless defined $x;

I prefer

defined $x
    or $x = 'some value';

I read the latter as: $x must be defined, otherwise some value must be
assigned to it, like a precondition.

YMMV,

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development



More information about the Python-list mailing list