PEP 308: Pep Update
James J. Besemer
jb at cascade-sys.com
Fri Feb 14 15:30:34 EST 2003
Andrew Dalke wrote:
> James J. Besemer:
>
>>Furthermore, (although I know you'll disagree) I'll point out that your
>>general complaint here also constitutes an argument for going with the
>>operator based alternative,
>>
>>a ? b : c
>>
>>as it couldn't possibly be confused with if/else statements.
Further evidence that I simply thought you did not like the other alternative.
> True, but it doesn't stand out as much.
That IMHO can be greatly improved by a different style (which I mentioned
earlier):
a = (
# The value can be cached or in the database
( is_cached
? self._get_cache[ name ]
: self.connection.fetch( name )), # database already open
# The ownership is stored in the database (if the
# name starts with "DB") or from the web service
( x.startswith( "DB" )
? self.connection.get_owner( name )
: self.webservice.get_owner_by_name( name )))
> The use of ?: seems more appropriate for smaller terms,
> and if/else for larger ones.
If adopting both forms was a possibility, we'd have that luxury.
Personally, I rather think that ?: fits most naturally with expressions and
keywords fits most naturally with statements. Certainly, this reflects my
decades of C background. But more than that, I think there's a natural
association in that expression operators tend to be punctuation based, while
statements virtually always are associated with keywords (all but assignment).
>I just wish you'd be willing to be more flexible about other people's
> opinion about style.
>
>
> I have at several times agreed that a given expression, when written
> with a ternary if/else expression, is more readable. My opinion though
> is that the overall readability/etc. suffers. I don't know why I need to
> be any more flexible than I have been,
There's no need. I was making a "wish". Unexpectedly, it seems to have come
true.
> nor why I couldn't respond that you too need to be more flexible.
I suppose that's fair.
> In any case, I think this will be my last post on this thread, since I am
> sure I'm tapped out on it, if not idea-wise then at least emotionally
> drained.
I do agree we covered all the bases.
And I had better get my butt out shopping for some Valentine gifts or else
I'll be "emotionally drained" by my wife.
Regards
--jb
--
James J. Besemer 503-280-0838 voice
2727 NE Skidmore St. 503-280-0375 fax
Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com
http://cascade-sys.com
More information about the Python-list
mailing list