anonymous414703 | | | | | login

Vying Games : Blog

Comments

Alexander Botero-Lowry says,

I do memoization all the time in python, though I admit to doing a bit of a check hack like you mentioned being a bad thing. :/ It's such a little test that I tend to ignore it though, only adds 2 lines to the function in the end.

class Blah(object): #Has to be new-style
  def __init__(self):
    self._expensive = None

  @property
  def expensive(self):
    if not self._expensive:
      self._expensive = do_expensive_operations_here()
    return self._expensive

I admit I find memoization as you describe it pretty attractive so I might just write a decorator to do this a bit more elegantly.

Eric says,

Hi, Alexander, thanks for commenting (I cleaned up your formatting -- sorry about that).

I'm still not happy with my own memoize (or I'd post the actual code). I think it's deceptively hard to get a good general solution.


Commenting on this article has been disabled.

Articles by Tag

Search the Vying Games Blog