Real Ultimate Programming

The Home for People Who Like to Flip Out and Write Code

Notes From PyATL 2011-10-13

An Example Python Program (Brandon Rhodes)

Looks like he is going to be using Python to do on-the-fly decompression of messages in the maildir format.

Pretty cool that he’s teaching the iterator protocol in passing.

I was not aggressive enough; he’s actually opening the emails and searching them for keywords.

Here’s the part where he emphasizes just how many batteries are included.

Monkeys, Typewriters, and the Complete Works of Shakespeare: A Brief Introduction to List Comprehensions (John Hackett)

He’s preaching to the choir, here. I love me some list comprehensions.

List Comprehensions in Python and Haskell (Kelsey Hightower)

The term came around in 1977 via NPL (never heard of that one before).

Python chose to crib from Haskell.

Haskell needs comprehensions, because that’s The Way™ you do iteration.

I so need to get around to learning Haskell.

[n * 2 | n <- [1..9]] is roughly equivalent to [n * 2 for n in xrange(1,9)]

[x + y | x <- [1,2], y <- [1,2]] is roughly equivalent to [x + y for x in [1,2] for y in [1,2]]

[n * 2 | n < [1..9], n > 3, n < 5] is roughly equivalent to [n * 2 for n in xrange(1,10) if x > 3 and x < 5]

Sweet! You can store list comprehensions as a function and the source can be the parameter to the function.

Differences:

  • storing a comprehension in a function
  • It’s faster in Haskell
  • Comprehensions are essentially syntax sugar in Python, but they’re fundamental in Haskell.

GEvent + Socket.io (Rick Copeland)

How many of those beers did Brandon have? He just called us butterflies?

Back to flipping out…