[Python-Dev] Re: heapq method names

François Pinard pinard@iro.umontreal.ca
25 Aug 2002 08:04:20 -0400


[Guido van Rossum]

> > So my suggestion of changing now, before `heapq' gets released for real:
> > 
> >     heappush -> push
> >     heappop -> pop
> >     heapreplace -> replace

> -1.  The nmes 'push', 'pop' and 'replace' are too generic.  The module
> seems to "invite" the ``from heapq import heappush, heappop'' syntax,
> and I'd like to honor that.

May I invite you to reconsider?  We are going to live with that one for
a loong time, you know...

Quite granted, as it stands, the module invites the long form of import
(from MODULE import LIST-OF-NAMES).  This _is_ what I question.

Writing `heapq.heapXXX' is kind of ugly, people are going to spontaneously
avoid it, especially given that the documentation says to do so.  Yet,
the long import line is uselessly tedious to write.  I would not think the
author really wrote `heappush' and `heappop' with the intent that they
could sit in a module and be imported with the long form, but rather as
inlinable `def', or maybe rather as built-in methods for `list' objects.
That intent changing, the method names are then asking to be revised.

There are not much cases in the Python library where the `from ... import'
is forced upon users in practice.  The `BaseHTTPServer' module and friends
are the only examples that come to mind, and I find these import lines
especially cumbersome to write: hopefully, these are not to be used often.

The `heapq' module is different, as for some programmers, it might be used
often, and I do not see a real reason for making it tedious or different.

As for `push' etc. being too generic, there are used in the context of a
specialised module, which gives these word there specialised meaning, so
genericity is not a real argument.  Other modules already qualify simple
words.  Has it been a problem?  Even, would it be that some people really
want to write `from MODULE import *' or `from MODULE import SUCH-AND-SUCH'
for a lot of modules at global scope, something which is not to be encouraged
anyway, these users still have `from ... import ... as' to help them.

Please consider altering the current `heapq' module so to _not_ invite a
different importing style.  Make it more similar to the rest of the library,
there is probably no real need for a difference.  Let it be nicer to use!

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard