On 13 December 2012 10:52, Ben Nuttall <[email protected]> wrote:

> Hi Safe
>
> The tennis scoring is interesting. Robie and I coded a simple
> implementation each since the last meet, using a dictionary of tuples
> mapping one score to the next (for player one scores) and reversing for
> player two. It removes the logic code you would otherwise need to write and
> test.
>
> Another example of good use of data structure we've found recently is in
> Conway's Game of Life. I've written a number of implementations of this,
> particularly at XP Man and the Code Retreat. When pairing with C# and Ruby
> types, they want to either set up multiple classes and introduce
> inheritance, or have a grid and store the 'alive' state as 0s and 1s in
> each position in the grid. I saw a video from PyCon recently (Stop Writing
> Classes [1]) where it was suggested that these usual approaches are
> overkill and that 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.
>

I couldn't agree more. Classes are a wonderful thing but people will
commonly factor them in prematurely, probably because we feel we're
expected to do so when writing object oriented applications, and possibly
because there's an assumption that Python's (excellent) collections class
won't do the job on their own. I'll hasten to add that there's nothing
wrong with classes, but I tend to use bare collections as far as sensible
then migrate to wrapping in a class, but I'll migrate to using them when
necessary and useful as part of a refactoring.  Pythonic and agile :)


> 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.
>

This is an interesting point. I agree that the code is very readable
because you're using constructs that Pythoneers know about already (e.g. a
tuple and the "in" operator) and immediately understandable because there's
no need to go looking at a class and understanding it first.  Having said
that, a good abstraction can be very useful! The following code is also
very readable:

cell = Cell(1, 2)
cell.is_alive()

And the ability to give useful and descriptive names to methods is a great
invention:

cell.number_of_neighbours()
cell.will_die()


> We could pair up and code one of these exercises in a Pythonic way, and
> compare outcomes?
>

Sounds good. Are you thinking tennis, Conway, or some other exercise?

Or discuss data structures? I've coded with people recently who, it turns
> out, didn't know what things like dictionaries, tuples and sets are. I'd
> love to find out if there are any useful ones I don't know!
>

Interesting aspects of lists, dicts, sets and the collections module could
do with a talk of its own! (Volunteers?)


>
> I'll be at the Madlab Christmas Party - hope to see a few Pythons there!
> I've donated a Raspberry Pi as a raffle prize. If any of you would like to
> donate a prize, or some food for the party - that would be much appreciated
> by Madlab. I'm feeling particularly grateful for Madlab at the moment as
> the Sheffield GIST Lab (the organisation that eased me in to the tech
> community with Sheffield GeekUp) has just announced it is closing down,
> which is really sad. Thanks to Daley for his contribution to the GIST Lab.
>

> See you all next week
>
> Ben
>
>
> [1] Stop Writing Classes - http://www.youtube.com/watch?v=o9pEzgHorH0
>
>
>
> On Wednesday, 12 December 2012 11:50:09 UTC, Safe wrote:
>>
>> Hi All,
>>
>> Python Northwest will be getting together again for a coding meeting at
>> 7pm on Thursday 20th December at MadLab.  It would be great to get an idea
>> or two together in preparation for the meeting.  As a starter for 10,
>> possibilities include:
>>
>> - On the way out of English Lounge last time, there was some discussion
>> about how you might go about coding a tennis scoring application.  It might
>> be interesting to compare approaches, and with a bit of effort, perhaps
>> find point-by-point histories of classic games on the interweb, feed them
>> into our scorers and see how well they do.
>>
>> - In the past we've run a coding dojo style session where we make
>> suggestions of what we might code then take a vote and get cracking.  Past
>> suggestions have included a crossword generator, a poker hand scorer and a
>> DVD database.
>>
>> Other ideas?
>>
>> fyi ... MadLab is also holding an End of Year party on Tuesday 18th
>> December to which we're cordially invited!  Details here:
>> http://madlab.org.uk/**content/madlab-end-of-year-**party/<http://madlab.org.uk/content/madlab-end-of-year-party/>
>>
>> Best,
>>
>> Safe
>>
>>
>> Safe Hammad
>> http://safehammad.com
>> @safehammad
>>
>  --
> 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
>

-- 
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

Reply via email to