4 ms·
Global data is bad; only the memoization code needs to access the cache; why expose the cache more broadly than that? More explicitly, one problem with overexpo
by arebop 17y ago
Global data is bad; only the memoization code needs to access the cache; why expose the cache more broadly than that? More explicitly, one problem with overexposure is namespace collisions.
- artlogic 17y agoGlobal data can be bad, but a function instance variable isn't global - it's simply public. Using closures to simulate private variables has always seemed like overkill to me, but I tend to prefer Python's approach to private variables. Also, being able to manipulate the cache from outside the function could be helpful in certain cases where a full fledged cache object would be overkill. I do agree that namespace collision is certainly an issue, but it's traditionally resolved by mild name mangling (again, see Python). In my opinion, the advantages of a less clever (read easily understood) public implementation outweigh the disadvantages.