Created
March 7, 2011 17:31
-
-
Save AdamG/858839 to your computer and use it in GitHub Desktop.
useless brainstorming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Just some brainstorming. I don't really have a good repo for this. | |
So I've been thinking about state. The total state of an application | |
consists of the code, the data, and that's about it. There's external | |
state too. But everything, I dunno... should be *managed*, I guess. At | |
one level, that's the job of an OS. On the other hand, we're talking | |
potentially many machines. | |
This sounds like something plan9 would have already solved. That's OK. | |
>>> s = State() | |
>>> s.add_change(s.current_state.__setitem__, "test", "bar") | |
>>> s.current_state['test'] | |
'bar' | |
>>> s.add_change(s.current_state.__delitem__, "test") | |
>>> repr(s.current_state.get("test")) | |
'None' | |
>>> len(s.changes) | |
2 | |
Well this seems pretty useless now. | |
""" | |
def _main(): | |
import doctest | |
doctest.testmod() | |
class State(object): | |
def __init__(self): | |
self.current_state = {} | |
self.changes = [] | |
def add_change(self, f, *args): | |
self.changes.append((f, args)) | |
f(*args) | |
if __name__ == "__main__": _main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment