Skip to content

Three books you probably haven’t heard of

Since nothing earth-shaking has happened in Real Life® lately, I thought I would recommend some books. But this isn’t a “best of my bookshelf” post: the best books I own you probably already know about. Instead these are the obscure but interesting ones: not necessarily recommended for everyone, but if one does catch your interest there’s a good chance you might not already have read it.

(Continued)

Back from Greece

So if you were thinking of robbing our house, wait for the next holiday.

In Athens, a city with a population just slightly less than that of New Zealand, we managed to bump into someone we met last year on holiday. We played rebetiko with the members of Giouf and stayed in one apartment with a view of the Acropolis, and another with a pair of delightful kittens.

In Katerini, Olga’s mother fed me as implacably as always. We swam in the sea, three times. (Greeks seemed to think we were slightly mad, but the water, although not at summer temperatures, was perfectly pleasant to stay in for a half hour or so.)

We drove to Thessaloniki to play rebetiko, and got home again at six in the morning.

For the first of May we joined some dear friends for a massive barbecue. To my great regret I failed to get a photograph of Stathis, four years old, with a wooden dagger in one hand and a souvlaki in the other, alternating between angelic stares at the goings on and enthusiastic gnawing on the souvlaki. I did, on the other hand, get a video of a beautiful oud performance by a friend-of-a-friend, but I managed to take it in portrait. Coming once I figure out how to turn it upright.

We spent another night close to Thessaloniki, entertained by Karagiosi (shadow puppet theater) performed by an eight-year-old, and then by the same story in abbreviated form courtesy of his four-year-old brother. The day after we added another member to our family:

Jasmine, or Γιασεμή, the lafta or lavta

Her name is Γιασεμή, or Jasmine (pronounced something like Ya-se-mi), from this beautiful song. She is a lafta (or lavta), a Turkish instrument sometimes called the “politiko laouto” in Greece (“the lute of Istanbul”). My plan is to use her frets and simpler tuning system to learn to hear the intervals of makam theory (much more nuanced and beautiful than the simple semitones I grew up with), so that I can start playing them also on the (fretless) oud.

It seems like wherever we went I got job offers. Some of these were late-night wine-assisted affairs of the “I know some guys who do web programming from home, surely you can help them out?” kind, but there seem to be some real possibilities for the end of this year or beginning of 2013. Fingers most decidedly crossed on that count…

Finally we played one last rebetiko session with the Katerini crowd, and left (reluctantly) at two in the morning, just as the party was getting started, to drive to the airport for the flight home. Olga is now ensconced in front of the laptop watching the election results come in, and we’re already planning the summer holiday.

Silence is sexy

Work is busy, we played in a symphony last weekend, now we’re going to Greece for a week. Quiet times ahead for a wee while yet.

In the meantime, if you’re not already reading Auch on Water, you should be.

Also in the meantime, something we cooked up the other evening:

Our new business cards

’Ow’s yer ’elf?

Today my public-shaming strategy paid off once again: I did a nice sweaty round of sun salutations rather than have to post here that my weekly exercise total was absolutely nothing. (In other words: yoga, once.) Not to worry though: the new rowing block starts tomorrow.

The extremely observant may also notice a dearth of non-exercise-related posts hereabouts. The weeks have been fuller than usual lately: Buzzcapture is working up to a (beta) product release, and the Via Egnatia Group (which I joined a month ago or so, playing Irish bouzouki) had a couple of concerts (yesterday night at the Pianola Museum, which is an amazing place). I have some plots and plans, but experience tells me that if I promise them here they’ll never actually come to fruition, so I’d better not.

’Ow’s yer ’elf?

Yoga. Once. Sigh.

Inferior decorating

It’s another programming post, sorry Mum!

Python’s decorator syntax is an extremely lovely piece of incremental language design. It adds just a tiny bit of syntactic sugar to the language, but that sugar makes you think about structuring your code in ways that I (at least, and apparently plenty of other people) find extremely productive.

There are two sane ways to write a decorator:1

def decorator(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        # do what the decorator does and...
        return func(*args, **kwargs)
    return wrapper
 
def decomaker():
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            # do what the decorator does and...
            return func(*args, **kwargs)
        return wrapper
    return decorator

The tl;dr of this article is: always use the second one.

(But why?)

Notes:

  1. There are less insane ways than I would have expected, because Guido in his wisdom followed a gut feeling and restricted the syntax of decorator expressions. []

’Ow’s yer ’elf?

This week’s total: one hour of rowing. Better than nothing, but nothing to be proud of. In a couple of weeks I’ll be rowing twice a week instead of just once, but I still haven’t managed to get a running schedule together.

Gatekeeper

There is a thing I’m reading, a serialised novel by the name of Constellation Games. It’s a slightly guilty pleasure, because its protagonist is a programmer in his thirties who gets to visit the Moon and play computer games with space aliens. And yes, I have been enormously enjoying his capsule reviews of alien computer games.1

So it seems other people are enjoying Constellation Games; people who are even closer to its ideal demographic; people who actually make games. Which is why there now exists Gatekeeper: a game written by space aliens millions of years ago, which you can play in your browser.

I can’t say that you should read Constellation Games if you enjoy Gatekeeper. (In fact, if you enjoy actually playing Gatekeeper for more than a few minutes then I’m a bit worried about you.) But if Lek Stalker and Ruins Deluxe tickle your funnybone, check out the rest of the novel. (Also, it is dirt cheap.)

Notes:

  1. I’m a sucker for microfiction and for reviews-as-fiction. Even with real computer games I have been known to let reviews, backstory and a bit of shoulder-surfing substitute for actually playing. []

Python list incomprehension

Here’s an oddity of Python that I stumbled upon, which has turned me off doing anything even remotely complicated with list comprehensions. For those following along at home, fire up your ipython now.

In [1]: array = [[1,2,3], [4,5,6], [7,8,9]]
In [2]: [ sum(col) for col in array ]
Out[2]: [6, 15, 24]

So far so good. Now suppose I want to take the squares of all the elements in array, and flatten the results into a single list. This looks to me like a natural way to do it:

In [3]: [ x*x for x in col for col in array ]

However, it is wrong. The result:

Out [3]: [49, 49, 49, 64, 64, 64, 81, 81, 81]

At this point I should insert a picture of a horse in a raincoat holding a cat or something similar.

Let’s try that one more time, for sanity’s sake:

In [4]: [ x*x for x in y for y in array ]
NameError: name 'y' is not defined

Wat?!

What’s going on is two distinct oddities of Python, which I have encountered in production code and debugged so that you don’t have to.

Firstly, loop variables leak into the surrounding scope.1 It’s easy to forget this for list comprehensions, since they don’t overtly contain a loop, but they work just the same. In our example, the col variable that for x in col is using is actually the exit value of col in the previous list comprehension. If you were following along at home and didn’t do that first, trivial, comprehension (with sum(col)) then chances are you didn’t have col defined in your ipython session and you hit the error early.

Once we’ve got that far, it’s easy to see where the example went wrong: variables are introduced in a list comprehension left-to-right, not right-to-left, so for row in array for x in row is the correct order. We can get here also by mentally creating the nested lists the comprehension represents:

for row in array:
    for x in row:
        yield x*x

A comprehension lifts the yield line to the front but leaves the loops in the same order.

Still, I think my ordering is a more natural way to represent the expression I’m trying to capture in code. I had assumed that it came from my long-ago love affair with Haskell, but that’s actually not the case. The equivalent Haskell expression is:

let array = [[1,2,3], [4,5,6], [7,8,9]] in [ x*x | row <- array, x <- row ]

The order the variables appear in is actually just the same.

This doesn’t raise my hackles the way the Python version does, though. The Haskell code clearly distinguishes the pipe from the comma; the rule you have to know is, before the pipe sees (variables defined) after the pipe, and scope resolution for commas works left-to-right as usual.2 The weird thing about the Python version is that for <something> in <somewhere> has different scope resolution rules depending on where it is: the first instance in a comprehension resolves the <something> in <somewhere>, but later ones cannot.

So there you go. A case where Python’s minimalist syntax, which usually I very much appreciate, seems to me to be taking things a bit too far. And (again, just my opinion) a good reason to avoid this kind of list comprehension construction completely. Although in this case the alternative, a wordy map-lambda and an esoteric sum, doesn’t make me any happier:

In [5]: map(lambda x: x*x, sum(array, []))
Out[5]: [1, 4, 9, 16, 25, 36, 49, 64, 81]

Notes:

  1. All Python programmers should know this about the for loop, since it lets you query the final value of the loop’s variable after exiting the loop. []
  2. And the same rules apply elsewhere in Haskell, for instance when pipe is used for guard expressions. []

’Ow’s yer ’elf?

Mission accomplished: the thought of writing this entry has driven me to exercise.

Not much exercise, mind you: 20 minutes of yoga this evening. But more than nothing, ergo better than nothing.

“Nothing?” you ask, “but whatever happened to running, and to rowing?” What happened this week is that I got ill. (Possibly helped along by running, and sweating, for 50 minutes in a t-shirt. It’s not actually really summer yet, turns out.) Tuesday I felt under the weather and skipped rowing, and Wednesday I woke up unable to speak and stayed in bed all day.

I must admit that the illness card had thoroughly played itself out by the weekend, so I have only laziness to blame for not getting back into the saddle. (After my last run my legs ached for days. I’m reluctant to go through it again, although I know I should.)

In more positive news, coming Tuesday is the last rowing session for this block and I’ve signed up for twice a week in the following block (back to one-man boats, and I hope by the time it gets warm and Springy to be in a skiff).