> > Just as a warning, none of what I'm going to code here is original at > > all: I'm rehashing a main idea off of a paper called "Using the Game > > of Life to Introduce Freshman Students to the Power and Elegance of > > Design Patterns": > > > > http://portal.acm.org/citation.cfm?id=1035292.1028706 > > Uh, with all respect Danny, this is a nice example of the Command > pattern, but to me this example would better be called "Using the Power > and Elegance of Design Patterns to Complicate the Game of Life".
Hi Kent, Yeah, in retrospect, I see that the design patterns there might be overkill. There seems to be a fashionable push to introduce patterns early on in computer science education, perhaps because they are easy to put in as test questions. But despite this, I do think that there are some patterns that are worth seeing, even if they are in unrealistic toy situations. I got a kick out of seeing how 'Command' was applied in the Life example, because it shows that we can store active actions as data. > Why not just build a new world with the values of the next generation in > it, and return that from apply_next_generation? That also works, but it doesn't fit the function's description. The example that I adapted originally wanted a function that mutated the previous generation, so that's what I stuck with. > The copying is not needed at all and the command pattern is introduced > to solve a non-problem. [code cut] > The caller would have to change slightly to accept the new world > returned from the function, but there is no unnecessary copying. Sure. I didn't think of this before, but the two approaches can reflect different ways that people can represent data that changes through time: o. Making changes on a "scratch-space" copy of the data. o. Maintaining a "diff" change log. The approach with the Command pattern seems close to a diff-oriented view of applying changes to a model. If the Life example sucked, don't blame me too badly: I'm just the translator. *grin* Talk to you later! _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor