3 ms·
Global 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
by artlogic 17y ago
Global 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.