[Python-Dev] Deprecate __ private (was Re: PEP 8 updates/clarifications)

Steven Bethard steven.bethard at gmail.com
Tue Dec 13 17:13:40 CET 2005


On 12/13/05, François Pinard <pinard at iro.umontreal.ca> wrote:
> [Steven Bethard]
>
> >Ahh.  I never run into this because I never import objects directly
> >from modules.  So, instead of:
>
> >    from elementtree.ElementTree import ElementTree
> >    ...
> >    ElementTree(...)
>
> >I almost always write something like:
>
> >    import elementtree.ElementTree as et
> >    ...
> >    et.ElementTree(...)
>
> This is a bit off-topic, but I felt like sharing our experience.  One
> consultant we once hired here was doing exactly that (importing over
> two-letter abbreviations).
>
> >Thus, all objects that were imported from external modules are always
> >immediately identifiable as such by their prefixed module name.  I do
> >see though that if you like to import the objects directly from the
> >module this could be confusing.
>
> Everybody here agrees that this style makes the code much less legible.
> Partly because of the constant indirection.  Also because it imposes
> learning all those two-letter abbreviations before reading a module, and
> the learning has to be redone on each visit, it just does not stick.

Much less legible than without the namespace?  Or much less legible
than with a non-abbreviated namespace.  FWIW, here's some real
examples from my code:

import ellogon.utils as utils
import ellogon.features.relations as features_relations
import ellogon.chunking as chunking
import ml.classifiers as _ml_classifiers
import ml.data as _ml_data

The only two-letter one was ElementTree, and the vast majority were
unabbreviated, though  as you can see,  some of them drop one of the
items in the import chain.  Do you find imports like the above
problematic?

FWIW, I don't like importing objects from modules directly for the
same reason that when I write Java now, I always use an explicit
"this" for instance variables.  When I see a name which isn't local to
a function, I want to have some idea where it came from...

STeVe
--
You can wordify anything if you just verb it.
        --- Bucky Katt, Get Fuzzy


More information about the Python-Dev mailing list