dict.has_key(x) versus 'x in dict'

Hendrik van Rooyen mail at microcorp.co.za
Sun Dec 10 04:28:16 EST 2006


<skip at pobox.com> wrote:


> >>>>> "Hendrik" == Hendrik van Rooyen <mail at microcorp.co.za> writes:
>
>     Hendrik> <skip at pobox.com> wrote:
>     Hendrik> - as long as it works, and is fast enough, its not broken, so
>     Hendrik> don't fix it...
>
>     >> That's the rub.  It wasn't fast enough.  I only realized that had
>     >> been a problem once I fixed it though.
>
>     Hendrik> LOL - this is kind of weird - it was working, nobody
>     Hendrik> complained, you fiddled with it to make it faster, (just
>     Hendrik> because you could, not because you had to, or were asked to),
>     Hendrik> it became faster, and then, suddenly, retrospectively, it
>     Hendrik> became a problem ????
>
> No, I think you misunderstand.  I was poking around in that function for
> other reasons, saw the "k in d.keys()" and realized that the wrong way to
> write it.  Rewrote it and noticed the performance increase.  What's so weird
> about that?

Nothing wrong with that - it is meet and good to make improvements as you spot
them - what seemed weird to me was not that you made the change, but that you
described it as a problem, retrospectively - why I say this, I expect, is that
in my
mind, such a definition would list as a "problem" all working code that could,
by rummaging around in it, be improved in some way.

I suspect that such a definition would condemn almost *all* production code to
problem status...

I just don't see it that way - my attitude, I suppose,  is a wimpy one, as I
think that working code in production use should be left alone, as every
time you touch it, there is a finite non zero probability that you will do
something stupid to break it, and the breakage may be subtle, and
undiscovered for a while, and then it will really be a problem...

So the weirdness for me was that you called a piece of perfectly good working
code a problem, just because it was faster after you fixed it, even though you
had no prior knowledge of the offending line that was doing the right thing,
albeit slowly. - I would only have called such a piece of code a problem if I
had been inundated with prior requests to fix the slow-running dog...

I dunno if all this makes any sense - and we are getting way off topic.    :-)

- Hendrik





More information about the Python-list mailing list