[Python-ideas] set.add() return value
Guido van Rossum
guido at python.org
Wed Feb 18 16:28:35 CET 2009
On Wed, Feb 18, 2009 at 4:58 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Raymond Hettinger <python at ...> writes:
>> Even if it did improve you one app, that would be
>> atypical. Most apps that test and add will do
>> something inside the branch that consumes far more
>> time than the contains test.
> Sorry, that argument could be turned into an argument against *any* optimization.
Well, the long form would be something like the benefits for a small
class of apps vs. the effort in implementing it plus the cost for
other apps. While the implementation cost of this feature is small
(which makes it attractive to some), I think that the cost of
developers guessing the returned value wrong is prohibitive.
> For example, "there's no need to optimize building dict literals, since most
> apps will do something with the dict that consumes far more time than building
> the dict".
> The assumption being that only optimizations which benefit a large class of
> applications should be attempted, which is bogus (are large classes of
> applications bottlenecked by dict literal creation? yet we have specialized
> opcodes for dict literal creation, and so on for lots of other things).
Here you make a logic error. The presence of an opcode for anything in
Python does not mean that it is considered to be worth optimizing --
it just means it is a primitive operation in the language, with syntax
associated with it.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-ideas