4 ms·
Is that clean and neat, or weird and inscrutable? Will it be clear to /anyone/ reading that code what it's doing?
by ZenPsycho 14y ago
Is that clean and neat, or weird and inscrutable? Will it be clear to /anyone/ reading that code what it's doing?
- o1iver 14y agoI agree with your sceptisism. This is misusing a language feature, a better approach is using a decorator.
- tzs 14y agoI'm a Python newbie, and that code was immediately clear and obvious to me when I read it. I won't say it would be clear anyone that reads it, because we live in a world where people who claim to be programmers can't do fizz buzz.
- StavrosK 14y agoI'm a Python veteran, and, if you do it like this, I'll shoot you. Add a @memoize decorator and do it there, you need to always be as obvious as possible. Compare: @memoize def fibonacci(n): pass def fibonacci(n, memory=[]): pass You don't even need documentation for the first example.
- paulmcpazzi 14y agoStarting from Python 3.2 there is a builtin decorator: http://docs.python.org/dev/library/functools.html#functools.lru_cache http://docs.python.org/dev/library/functools.html#functools....
- StavrosK 14y agoThat's fantastic, thanks for the link.