Re: list.clear() missing?!?



[Steven Bethard]
I think these are all good reasons for adding a clear method, but being
that it has been so hotly contended in the past, I don't think it will
get added without a PEP. Anyone out there willing to take out the best
examples from this thread and turn it into a PEP?

Something this small doesn't need a PEP. I'll just send a note to
Guido asking for a pronouncement.

Here's a draft list of pros and cons (any changes or suggestions are
welcome):

Pros:
-----

* s.clear() is more obvious in intent

* easier to figure-out, look-up, and remember than either s[:]=[] or
del s[:]

* parallels the api for dicts, sets, and deques (increasing the
expecation that lists will too)

* the existing alternatives are a bit perlish

* the OP is shocked, SHOCKED that python got by for 16 years without
list.clear()


Cons:
-----

* makes the api fatter (there are already two ways to do it)

* expanding the api makes it more difficult to write classes that can
be polymorphically substituted for lists

* learning slices is basic to the language (this lesson shouldn't be
skipped)

* while there are valid use cases for re-using lists, the technique is
already overused for unsuccessful attempts to micro-optimize (creating
new lists is surprisingly fast)

* 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)

.



Relevant Pages

  • Re: list.clear() missing?!?
    ... examples from this thread and turn it into a PEP? ... parallels the api for dicts, sets, and deques (increasing the ... be polymorphically substituted for lists ... drop the first two clauses of the point below (but the "relevant idiom" part is clearly a good point). ...
    (comp.lang.python)
  • Re: Dict sharing vs. duplication
    ... array to enforce unique keys and I use lists to enforce order. ... API in a page or two of Tcl code, it isn't so much a missing feature ... OpenACS database API which creates a new specialized data structure, ...
    (comp.lang.tcl)
  • Re: [Python-Dev] PEP 324: popen5 - New POSIX process module
    ... > This PEP describes a new module for starting and communicating ... > with processes on POSIX systems. ... I see many aspects in this PEP that improve the existing implementation ... needs - having different API for them is reasonable. ...
    (comp.lang.python)
  • Re: block ciphers
    ... How about adding block ciphers to Python 2.4? ... PEP 272 has an API for both block and stream ciphers, ...
    (comp.lang.python)
  • SensePost Aura - aka Solving the Google API Key Problem..
    ... (im guessing moderators on moderated lists ... A while back Google encouraged developers to make use of their API. ... SensePost AURA will help to get those ...
    (Pen-Test)