What is a function parameter =[] for?

Gregory Ewing greg.ewing at canterbury.ac.nz
Sun Nov 22 18:43:52 EST 2015


Steven D'Aprano wrote:
> Memoisation isn't "esoteric", it is a simple, basic and widely-used
> technique used to improve performance of otherwise expensive functions.

That may be true, but I don't think it's a good example
of a use for a shared, mutable default value, because
it's arguably an *abuse* of the default value mechanism.

Whenever I want to cache function values, I use a module
level variable to hold the cache. It's clearer, and it
doesn't clutter the function signature with something
that isn't logically a part of it at all.

-- 
Greg



More information about the Python-list mailing list