[SciPy-User] (pas de sujet)

Hans Georg Schaathun hg+scipy at schaathun.net
Fri Apr 1 17:28:01 EDT 2011


On Fri, Apr 01, 2011 at 11:44:38PM +0300, eat wrote:
> I just like to ask yours and others matured ones opinion about
> systematically using import pattern like:
> from numpy import x, y, z, longname as ln
> from scipy import u, v, x as sx
> from scipy.abc import e, f, g
> With this scheme I think that:
> - programmer takes (still) the whole responsibility of avoiding name
> conflicts

Good.

> - reader (user) avoids the possible confusion between modules and classes

Does he?  How?

> - reader (user) still needs to be aware where the names originated

No.  He will have to look it up in the import line, which may or may
not be easy to find, but only the reader with photographic memory
will be `aware' of it.

> - it's kind of against of the philosophy of import this; explicit is better
> than implicit (but that depends actually on how familiar you are with the
> imported names)

I am not sure I understand you here.

> -  it still feels somehow right to express that these (and only these) are
> my external dependencies

I certainly find that this is useful.  When I need to restructure
modules it does help to see the dependencies to this level of detail.

> -  it seems kind of to unify the way how you import external dependencies

And that's probably its bane as well.  You very quickly end up using
the same name for different objects and different names for the same
object in different files of your project, because you need to improvise
aliases to avoid name clashes as you go along.  (I cannot imagine you
being able to plan a consistent alias scheme for your entire project,
but maybe that's only my imagination.)  It gets nasty very quickly.

The case for spelling out /rarely/ used names in full is very strong.
Your scheme works very well for important objects which you may need
to replace with a different implementation at a later stage.  For
instance, I always use import numpy.random as rnd for the very reason
that I am likely to reconsider its use, and may want to just redefine
rnd as a different PRNG, without any desire to do search and replace
throughout the code.

In short, being systematic about this is probably a bad thing.

:-- George



More information about the SciPy-User mailing list