Function decorator that caches function results

Fredrik Lundh fredrik at pythonware.com
Sat Oct 8 11:29:58 EDT 2005


Lasse Vågsæther Karlsen wrote:

> Yeah, but as far as I can see it, this one too fails to recognize
> situations where the function is called twice with essentially the same
> values, except that in one call it uses named arguments:
>
> k1 = fibonacci(100)
> k2 = fibonacci(idx = 100)
>
> this is essentially the same call, except the second one uses a named
> argument, which means the function will be invoked and a second cache
> entry will be stored.

whoever writes code like that deserves to be punished.

I'd say this thread points to a misunderstanding of what keyword arguments
are, and how they should be used.  the basic rule is that you shouldn't mix and
match; use positional arguments for things that are documented to be positional
parameters, and keyword arguments for keyword parameters.  if you don't,
you'll end up with code that depends on implementation details.  and that's
never a good idea...

</F> 






More information about the Python-list mailing list