Raymond Hettinger wrote: > [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.
Thanks. It'd be nice to have something to refer to the next time this comes up. > 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 > I'd snip the one below. It doesn't really contribute anything, and was sarcastic in the first place. ;) > * 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) > In fairness, if we're going to drop the "SHOCKED" comment, we should drop the first two clauses of the point below (but the "relevant idiom" part is clearly a good point). > * 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) Other than those minor edits, I think you've pretty much gotten everything. I look forward to a pronouncement. Thanks again! STeVe -- http://mail.python.org/mailman/listinfo/python-list