On Sun, 17 Apr 2011 08:33:47 -0400, D'Arcy J.M. Cain wrote:

> On Sun, 17 Apr 2011 16:21:53 +1200
> Gregory Ewing <greg.ew...@canterbury.ac.nz> wrote:
>> My idiom for fetching from a cache looks like this:
>> 
>>    def get_from_cache(x):
>>      y = cache.get(x)
>>      if not y:
>>        y = compute_from(x)
>>        cache[x] = y
>>      return y
> 
> I prefer not to create and destroy objects needlessly.
> 
>  def get_from_cache(x):
>    if not x in cache:
>      cache[x] = compute_from(x)
>    return cache[x]

What object(s) do you think are being created and destroyed needlessly?

(This is not a rhetorical question.)


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to