list.clear() missing?!?

Raymond Hettinger python at rcn.com
Thu Apr 13 12:34:46 EDT 2006


> > * the request is inane, the underlying problem is trivial, and the
> > relevant idiom is fundamental (api expansions should be saved for rich
> > new functionality and not become cluttered with infrequently used
> > redundant entries)
>
> Is this sort of editorialising fair, or just a way of not-so-subtly
> encouraging Guido to reject the whole idea, now and forever?

Bah.  Guido is not stupid, nor easily misled.  Both the pros and cons
were quipped with abrupt perjoratives so the bullet points could be
stated succinctly and with a bit of levity.  The translation to
verbose, soft, politically correct statements is self-evident.

"request is inane" --> "A generation of python programmers has found
list clearing to be like other parts of the language that you get used
to very quickly and do not prove to be a problem in practice.  The
request is in the same category as others which challenge api choices
made 16 years ago; in particular, the decision to have compact APIs
where the named methods do not duplicate functionality provided by
syntax using operators and keywords. The request is less of a bug
report and more a rejection of Guido's sense of design and his
subsequent experience using his own language."

"underlying problem is trivial" --> "Books such as the Python Pocket
Reference or Python in a Nutshell are able to cover this idiom with
just a single sentence. Once known and understood, the application of
the current-way-to-do-it is immediate, compact, and effective."

"the existing alternatives are a bit perlish" --> "Both alternatives
involve a bit of inventiveness in combining two ideas (either the del
keyword and its interaction with slicing notation or the assignment of
an emtpy list to a slice).  Each approach has a visual appearance of
being a syntax trick.  The effect contrasts with much of the rest of
the language where it is usually possible to write code is a way that
can be read and understood by non-python programmers.  The existing
solution trades readability for the succinctness of a compact
syntactical idiom."



> A list.clear method will make deleting items from a list more OO,
> consistent with almost everything else you do to lists, and less
> procedural. This is especially true if clear() takes an optional index (or
> two), allowing sections of the list to be cleared, not just the entire
> list.

Don't shoot yourself in the foot here.  If you want to advocate
list.clear(), then you're hurting your chances by pushing for it to
take an optional argument.  Essentially, this amounts to an
unwillingness to use the del-keyword and to duplicate its functionality
with a named method.

Also, in the python-dev world, making something "more OO"  is neither a
virtue nor a vice.   It is better to argue for rich functionality,
succeptibility to errors, or dramatic improvements of existing
real-world code.




More information about the Python-list mailing list