Shawn Walker wrote:
> [email protected] wrote:
>
> > - Is there something special about how we tell if a pfmri exists?
> > There are a bunch of places where 'if pfmri' has been changed to 'if
> > pfmri is not None' and 'if not pfmri.publisher' was changed to 'if
> > pfmri.publisher is None.' This seems counterintuitive, which is why
> > I'm curious about this part of the change.
>
> The best explanation (assuming it is accurate) I've found is here:
>
> http://stackoverflow.com/questions/100732/why-is-if-not-someobj-better-than-if-someobj-none-in-python
>
> In short, "is None" is the most efficient comparison test for an object.
> Using a simple boolean test causes python to perform an extra conversion.
>
> It also prevents silly bugs where a False value other than None has been
> specified. So I test explicitly for None since that is the only "False"
> case I'm expecting.
In general, I'd rather see the bare boolean test, rather than a direct
comparison with None. The only times we should see a comparison against
None (which should always be done with "is", and not with "==") is when
other False-evaluating values need to be handled differently, or when
there's a bug in the underlying __boolean__() method (or lack thereof; cf
dbm).
That's not to say that you can't make a case for any individual test. But
Python is supposed to be polymorphic, and having some arbitrary parts of
the code not follow that model may get confusing.
Besides, what if pfmri.publisher is "", or False, or {}? Maybe
AnarchicalCatalogFMRI is the wrong thing to throw, but going forward
probably isn't the right thing, either. Do you want to assert that it's a
string, too?
If we want to add preconditions and postconditions, we can do that, but
let's do it formally, rather than with ad-hoc tests.
Danek
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss