Ian Hopkinson

Author's posts

Book review: Beautiful Code edited by Andy Oram & Greg Wilson

This review is of Beautiful Code edited by Andy Oram and Greg Wilson, a collection of 33 essays by 41 authors about computer code that the authors consider beautiful. A number of the authors are very well known, including Brian Kernighan, Charles Petzold, Douglas Crockford and Yukihiro Matsumoto.

The chapters vary considerably in length but average a little under 20 pages which works well for me – I find 20 pages is a reasonable chunk to read in one go. Although the chapters are presented without any organization, they are actually grouped into themes.

A few chapters are on algorithms, which is what I think of when people talk about beautiful code. A few chapters are on applications, and their architecture, a couple are on assistive technologies, a couple are on libraries/frameworks. A few are on operating system code: device driver architecture and handling threads. It is fair to say that beauty is in the eye of the beholder, and generally I felt authors wrote about their favourite piece of work rather than something that might be broadly considered beautiful code.

Several chapters I was more interested in the subject area than the actual code. There are a couple of chapters on bioinformatics (I was a lecturer in Biological Physics for a couple of years), a couple on Python (my primary programming language for the last 10 years or so) . The Python chapters are on the implementation of the dictionary in the core language and multidimensional iterators in Numpy (a widely used numerical library). The NASA chapter was a bit of a let-down since it involved strictly ground based code. However, I was excited to learn about the challenges of two Martian time zones as well as earth based time zones!

Pretty much all of the chapters contain moderate amounts of code. The implementing language varies, there are a number written using examples in Lisp. Ruby and Perl have a couple of outings, as does Haskell, also present are Java, C#, Python and C. Reading through the author biographies it seems some of them were involved in the creation or ongoing development of some of these languages.

I gave up on one chapter in part because it was in Lisp (not a language I’ve ever used) with no support except a suggestion to go read the first few chapters of the author’s book on Scheme (a dialect of Lisp) but also because it was about macro expansion which I’ve always considered a nasty kludge. Brian Hayes’ chapter also used Lisp but provides a little schematic diagram showing the structure of a Lisp function which was really helpful. Lisp programmers really like their brackets!

It was interesting to learn about Lisp’s advice functionality which is like Python decorators. Haskell is neat in its very clean separation between pure functions and functions with side effects. I can’t help thinking that both languages are best suited to highly mathematical developers working alone, their notation is exceedingly concise and impenetrable to outsiders. However, ideas from these more esoteric languages are usefully incorporated to more mainstream ones and programming styles.

Binary search and sorting are a feature of several of the early chapters. One author points out it took 12 years after its invention for a correct implementation of binary search to be written, and only 10% of developers get it right first time when implementing it themselves. The core error is an issue with numeric overflow which highlights that the difficulty of coding comes not just from algorithmic design but also lower level implementation details. The later chapter on the numerical analysis libraries from CERN (BLAS, LINPACK, LAPACK) highlight this again, optimum algorithms changed as the underlying machine CPU, memory and network architectures changed. The book finishes with a chapter on algorithms for checking the collinearity of three points on a plane, I liked this one. The twist at the end is that the best algorithm is to measure the area of the triangle the three points form, if it is zero then the points are colinear. This algorithm has the benefit if numerical stability, again a imposition of underlying numerical representation.

I liked the chapter on a logging framework, it made frequent references to design patterns and seemed like a nice example of beauty in higher level design.

In my view Charles Petzold’s chapter describes eldritch code, rather than beautiful! He shows how to generate C# intermediate language (IL) at runtime in order to speed up image processing operations. This involves line by line generation of raw IL using C#’s reflection functions. I’m not saying it is not very cunning or interesting but it isn’t pretty. It is also a personal interest of mine since I spent a number of years working on image analysis.

Some of the applications discussed have stood the test of time, ERP5 is still around as is Emacspeak (accessibility software for the blind). I can find no trace of Cryptonite (an email client) or Elocutor (accessibility software originally designed for Professor Stephen Hawking). Components of the Subversion and Perforce source control applications are included. Obsolesce seems to be a combination of the language used, the change in the web and competition. Beautiful Code was written in 2007, nearly 20 years ago and the web was a very different place then.

A couple of chapters talked about how code appeared on the page – I particularly liked the idea of “bookish” code, code laid out in the manner of a book or magazine to aid readability – interestingly this chapter was in favour of shorter variable names for readability rather than longer ones for description. A recurring theme is that the code is never beautiful in the first instance, it normally reaches beauty by a process of iteration and refinement.

The book was first published in 2007, and its age shows in some places. It finishes with biographies of the authors which could have more usefully been put with their respective chapters. I was sad to see that only one author appears to be a woman, I suspect this would be the case if the book was written now.

I enjoyed this book, most of the chapters struck some sort of cord with me.

Book review: Daphne Draws Data by Cole Nussbaumer Knaflic

I recently reviewed Cole Nussbaumer Knaflicā€™s Storytelling with data, as a result the storytelling team sent me a (pre-publication) copy of their latest book, Daphne Draws Data scheduled for publication 29th October 2024 (UK) and 4th September 2024 (US). This is something of a change for me in the sense that the book is targeted at teaching data visualisation to the 6-9 year old age group. I am 54 – however, I have a 12 year old son and an interest in education. I have never reviewed a book intended for children before.

The first thing to say about this book is that it is beautifully illustrated by John Skewes. As I write this review Daphne (a dragon) is looking out at me from the cover of the book which has put a smile on my face.

The book follows Daphne as she visits various locations, and helps the creatures she finds there by collecting data and drawing graphs (having first reassured them that she was not going to incinerate them!). This is very much like my own career. I particularly liked the visit to the ocean where she draws a graph showing that shrimp and crabs move at the same speed if you allow for the size of the creature. This is quite sophisticated scaling analysis that I’ve taught to undergraduate physics students.

The book finishes with a glossary of chart types which is reminiscent of the material in Knaflic’s books for adults. I was slightly disturbed to see the caption “Eat a rainbow” close to an illustration of some coloured crayons but it is an exhortation for children to record the colour of the food they eat during a day and make a bar chart, rather than eating the crayons!

A children’s book fits very well with the central theme of Knaflic’s work on data visualisation which is the importance of storytelling. To be honest working out who is eating the monkey’s bananas is more engaging than the usual stories we tell in our business presentations.

I guess a key feature of books for children in this age group is that they are read with an adult, I imagine a lot of adults would learn from it too.

Alongside the book there is a website daphnedrawsdata.com which includes resources for educators, amongst much else. This shows how the book fits in with the Common Core requirements in the US school system, I’m sure this will align pretty well with the UK standards.

I’d have definitely bought this book during the COVID lockdowns as material for home-schooling, not only does it cover some data visualisation techniques but it also encourages the data collection that has been central to my life as a scientist. I’d probably also borrow the illustrations for any presentations (to adults) I might give on data visualisation.

Book review: Anatomical Oddities by Professor Alice Roberts

It turns out I could not resist another Alice Roberts book, this time Anatomical Oddities. I must admit this book was not what I expected – chapters on different, possibly pathological aspects of human anatomy. It turns out it is a book of illustrations of anatomical features of the human body with a brief description of the etymology of their name.

As such I am struggling to work out how to review it!

There are about 60 illustrations, each with a facing page of text describing the etymology of their names. There is no overall organisational structure to the book that I can discern, it does not work its way systematically through the body by location, organ type, linguistic root or anything else.

Illustration is key in both anatomy and archaeology – Roberts’ fields of study. The camera can capture very literally what we see but are not so good at showing what we know to be there or placing appropriate emphasis on the key parts of a scene. Roberts is a fine illustrator, so the illustrations in the book are pleasing. Some are straightforward anatomical illustrations, some are more whimsical (a sphincter with legs), others borrow from classical sources (the Achilles tendon is illustrated in the style of ancient Greek pottery)

Some anatomical structures are named for people, typically their discoverer – for example the “Islets of Langerhans”, which I think sounds like an excellent holiday destination, are found in the pancreas where they make insulin. They were discovered by Paul Langerhans in 1869. Who, we learn, had no idea what they did and died at the age of 40.

Other structures are named via convoluted Classical roots, the “arachnoid mater”, for example. The brain is shrouded in three membranes (meninges from the ancient Greek), the pia mater, the arachnoid mater and the dura mater or in English: the pious mother, the cobweb mother, and the hard mother. These are translations to Latin of Arabic terms from the first millennium.

The audience is another puzzle, in places the vocabulary implies a target of the interested teenager but a small amount of the content is not what you’d give your 12 year old. In the end I came to the conclusion that is intended for first year anatomy students and Roberts’ own amusement.

All of this sounds rather negative but in the end I enjoyed the book for what it was, once I’d given up my preconceptions as to what format a book that I review should take.

Book review: Britain BC by Francis Pryor

Prompted by reading various books on archaeology by Professor Alice Roberts I came to this book, Britain BC by Francis Pryor. This is a prehistory of Britain prior to the Roman invasion, at which point Britain starts to get a written history. The book covers the Mesolithic, Neolithic, Bronze and Iron Ages in 12 chapters spread across three parts, the parts covering the Pre-Neolithic, Neolithic and Bronze and Iron Ages. The Ages are divided into chapters by a mixture of more precise period and topic.

The very earliest human remains in Britain were found at Boxgrove and date back to 500,000 years ago, they are not much. There are scatterings of stone tools across southern Britain from this period. Still in the oldest division of the Stone Age, the Palaeolithic, there is the Red “lady” burial in South Wales dating from 34,000 or so years ago. This is the first prehistoric skeleton to be excavated by William Buckland in 1823 (it turns out the “lady” is a man!) . It is interesting because the body is buried with some ceremony and it is clearly a site which was returned to repeatedly.

There is then a break as an ice age intervenes before the action resumes around 12,600 years ago – at this point the diversity of stone tools becomes much greater – a hallmark of the Middle Stone Age (the Mesolithic). The ice age lowers the sea-level producing Doggerland – the area of land where the North Sea now sits – it is again flooded around 6,500BC, at which point Britain and Ireland broadly take on the outline they now have.

There are Mesolithic sites in Britain, such as Star Carr, Thatcham and Mount Sandel in Northern Ireland. These are fairly limited, generally the scant traces of temporary camps but they show some signs of structures and worked wood. Pryor notes that the shell middens found from this period (piles of discarded shells from edible molluscs) are too large to be simply practical – they perhaps mark territory.

The Neolithic is when farming starts. It is worth noting that timing and detail of the various prehistoric ages varies across Eurasian – Britain is late into the Neolithic, as a result of retreating ice. In Britain the Neolithic farming revolution likely starts with animal husbandry rather than crops – this is evidenced by the field boundaries/”crop marks” found from this period. In the past the introduction of farming to Britain was seen as an invasion of farmers from continental Europe, displacing the indigenous hunter-gatherers but the more modern view is that farming spread by diffusion and was not taken up wholesale, hunter-gatherers adopted what worked for them.

It’s in this period we start to see ritual behaviour, in particular the “sacrifice” of artefacts such as hand axes. A common find across Britain are hand axes made from greenstone originating in Great Langdale. The location where these are made is spectacular but not necessarily the most efficient and they are often found pristine. Sacrificial items are not at end of life but apparently always intended for the purpose. Pryor suggests that the manufacture of such items is also at least partly ritual, he sees forest clearance also having ritual elements and metal mining/smelting too.

It is in the Neolithic that great monumental landscapes like that at Stonehenge are built. It seems the British had a unique passion for henges, cursuses (linear, race-track shaped features) and also roundhouses – they are typically not found in continental Europe. Pryor presents some interesting ideas about the layout of landscapes and how they might have been structured following the work of Pearson and Ramilisonia, the latter is from Madagascar which is relevant because these ideas are based on some rituals from their home country. The core idea is that certain materials represent the living (wood, for example) and others the dead (stone, for example). This is also reflected in styles of pottery, some represent the living and some the dead. The ritual landscape is laid out to allow celebrants to make a journey from the land of the living to that of the dead. It seems the various ritual landscapes around Britain broadly fit this model.

I found these ideas intriguing and frustrating at the same time. I guess fundamentally I’m a “history man” – I have faith in the written record and as a long time connoisseur of archaeology programmes I know that the remains from the Neolithic are often quite subtle. It’s clear that Stonehenge is not just a few stones in the middle of a field, it has a history of thousands of years and lives in a landscape of other human structures.

Early Bronze Age tools sometimes simply replicate Stone Age tools. Metal axes are greatly superior to their stone counter parts – they are first seen about 2000BC – stone axes are rapidly replaced with metal ones. Flint working continues until about 500BC but artefacts are cruder and typically for single, special purposes. The Great Orme, on the North Wales coast and only 50 miles from where I live in Chester is very important to Bronze Age Britain, producing a couple of hundred tonnes of copper over its life time in a mine which, unusually for the time, follows a pattern of vertical shafts and horizontal galleries.

Also in the Bronze Age Pryor introduces his own work at Flag Fen which was active in the middle Bronze Age (1800-700BC). The core feature he discusses here is the causeway, a lengthy wooden structure across marshy, flooded land. Such causeways are found around Britain and Ireland. At Flag Fen offerings (sacrificed objects) are found only on the land-ward side of the causeway so perhaps it was a symbolic structure to hold back the encroaching waters.

The final period before the arrival of the Roman’s is the Iron Age. By now Britain has an extensive field system, and plank built, seagoing boats. It is also in this time that we first start to see the emergence of chieftains – Pryor has been very reluctant to accept the existence of such “big men” in previous periods, arguing that previous societies have been fairly egalitarian. It is in the Iron Age we start seeing very rich individual graves – including chariot burials. The artifacts Iron Age Britain are producing are sophisticated; wheels are constructed with iron rims and spokes and different wood species according to their functions, metal woodworking tools look like their modern counterparts, and there are also elaborate decorative objects.

Archaeologists (actually Barry Cunliffe) have divided Britain into five areas with differing economic systems and settlement styles (hill forts, open settlements, homesteads with varying degrees of fortification). These actually seem relevant today – with a South Western Zone (Celtic Fringe), Central Southern Zone (Wessex), Eastern (East Anglia), North Eastern (Northern England) and North Western Zones (Scotland).

The final chapter covers the growing influence of the Romans, Julius Caesar “visited” Britain in 55BC and 54BC. He actually visited with in excess of 10,000 legionaries who did some fighting so arguably it was more an abortive invasion attempt. We start to see local coinage in circulation prior to the Roman invasion, and there is clearly a lot of trade with the Roman Empire, with raw materials and slaves going out and luxury goods coming in. The Romans were eventually to invade in 43AD, this seems to have been by semi-invitation in the sense that there were competing leaders in Iron Age Britain with Roman using their battles as a pretext to invade in support of their favoured ones. Pryor is clearly not a fan of the Romans, he draws parallels between the Roman Empire and the British Empire, but the tables are turned.

This is definitely an enjoyable read, I think because it brings the British landscape alive. It gives the lumps and bumps found in the British countryside, and more impressive remains, meaning. I grew up in Dorset, home to many of the late Neolithic monuments, I’m currently on holiday in Anglesey – also littered with monuments and where the Romans fought the druids in 59AD. Pryor struggles to identify what has been carried over to the present from our pre-Roman ancestors, coming up with “individual freedom” which seems a bit weak to me. To me it seems our regional divisions date back to this period, as do some counties and settlements. Pre-Roman Britain was clearly a sophisticated and complex society which only lacked writing, the Roman invasion provided that and a skin of “civilisation” to the British elite. Fundamentally, the population of Britain at the time of the invasion was something like 1 million people, and the garrison left by the Romans was only 15,000 or so troops so there must have been real limits on their influence in day to day life for most people.

Perhaps perversely I am now motivated to read more about the Roman invasion and occupation of Britain.

Book review: Sound tracks by Graeme Lawson

This is a review of Sound Tracks: Uncovering Our Musical Past by Graeme Lawson, a history of musical instruments discovered through their archaeological remains. Unusually for a book such as this the action takes place in reverse, starting from the present day and finishing several million years ago. Also unusually the chapters are very short, typically less than 10 pages. Chapters are grouped into 12 chronological periods. Each chapter introduces an object, or a few objects and discusses a wider issue prompted by the object. Issues may be something like the discovery of a music shop in medieval Oxford and how it is identified from court records relating to crimes (counterfeiting) committed by the owner, how different materials are preserved, or how an instrument has developed. Although unusual I liked this style, I thought it would work quite well for history lessons. It means my usual note taking process was modified, rather than writing notes on individual pages, I read a whole chapter and wrote notes on that.

It is a fair sized book running to 50 or so (short) chapters.

Sound Tracks is focussed on archaeological finds, in terms of quantity the most finds are small, ubiquitous instruments with metal, bone or ceramic components which means things like harmonicas, mouth harps, small whistles/flutes and the metal tuning pegs of instruments like harps. These items are found as discards but not commonly. Musical instruments are also found as grave goods. However, they are not as common as finds like weapons or jewellery – unsurprisingly since few are so committed to music that they would take their instruments to the grave.

Musical instruments are also found as “sacrificial” items – sound and often valuable items which have been systematically broken or destroyed are common in archaeology – what is not clear is the “why” of such breakages.

The oldest stringed instruments, dating back to 3000BC, found in Ur in Iraq were discovered because an archaeologist spotted several interesting looking voids in a tomb they were excavating and decided to fill them with plaster of Paris. They turned out to be lyres, and their approach meant the structure of the instruments were fantastically well preserved. Even in high status graves and tombs preservation is the exception rather than the rule.

Somewhat to my surprise shipwrecks are sites of sometimes remarkable preservation in musical instruments. In the right conditions artefacts will quickly be buried by anoxic sediments which gives excellent preservation – in fact on one shipwreck written musical notes were found (although the paper on which they sat had decayed away). Lawson cites violins recovered from the Kronan in Sweden (sunk 1676) and the Mary Rose (sunk in 1545). These examples show the effect of standardisation on instrument design often fine instruments are upgraded as fashions change. In some cases instruments from shipwrecks even preserve use patterns – showing what notes were commonly played. Related to shipwrecks, Lawson also talks about whistles and trumpets used not for music but for communication and command.

A recurring theme is that instruments often appear in the archaeological record “fully-formed”, that is the earliest examples found are fully-functional and sophisticated. The cause of this might be illustrated by the development of steel drums in Trinidad, this process started in the 1930s when the colonial authorities banned the traditional bamboo drums – in no more than 20 years the steel drum was fully formed in design. So musical innovation can happen in the blink of an eye. Furthermore, experiments in musical design are not preserved – at best their components will be reused, and at worst used as firewood. Pipes/flutes with evidence of deliberate, consistent tuning have been found dating back 40,000 years.

I was intrigued to learn that the earliest keyboard instruments were Roman pipe organs dating back 1700 years, this illustrates another feature of the archaeological record – the key specimen of Roman pipe organs was found in Hungary rather than back home in Rome. In another case, the understanding of Greek lyres was advanced by the discovery of a “bridge” on the Isle of Skye, in North West Scotland.

Musical instruments can represent incredibly advanced technology. For example, a chapter is dedicated to casting church bells in situ by digging a large pit at the host church, another to a carnyx from the late Iron Age, another to a carillon of 64 tuned bells from a Chinese tomb (dating back to the 5th century BC). There are numerous well-crafted tubes forming flute/wind instruments. Lawson is an experimental archaeologist, so has experience in trying to reconstruct these instruments – it is not easy, or without risk – one researcher died from inhaling toxic yew wood dust, another from trying to play his reconstructed instrument – he blew too hard!

Writing music is a bit outside the remit of this book because it is largely a historical exercise rather than an archaeological one although Lawson mentions some musical graffiti and the earliest example of lyrics and musical notation together found on a clay tablet dating back to 1300BC in Syria. This also touches on the theme of the relationship between poetry and music. There is some evidence that epic poems like Beowulf were performed with musical accompaniment.

The book finishes with a couple of chapters on what music might have existed in the deep past on the basis on human biology, genetics and cave art. The oldest wooden artefacts recovered date back 300,000 so there is a slim chance of discovering musical instruments back to this time.

I really enjoyed this book, the short chapters worked very well for me and I’m interested in music.