skip to main bit
a man slumped on his desk, from 'The Sleep of Reason Produces
      Monsters'

Oblomovka

Currently:

python class Culture:

Every Friday at EFF, we have a Python class, where anyone in the org (and a few friends from outside) join up to learn a little Python, talk about coding and share what they’ve learnt. There’s a good mix of seasoned python hackers, coders who don’t know much python, casual programmers, and people for whom this is their first experience of programming.

The part i enjoy the most (apart from congratulating myself for reaching a level of maturity that means I don’t go I KNOW I KNOW whenever i know the answer) is the material that isn’t about the technicalities of programming, but of the culture. We often discuss, for instance, about the most aesthetically pleasing way of writing code. Watching smart coders attempt to verbalise those instincts is fascinating, especially when the instincts begin to spread through the group.

To give an example, we’ve been coding up a Python version of Conway’s Game of Life. We all spent a fair bit of time discussing that niggling problem with counting up how many neighbours a cell has. Do you do it “manually”:

or iteratively:

I think most coders would end up doing the first, but they would feel a bit dirty doing it, just as I always feel a bit dirty when I have x and y as attributes, instead of being able to treat them as different aspects of the same thing. It’s the right instinct to try and generalise, and it was fun seeing starter programmers expressing their mild discomfort.

After we’d got Life to work, Seth rewarded us by showing Golly, which is a great cross-platform Life simulator with many pre-programmed patterns. I really had no idea that they’d managed to code up a Turing machine in Life, let alone patterns that emulate a universal machine, running a program that runs the Game of Life.

5 Responses to “python class Culture:”

  1. Sumana H. Says:

    Yay for Python classes at work! That is so freaking awesome. A friend of mine works at a firm where every Friday at 4:30 is “hamster time” and responsibility for organizing a silly, fun contest rotates from staffer to staffer.

  2. Michel Says:

    I would not use the first version, but that’s only because you included cell(x+1, y-1) twice :-b

    I’m curious, is the second version about as fast as the first ? My instincts would tell me about twice slower, but I never tried, and I have not done that much python so I don’t really trust them much either.

    Also, I would consider the first version with some indenting done to arrange the 8 cell() invocations into a 3×3 grid with a hole in the middle.

  3. Waider Says:

    At one point in college I was working on something that required similar grid processing, and I started out with the first variant and then gradually rewrote it into the second. When I got it to what I considered to be the cleanest variant of the code – essentially one long line of C featuring several nested loops – the compiler broke.

    @Michel: I strongly suspect that speed differences for something like this get optimised away if your interpreter starts doing stuff like unrolling loops. As I was recently advised (with respect to Perl, but it’s universally applicable) on the topic of second-guessing which variant of an algorithm is faster (or smaller, or less of a resource hog in general) it’s usually better to benchmark than to try and guess how the compiler/interpreter you’re working with will deal with the code.

  4. Jens Ohlig Says:

    Couldn’t you just do it in one line?

    neighbour = len(filter(lambda i: (i == 1), map(lambda j: (cell(x+j[0], y+j[1])), [[-1,-1], [0, -1], [1, -1], [-1,0], [1,-1], [-1,1], [0,1], [1,1]])))

  5. Jens Ohlig Says:

    Never mind :) This is just the functional way to write what you called “doing it manually”… But it seemed a bit clearer to me.

                                                                                                                                                                                                                                                                                                           

petit disclaimer:
My employer has enough opinions of its own, without having to have mine too.