On Thursday, December 13, 2012 10:52:16 AM UTC, Ben Nuttall wrote: > Another example of good use of data structure we've found recently is in > Conway's Game of Life. > > [snip] > > it can be simplified with a sensible data structure and by removing > the logic using set theory: e.g. a set of tuples (only the live cells) > therefore storing all the information you need in much less data. Your > code become more readable too - (1, 2) in alive_cells returns whether > or not that cell is alive, rather than having to loop over the values > in a nested list.
I did something similar in Ruby, much to the joy of most of the Java or C# people I paired up with. One of them was so pleased with what we did (we got a visualisation up in 45 minutes) that he asked me to save it so he could go over it again later. It's on GitHub. https://github.com/gma/code-retreat-game-of-life We used Ruby's equivalent of a dictionary instead of a set, but the principle is the same. > When pairing with C# and Ruby types, they want to either set up > multiple classes and introduce inheritance, As a Ruby type (and ex Python type) myself, I'd actually expected the common approach in Ruby to be to use the built in compound types to implement the whole thing. And yet, I paired with another Rubyist early in the day and was surprised that they wanted to start with a class to represent the state of a cell. At this point he had no plan for how his data structure was going to evolve into something that would cope with the entire problem. I assumed our different approaches reflected our relative experience of working on data-oriented problems, but perhaps you're right - perhaps there is a subtle difference in language culture. Ruby doesn't have tuples, which could make the approach of storing living cells in a set less obvious (for example, I bet many Ruby programmers wouldn't immediately know whether an Array can be used as a Hash key, while I think it's well understood tuples can be used as dictionary keys). Just out of interest, how many Rubyists did you pair with? > We could pair up and code one of these exercises in a Pythonic way, > and compare outcomes? Or discuss data structures? I've only been to one, but I like the interactivity of the Python meetings. -- To post: [email protected] To unsubscribe: [email protected] Feeds: http://groups.google.com/group/python-north-west/feeds More options: http://groups.google.com/group/python-north-west
