moving LatLongBoundingBox?
Bernhard Herzog
bh at intevation.de
Mon Dec 20 12:48:06 CET 2004
Russell Nelson <nelson at crynwr.com> writes:
> I notice that RasterLayer is using this definition of LatLongBoundingBox:
> def LatLongBoundingBox(self):
> bbox = self.BoundingBox()
> if bbox is None:
> return None
>
> if self.projection is not None:
> bbox = self.projection.InverseBBox(bbox)
>
> return bbox
>
> And Layer is using this definition:
> def LatLongBoundingBox(self):
> bbox = self.BoundingBox()
> if bbox is not None and self.projection is not None:
> bbox = self.projection.InverseBBox(bbox)
> return bbox
>
>
> They both do the same thing, and both classes are derived from
> BaseLayer, so shouldn't it be defined in BaseLayer?
That would probably be better. What do we do about BoundingBox()?
Implement it in BaseLayer too with the default implementation simply
returning None?
> I'd pick the
> first of the two because it's more clear. Also, I would use this
> Python ideom:
>
> if self.projection:
>
> rather than this:
>
> if self.projection is not None:
>
> The first is more clear than the second, which essentially involves
> two negatives. Negatives are harder to process mentally. Yes, I
> realize that these are not equal tests (although they are equivalent).
Not sure what you mean by that exactly, but the tests are not equivalent
in general, although they would both work in this particular case (the
projections will never be considered false in the current
implementation). The first tests whether self.projection is true when
considered as a boolean. The second one tests whether self.projection
is not None, which is different. There values that are false and not
None. That's why Python's PEP 8 recommends this:
- Comparisons to singletons like None should always be done with
'is' or 'is not'. Also, beware of writing "if x" when you
really mean "if x is not None" -- e.g. when testing whether a
variable or argument that defaults to None was set to some other
value. The other value might be a value that's false in a
Boolean context!
I learned that the hard way several years ago.
Bernhard
--
Intevation GmbH http://intevation.de/
Skencil http://skencil.org/
Thuban http://thuban.intevation.org/
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)