Namespace pollution

Carel Fellinger cfelling at iae.nl
Mon Jan 31 14:50:00 EST 2000


Dirk-Ulrich Heise <hei at adtranzsig.de> wrote:
...
> I've got one problem with all this stuff:
> I end up with dozens of helper functions that are
> called exactly one time. They pollute the namespaces
> of the module or class they're defined in. I hate polluted
> namespaces.

> How do others cope with this problem (that does not only
> apply to Python)?

You could switch to Literate Programming and use real functions when
appropriate but otherwise rely on the inline nature of chunks like this:

===================

Some chunks of code that would have been silly functions had I not
switched to LP but are now 'inlined'.
<<do something, only needed once>>=
  pass

Enhance your coding style and explain what's going on here on a meta level
<<do something else, only needed once>>=
  pass

Let's now apply those chunks once
<<global functions>>=
  def real_work:
    <<do something, only needed once>>
    <<do something else, only needed once>>

And just to be complete call upon [[real_work]] somewhere
<<main>>=
  <<global functions>>

  real_work()

=======================

Sorry, couldn't resist to plug my oldtime love, though I've never
used it on Python (yet). Somehow it feels like overkill for such
a readable language;} But it sure is a hassel, going back to edit -
compile - run cycli.
-- 
groetjes, carel



More information about the Python-list mailing list