Specs, Bugs & Rock’n’Roll

Great Scott! I have probably seen Back to the Future over 100 times. It’s one of my favourite movies, and it’s also astonishing how a movie that I loved when I was seven years old has retained it’s appeal for over twenty years - it’s like it somehow evolved from a time-travel movie into a 50s/80s period time-travel movie without ever really looking dated in between. (That, or I’m just a huge nerd with an 80s obsession who never really grew up.)

Anyway, you know the scene where Marty’s playing at his parents’ high-school dance, and he’s about to leave, and the band ask if he’ll play one more – “c’mon, something that really cooks” – and Marty steps up to the mic, jokes about “this one’s an oldie… at least, it’s an oldie where I come from” – and then he plays a storming version of Johnny B. Goode, and invents rock’n’roll? Well, as a kid watching this movie over and over, that’s one of the things that never, ever made any sense to me. Time travel, fine – I mean, they have a nuclear DeLorean, right? – but the band jamming along, in perfect time, to a song they’d never, ever heard before? Inconceivable!

A couple of years later I took up the guitar, probably inspired in no small part by Marty McFly, and along the way I started picking up odd bits of music theory. I remember watching  Back to the Future one day around this time, and noticing something I’d never noticed before… just before Marty starts his whole Johnny B. Goode riff, he says to the band “Ok, guys, this is a blues riff in B; watch me for the changes, and try to keep up, OK?” Right up until that point, I’d been teaching myself guitar, on my own, by playing along to tapes and stuff. I’d never been in a band and never really taken any formal music classes. I had some music theory books, and I knew vaguely what a "blues riff" was, but I’d never stopped to think why that particular chord sequence had a special name. See, when you’re playing guitar by yourself in your bedroom, you don’t need to communicate with other musicians, so a lot of things – sheet music, sight reading, key changes and music theory – just seem like a complete waste of time. Of course, to seasoned pros like the musicians in Marvin Berry’s Starlighters, those two simple bits of information - “blues riff” and “in B” – tell them exactly what’s about to happen – at least, in enough detail that they can join in at the right point, hit the right notes, and work the rest out as they go along.

What’s this got to do with software? Well, blues riff refers to a 12-bar blues chord progression, which is a pattern - in both senses of the word. Trivially, it’s a repeating sequence of things; in this case musical chords. It’s also a pattern in the software/architecture sense - a recurring ‘solution’ that’s implemented in many different contexts. Whilst the implementation details may vary wildly from one implementation to the next, the underlying structure doesn’t. Whether it’s jazz, thrash, funk or fusion, you’ll find twelve-bar patterns cropping up all over the place in contemporary music, and

This is why design patterns are important in software development. Knowing them doesn’t necessarily make you a better programmer. Just as someone can play a wonderful tune without knowing what all the notes are called, it’s quite possible to implement design patterns without being aware that’s what you’re doing. I built some code years ago that used an ‘active record’ design.  At the time, I had never worked with design patterns. I had no idea that my “objects-based-on-tables” solution had a name, or that anyone else was doing the same thing. Without that shared vocabulary, though, collaborating on that code was painful. I had to explain that code line-by-line, explain what it does, how it works, how all the pieces fit together. It’s time-consuming, it’s error-prone, and it’s probably really, really boring for the person listening to the explanation.

Imagine Marty McFly turning to the band and saying “OK, guys, this song has this chord here (plays a B chord) for four bars, then two bars of a this one (plays an A chord) – got that? – and then two bars of that first chord again…” and so on for about ten minutes; and the band are working it out and making notes as he goes along, so they can remember what goes where, and by the time he’s done, the crowd’s got bored and lost interest, Lorraine’s gone home with Biff, and George is out in the parking lot crying quietly into a copy of Amazing Stories.

On the other hand, you can learn the patterns. Not because they’ll make you a better coder, but because they’ll transform your ability to communicate with other pattern-literate developers. You’ll learn them, and you’ll practice them at home, on your own little projects, and then when Lead Architect Martin McFowler turns round at the start of your next project and says “OK, this is a domain model with data access via a repository, we’ll manage references via an identity map and use concrete table inheritance to map the subclasses”, you can sit down, work out how to apply those patterns to your particular project, and bam! – you’ve just invented rock’n’roll.

http://www.seeing-stars.com/Locations/BTTF/Dance-JohnnyBGoode(smaller).JPG