Reading Beautiful Code
I’m reading Beautiful Code and it’s very good indeed. However, you have to feel sorry for Tim Bray – his chapter, “Finding Things” is excellent, as you’d expect. The only problem is, he’s following Jon Bentley, author of that perennial classic, Programming Pearls. It’s been a while since I (re)read anything by Bentley and I’d forgotten how good his prose was.
Which isn’t to say that Tim Bray is a bad writer. Far from it. It’s just that Jon Bentley is a very good one indeed.
Apart from that, Beautiful Code is a cracking book so far, and the royalties go to Amnesty International. You should buy a copy.
Holiday Reading
Mmm… back from Scotland with a chunk of reading done:
Harry Potter And The Deathly Hallows. Mmm… top notch stuff. Wraps up the series perfectly.
The Book Thief. Wow! Seriously… wow. Whatever you do, don’t read the last chapter of this in public. I was a wreck. Beautiful. Sad. Really Sad. Life affirming stuff. Read it.
The Complete Polysyllabic Spree. Nick Hornby writes exceedingly good litcrit/columns.
Compilers: Principles, Techniques and Tools aka The Dragon Book. Good, crunchy computer science full of stuff I’ve skirted around learning for ages now. I’m still far from finished with this book. It does feel old fashioned though, and a little light on techniques for implementing highly dynamic languages.
Programming Language Pragmatics. More seriously crunchy computer science; I’ve only really skimmed the surface of this one so far, but I’m liking it a lot so far.
The Amazing Adventures of Kavalier & Clay. Another wow. What’s not to like? Golden Age Comic book history. Close up magic and escape artistry. Nazis! Citizen Kane! Astonishing, page turning, storytelling. No wonder it won a Pulitzer. It might well make you cry too (though not as much as The Book Thief)
The Essential Turing. You know how everyone who knows anything about computing tells you that Alan Turing was a genius? They’re right. I knew they were right before I read On Computable Numbers, with an Application to the Entscheidungsproblem (the first paper in this book and the only one I’ve read so far), but the paper drove home how much of a genius he was. The way he bootstraps from the idea of the Turing Machine to a Universal Turing Machine is just beautiful – one minute he’s describing the basic workings of a seemingly simple machine and a few conventions he intends to use and then within a few pages he’s implementing a Universal Turing Machine and describing it using the kind Higher Order Functions that get ‘metaprogrammers’ so excited whenever the come across a language like Ruby. Great, great stuff.
Why don't more books work like this?
When you read Christopher Alexander’s A Pattern Language, the patterns within the language are interdependent and ordered from big patterns down to small ones. Each pattern has a number and wherever one pattern refers to another it’s referenced with both the pattern’s name and its number.
Beck, Fowler and the Gang of Four (if memory serves) go one better, wherever they reference a pattern, they give the pattern’s page number (ah, the joys of computer typesetting). I’m not sure it’s an enormous improvement over pattern numbers with the pattern numbers in the running heads, but both practices make the books easy to use.
Writing this up as mini patterns, (very roughly based on Alexander’s pattern format) you’d have something like:
A Tiny Pattern Language for technical writers
1. Organizing Principle
You’re writing a Pattern Language on paper
Without some organizing principle, a random collection of patterns is just that
When you’re organizing material in a book which needs to be usable both as a learning resource and as reference material there’s a tension between the needs of the new reader who wants each pattern to follow logically from the patterns she has already read about, and the needs of a seasoned pattern user who needs to find details of a specific pattern.
It’s tempting to take the view that a reader is only new once, so it’s best to arrange the material to suit the reference user and put your patterns in alphabetical order. Don’t. If your material doesn’t make sense to the new reader, they’ll never reach the point where they use your book as a reference.
Therefore:
Arrange your patterns for new readers. Provide an index and cross references to support reference use
Use Arrange Patterns by Scale(2) to order your patterns and Reference by Name and Number(3) for your cross references. Provide a Table of Contents and an Alphabetical Index.
2. Arrange Patterns by Scale
You’re choosing an Organizing Principle(1) for your pattern language
It’s hard to understand a pattern without some idea of where it fits in the scheme of things
Read A Pattern Language, look at the way that each pattern in the book flows from the ones that precede it and leads you on to the patterns that support it. There’s a huge amount of information in that book, but it just flows. It has The Quality Without A Name.
Now read Universal Principles of Design, another book which contains a great deal of good information backed up with great pictures and some real research. Each spread in the book is analogous to a Design Pattern, and each spread is great. It’s a bugger to read though. The designers have chosen to arrange their principles in alphabetical order; reading through is like being taken on a drunkard’s walk by a conceptual grasshopper. Many of the principles are hierarchical, but the reader is left to work that out for themselves. It reminds me of the joke about reading a dictionary; the content’s great, but the characterisation and plot are all over the place.
Therefore:
Find patterns that use other patterns, put them before the patterns they use. Group patterns with a similar scale or motivation in chapters.
3. Reference by name and page number
You’re referring to a pattern.
Why can’t books be more like the web?
We’ve all done it I’m sure; one part of a book refers to another part and gives just the section title. We curse the author or his editor and go scurrying off to the table of contents or the index to find the referenced page and then turn to it, all the while keeping our index finger jammed between the pages so we don’t lose our original place.
Or the author has taken pity on us and, following the Chicago manual of style, supplies a section number (with multiple decimal points) and we start flipping forwards or backwards to find the right section number. This is less fun than it could be because no two sections are the same length. Or the content’s arranged alphabetically, and every section is the same length, but we’re not entirely sure of how many sections start with any given letter – I’m looking at you Universal Principles of Design.
There has to be a better way. Wouldn’t it be great if we could just go directly to the right page as if we were following a hypertext link?
Indeed it would.
Therefore:
Whenever you refer to another pattern, use both the pattern’s name and its page number; that way the reader can turn directly to the right page without having to visit an index or flip hopefully trying to guess how long each section is.
What next?
Obviously we need to hunt down and deliver a good telling off to authors, editors and publishing houses that don’t follow this pattern language.
Would you believe that I started this article meaning to write a review of Universal Principles of Design? Despite my grumbles about it above, it’s a cracking book full of really meaty stuff. I commend it to you all.
Spiers and Boden: Songs
Listen to this. You’ll not regret it.
Whee! John Spiers and Jon Boden have finally made an album (Songs) that sounds as good as they do live. Not that Through and Through and Bellow are bad albums, it’s just that their playing has improved somewhat since they were recorded. On stage, Jon and John play with an almost telepathic level of communication. Songs captures that magic.
Songs is the companion piece to Tunes[1] and it fairly fizzes with excitement. The material is almost all Big Ballads, and these are handled with a freshness and authority that is great to hear. The only ballad here that’s familiar to me from other singers is Lucy Wan, which Martin Carthy does so well. Jon and John give the nod to that version as their inspiration, but the result is entirely their own.
There’s one modern piece, Innocent When You Dream by Tom Waits, and it’s fabulous—the sort of song that wouldn’t sound out of place in Peter Bellamy’s repertoire next to the obscure Dylan covers, big ballads and the Kipling. You can hear Bellamy’s influence everywhere. He’s the source for one song (Derry Gaol), but Jon’s singing style has Bellamy written all over it. Like Bellamy, Jon will start a song with a testing range at least three notes higher than seems sensible and then thrill you as he hits all the high note with ease3. And, just like Bellamy, Jon sounds like nobody else4.
Buy this CD. And if you get a chance, go and see them live. Good as this album is, these guys are still improving and in a year or so this is going to sound a little bit disappointing compared to what they’re doing on stage. If they can keep doing that trick, who knows what’s going to happen.
1 Although Tunes was released earlier this year, I’ve not actually listened to it; I’m more of a songs person I guess.
2 A year or so ago I found myself singing a high harmony while Jon sang Bellamy’s setting of The Old Songs at the Cumberland singing session - I was up next and that was the song I was planning to sing so when Jon started in on it I thought “What the hell?” and came in with a harmony line - I didn’t know I could go so high. Those notes are often there if you’ve got the nerve to really go for them; they only disappear if you don’t think you can get them.
3 There’s nothing here like Bellamy’s astonishing Santa Fe Trail where, having sung the whole thing at very high altitude he repeats the last chorus singing a high harmony line that leaves you gasping. But some of the stuff he was singing with Bellowhead a few weeks ago was definitely getting that way.
4 It’s the old problem isn’t it? Bellamy sounded entirely like himself; the best way to follow his lead is to sound entirely like yourself.
Had we but world enough, and time: Serenity
Joss Whedon’s Firefly was a sf series that was never given time; episodes were jumbled by the network and the show got cancelled just when it was starting to build a serious fanbase. And that’s all she wrote.
Except, as fans of Buffy and Angel know, Joss Whedon doesn’t tell the same stories as everyone else. He managed to hold his cast together and found the funding to make Serenity. It isn’t quite the film of series they didn’t have time to make, but it comes close.
Capsule review: I liked it. I liked it a lot. You should see it.
For a slightly longer, and possibly spoilery review, kindly step behind this curtain…
I really liked Firefly. I pulled the episodes down via bittorrent as they became available and watched them in all their lo-fi glory, putting up with jaggies, out of sync audio and the rest. I bought the DVDs, downloaded the soundtrack and, a couple of weeks ago, went to one of UK’s “Can’t Stop The Signal” previews of the finished movie and laughed in all the right places as, instead of the usual previews, Joss introduced the film.
The film is great. Like most modern sf films, it’s something of a ride. There’s even the cliche of the big fight over the bottomless pit in there somewhere. But there’s snappy dialogue and food for thought too, and some beautifully violent fights (everyone else take note, casting a dancer as your lethal weapon is a good move).
However…
But at my back I always hear
Time’s wingèd chariot hurrying near
—Andrew Marvell, To His Coy Mistress
You can almost hear Time’s chariot as you watch Serenity. The shows were never slow, but the film rattles along at astonishing speed: there’s no time for sitting round the galley table; no time to give sense of lives being lived; no time for Shepherd Book; no time for anything that isn’t going to be relevant within the space of this film. Most films do this, but it’s more noticeable when you already know the characters from a TV series.
The decision makers at Fox took that time away. The bastards. I really want to see Serenity get spun off into another TV series, but the grapevine has it that that’s not going to happen—apparently Fox won’t relinquish the rights. The bastards.
“If you can’t do something smart, do something right”
Thomas More: The last temptation is the final treason,
To do the right thing for the wrong reason
—TS Eliot Murder in the Cathedral
If the film has a message, and I think it does, it’s the same one that Whedon sent in Buffy and Angel. Morality is about personal choice. When it comes down to it, integrity is all that we have and that integrity only exists if you have the freedom to do the wrong thing. For Joss, the greatest sin is taking someone’s freedom to sin from them, because by doing that you take away their chance of redemption.
Which brings us perilously close to politics, but I’ll save that for another entry.
A bright light on the culinary road to Damascus
If you’ve eaten with me, you might be aware that I’m not a big one for chili heat. I don’t mind it, but you won’t find me chopping up the Scotch Bonnets for a mole or ladling out the chili oil in a Chinese restaurant.
If you’d suggested that I would cook something that involved 3 tablespoons full of chili oil, complete with the sludge of seeds from the bottom of the jar, in a dish for two people I would have thought you had gone mad. If you had then suggested that I’d love the resulting dish with a passion that made me want to rush off and blog about it…
It all started 4 years ago when I read an article in The Observer by Fuchsia Dunlop about her time in Sichuan Province and how she became the first Western woman to study at the Chengdu School of Cookery, and how she ended up writing a book about Sichuan Cookery. It was a fabulous article, beautifully written and it set my mouth watering as I read it. “I should get that book when it comes out” I thought, and promptly forgot about it.
A few weeks ago, browsing in the Newcastle branch of Borders, I came across the paperback edition and grabbed it, took it home and read it in short order. Wow. So many Western books about Chinese food (and probably other foreign foods, I only really “know” about Chinese food) are full of compromises, on ingredients, recipe choice, cooking methods… I don’t want to learn how to make westernised restaurant standards like day glo sweet and sour pork, or chop suey. I want to know how to make Siu Yuk, or the fabulous ‘Braised Belly Pork with Sweet Preserved Vegetables’ they do at Mangos, or the amazing ‘fried blood’ I once ate with Jon Singer1 at a hole in the wall Chinese Restaurant in Washington DC’s Chinatown.
Sichuan Food definitely goes in the ‘authentic’ section of your cookery bookshelf. Heck, it took me about a month to get the store cupboard stocked with basic ingredients and I’m still trying to find a source for dried sky facing chilies and Sichuan pickled chilies, but tonight I finally cooked something from it. I went for ‘Cold Chicken Slices in a Hot and Numbing Sauce’. The thing was simplicity itself: Boil the chicken (at least free range, in our case organic), for half an hour, cover it in cold water for a couple of hours to cool down, slice the meat from one side, stick it in a bowl with some sliced spring onions, sprinkle a teaspoon of ground roast sichuan pepper over it, pour on a sauce made from the aforementioned 3 tablespoons of (home made) chili oil + sludge, sweetened soy sauce and a splash of sesame oil, mix it up and serve with rice.
It was fabulous. I confess that I was prepared to find it inedibly hot, but wow. The combination of flavours and the amazing tingly ‘numbing’ sensation from the sichuan pepper took away the burn and let you savour the tastes and textures. I’d probably eat an old boot if you chopped it up small and covered it with this sauce. But on top quality chicken… I know what I’m doing next time we have leftovers from a roast bird.
I dunno what I’m doing next from this book, but I’m delighted to report that on first showing it’s at least as good to cook from as it is to read. Definitely one for the shelf in the kitchen with Nigel, Hugh, Elizabeth and Fergus. I just wish I’d had the sense to remember to buy it in hardback.
1 If you ever meet Jon, for heaven’s sake don’t play the “I’ve eaten weirder Chinese food than you” game. I actually managed to outweird him on the Japanese stakes, but I reckon we probably managed a Chinese tie by having the fried blood…
The Pickaxe Book
I can’t remember when Adam Turoff pointed me at Ruby On Rails, but I’m still grateful. Blame Adam for the fact that this weblog is no longer running on Movable Type, but on Typo. My initial plan was to roll my own blogging software on top of Rails, but by the time I got my act together it just made sense to grab an existing package and extend it as required.
I first heard about Ruby when I read Andy Hunt and Dave Thomas’s excellent book The Pragmatic Programmer. I thought, “that looks interesting”, so I read the first edition of Programming Ruby aka the Pickaxe Book, learned the syntax and some of the idioms and then sort of forget about it. As a programming language Ruby pushes a lot of my buttons: it has closures, objects all the way down, dynamic typing and its refreshingly concise. However, I never quite got round to writing anything in it (not the language’s fault, I wasn’t writing anything in anything at the time).
Then along came Ruby on Rails and it’s lovely. I saw the first version of the Rails Video and it knocked me out. Rails does so much right. Here was a web development tool that did most of the heavy lifting for you, and makes it easy to do things Right. David Heinemeier Hansson was obviously getting a great deal of leverage from Ruby’s dynamic nature and I wanted some of that.
However, I found that Ruby had moved on since I skimmed the first Pickaxe so I got hold of a copy of the second edition of Programming Ruby. What a cracking book it is. My personal benchmark of quality when it comes to a language reference is the first edition of Programming Perl which, as well as being a language reference was an introduction to a programming ethos. Whilst I don’t think the Pickaxe is quite that good, it’s definitely up there. The chapter on ‘Duck Typing’, for instance, is wonderful. It’s a well made argument for dynamic typing and it deserves to be widely read. I sometimes think that there are two sorts of programmers in the world, those who think typed values are essential, and those who think typed variables are essential. I’m definitely a typed values kind of guy. Typed variables have their place, but that place is in the optimization toolbox next to the profiler.
Ruby’s a great language. I don’t think it’ll ever be my primary language—I still have high hopes for Perl 6, which will have all the things I like about Ruby whilst addressing some of the things about it that make me uncomfortable. But in the unlikely event that Perl 6 crashes and burns, Perl 5 finally has a competitor that I enjoy using if only because I’m sick of typing:
sub foo {
my $self = shift;
my($arg1, $arg2) = @_;
at the start of every method.
def foo(arg1, arg2)
is just so much shorter. And until I can do
method foo($arg1, $arg2) {
Ruby will entice me. Maybe I should just get Emacs to fill in the Perl 5 boiler plate…
Quite Ugly One Morning
Spurred on by the forthcoming adaptation on ITV, I’ve finally got round to reading Christopher Brookmyre’s first novel, Quite Ugly One Morning
Wow.
If you can make it past the (quite disgusting) first chapter, then you’ll be in it for the long haul. Great characters, spiky dialogue, twisty plot, worrying prescience and some fabulously gruesome set pieces and comeuppances.
So, in summary. Buy this book. Then do what I did and buy the other Parlabane books too; they’re worth it for the titles alone.
'Extreme Building'
Our experience as contractors, engineers and architects during the last 15 years has proved one thing over and over again: The things placed on drawings are inevitably – always – wrong in many particulars. Drawings serve as an important rough sketch of something that will be built, but must be executed with constant attention to room shape, light, wall and ceiling detail, openings – above all to the feelings which arise in each place, in the construction, as it is taking shape. These feelings are too complicated to predict and cannot be predicted. When a building is built from plans that are conceived on the drawing board and then simply built, the result is sterile at best – silly most of the time – and sometimes unthinkably bad. This is something familiar in virtually all large buildings that have been built since 1950. It is inevitable, given the process of construction used to build them. And it is inevitable that this process must lead to unsatisfactory results.
—Christopher Alexander, Gary Black & Miyoko Tsutsui The Mary Rose Museum
Another installment in my ongoing series of reviews of books that Amazon will take an age to deliver.
The Mary Rose Museum is an account of the Center for Environmental Structure’s bid to build a museum around the Mary Rose, Henry VIII’s flagship, which, in 1545 unaccountably sank in calm seas, in the sight of the King himself1 with the loss of nearly 700 men. The story of how the wreck was found, raised and conserved is pretty impressive in itself. I can remember watching BBC specials on the process as it was happening and being amazed at the dedication/insanity of those involved, but that’s not really what Alexander’s book is about.
In 1991, Christopher Alexander was in conversation with Prince Charles (whose interest in architecture is (in)famous). They were lamenting the then design for a museum to be built over where the Mary Rose still lies beneath a huge tent, continuously sprayed with a cold mist of water to prevent any decay of the timbers. The proposed design was for yet another anonymous hangar-like structure at odds with the other buildings in the Portsmouth Naval Dockyard, and not exactly sympathetic to either the Mary Rose or HMS Victory which sits in a nearby dry dock. The Prince sketched (probably not on a fag packet, but who knows) a profile, saying to Alexander “What about something like this?”, and off Alexander went.
At Charles’ request, the Mary Rose Trust commissioned Alexander to produce the proposal for building The Mary Rose Museum that is, ostensibly what this book is about. The bulk of the book’s 128 pages is taken up by a description of the proposed museum, outlining its development from the original rough sketch through to a fully costed, structurally feasible design.
At this point, the principle sponsor backed out leaving the project with no funds and it had to be shelved. Alexander says that, by then, he and his team had put in some 5000 man hours of work on the project; I’m sure they must have been gutted to have the plug pulled. A smaller section at the back then goes on to discuss the (much rougher) work the team did on redesigning the museum so that it could be built in incremental fashion without needing all the funds up front in the hope that the Trust’s funding could be spent on something permanent rather than having to spend a large amount of the donated money on temporary measures to maintain the structural integrity of the current ‘tent’ over the ship.
So, it’s a war story from a failed project, why should you part with the thick end of £30 to read about that? And what does all this have to do with programming? Here’s why: Christopher Alexander is the most influential bricks and mortar architect that the world of computer programming has ever known, if only for his work on Pattern Languages and ‘The Quality Without a Name’. As a literary form, the design pattern and the larger pattern language are fabulously useful (and egregiously abused) ways of describing how to solve many of the problems we face as programmers.
However, what is often overlooked about Alexander’s work is that an awful lot of what he advocates about the process of generating a room, building or town foreshadows the processes advocated by the Extreme Programming people. You should not be surprised to learn that Kent Beck, author of the seminal book on XP, was also one of the earliest writers to use design patterns as a way of addressing programming issues.
In The Mary Rose Museum, Alexander describes the ‘agile’ process his team uses on projects, and he also shows the basic contracts between Owner and Architect, and Architect and Subcontractor that he and his team use when building.
As a houseowner who had some fairly substantial house renovation done I’ve been a signatory to a standard RIBA contract for building works, and it’s a very different beast indeed from the Center for Environmental Structure (CES) contracts. I would rather have signed the CES ones. Alexander maintains, and I think I agree with him, that his form of contract deliberately nurtures the process of building something that will live, while the standard contracts are based on the myth that the plan is how it will be and any variation will cost the client. The CES contracts state up front that change happens, and handle that change without having tons of ‘extras’ added to the cost. Here’s an extract from the Craftsman/Subcontractor[2] contract.
ARTICLE 5. CRAFTSMAN’S GOAL. The ultimate purpose of this agreement is to secure the craftsman’s work under conditions which make the craftsman’s work a work of beauty and pride and self-respect, and in which the craftsman leaves behind work he is proud of, and can cherish in the future.
It is specifically understood that the craftsman’s goal is not only to be paid for his work, but that the beauty and satisfaction of the work itself provide part of the craftsman’s reward. To this end, the craftsman shall be treated as an artist who has some power and control over his work as necessary to allow the creation of a beautiful and fitting work within limits accepted by CES.
It seems to me, as someone who believes that we programmers are more craftsmen than engineers, that the CES contracts for building works may well offer a useful model for designing contracts for building software using agile processes. Certainly Alexander has interesting things to say that will repay your careful reading and consideration.
1 One theory my wife has heard is that someone on board said “Ee look, there’s t’ King!” at which point everyone on board rushed over to one side of the ship to take a look, and the subsequent heeling of the ship meant she started shipping water through the lowest gun ports.
2 The contract is careful always to refer to subcontractors as craftsmen “in order to emphasize the craft-like nature of the work which CES expects.”
"The best thing for being sad"
“The best thing for being sad,” replied Merlin, beginning to puff and blow, “is to learn something. That’s the only thing that never fails. You may grow old and trembling in your anatomies, you may lie awake at night listening to the disorder of your veins, you may miss your only love, you may see the world about you devastated by evil lunatics, or know your honour trampled in the sewers of baser minds. There is only one thing for it then—to learn. Learn why the world wags and what wags it. That is the only thing which the mind can never exhaust, never alienate, never be tortured by, never fear or distrust, and never dream of regretting. Learning is the only thing for you. Look what a lot of things there are to learn.” —T.H. White, The Once and Future King
T.H. White is one of my favourite writers. It’s easy to be dismissive of The Once and Future King, based on the Disney adaptation—which, like their version of The Jungle Books, is great fun but a travesty of the original. However, as I hope the extract shows, there’s rather more to him than that.
My favourite chapter in the book was the one dealing with the night Wart spent in the castle mews with the falcons and the baleful nightmare, Cully. Ever since I read it I’ve been fascinated by falconry—I’ll know I’ve made my fortune when I can retire to a large house in the country and keep and become a falconer. I mentioned this to Gill shortly after we met and she pressed The Goshawk on me. Wow. This is a fabulously written account of White’s attempts to train a Goshawk using a medieval textbook as his guide (even when he wrote the book, the profession had moved on a great deal, but White didn’t know that). It’s been described by austringers1 as the ideal ‘how not to’ book. But you don’t read it for the techniques, you read it for White’s perfect prose, for the boundless patience of the man and the seemingly boundless stubbornness of the bloodyminded Cully. I’ve flown a Harris Hawk on a course that Gill arranged for my birthday one year, walking around with a hawk on your fist, calmly talking to it and getting it used to you is (for me) an indescribable experience; the best I can do is point at The Goshawk and say “Read that!”
I wish I could say that Merlin’s speech branded itself on my brain when I first read it around 25 years ago, but sadly, I can’t. It only had that effect when I logged into my Linux box one morning and my standard .profile ran fortune and up it popped. Merlin’s dead right you know, the process of learning things is the finest pill to purge melancholy I know. At my father-in-law’s funeral (he had been a stalwart of the WEA for a large part of his life), we took that passage and had it printed up on cards for the mourners, and Gill used it as a reading. Everyone who knew him remarked on how appropriate and cheering it was. I hope that it will be just as appropriate a reading for me when my time comes.
1 Fabulous word isn’t it? An austringer is someone who flies hawks, as opposed to a falconer, who flies falcons.
Older posts: 1 2
