Category: Book Reviews

Reviews of books featuring a summary of the book and links to related material

Book review: The Programmer’s Brain by Felienne Hermans

programmers_brainI picked up The Programmer’s Brain by Felienne Hermans, as a result of a thread on Twitter. I’ve been following Hermans for quite a while, and knew the areas of computer science she worked in but my interest in Programmer’s Brain was stimulated by a lengthy thread she posted over the Christmas break.

The book is based around the idea of the brain as having long term (LTM), short term (STM) and working memory and how these different sorts of memory come into play in programming tasks, how we can improve our memories, and how we can write code that supports our use of them. It cites a fair number academic studies in each area it looks at.

The book is divided into four parts.

The first part covers the reading of code. We do a lot of training on how to write code but none on reading it, yet as developers we spend a lot of time reading code, either our own code from the past, the code of our colleagues or library code.

Perhaps most traumatic for me was the suggestion that I should learn syntax. Hermans suggests flash cards to learn syntax, as an aid to reading code (and writing it), highlighting that going and looking up syntax is likely to break our flow, by the time we have checked out twitter and some pictures of kittens. Thinking about my own behaviour, this is definitely true. My first flash cards would all be around Python – set syntax, format statements, unittests boilerplate and the options for sort and sorted.

An idea I hadn’t come across before was refactoring code for readability which may be at odds with how code currently stands; you might, for example, inline functions to remove the need to go look them up and potentially lose your place in code. Or replace lambdas, list comprehensions or ternary operators – all of which take a bit more effort to parse – with their more verbose, conventional alternatives.

Two things that aid reading code are “chunking”, experts in a field, like chess or programming, don’t learn remember every detail but they know the rules of possibility so they can break up a programme or a chess position into larger pieces (or chunks). They thus have better recall than novices.

The second aid to reading code are beacons, variable names and comments that hint about the higher purpose of code, to enable you to recall the right chunks. That’s to say if you are implementing code that uses a binary try you use the conventional names of root, branch, node, left and right rather than trying to be individualistic.

I suspect a lot of programmers, like me, will be looking at the rote learning exercises that Hermans proposes and starts to think immediately about how to automate them! I think there is scope for IDE extensions that allow you set up some flashcards or little code exercises. Also Hermans proposes quite a lot of printing out code and annotating it, again this was something I’d quite like IDE support for.

The second part is on understanding code more deeply, how it works. I was interested to learn that our natural language abilities are a better predictor of how good we are at comprehending what code does, than our mathematical abilities. In terms of understanding code, Hermans talks about marking up listings of code to highlight the occurrence of functions and variables. And, furthermore, to label variables by role following the work of Sajaniemi that is to say into the categories of fixed value, stepper, flag, walker (like a stepper), most recent holder, most wanted holder, gatherer, container, follower, organiser, and temporary. The co-occurrence of these roles provides strong clues as to what code does – in the same manner as design patterns. If we spot a design pattern we can access our long term memory as to what a design pattern does.

Following on from the idea of labelling roles of variables is the somewhat depreciated “Hungarian notation” proposed by Simonyi. This is where you include some type or role information in a variable name such as “strMyName” or “lb_textbox”, Simonyi’s original proposal was to name variables with their roles, rather than just their types which is rather less useful in strongly typed languages and modern IDEs with syntax highlighting.

The third part is on writing code, starting with the importance of naming things. The key here is consistency in naming (i.e. stick with either snake case or camel case, don’t mix), and agreeing a “name mould” – a pattern for compiling parts of a name. Martin Fowler’s “code smells” are also covered in this section, highlighting how they interact with the model and how bad code smells prevent us accessing our long term memories. 

The final part is on collaborating on code, including the developer’s great bugbear “the interruption”, it turns out this annoyance is well-founded with research showing that an interruption typically requires 15-20 minutes for recovery. I was also interested to see that we are not very good at multi-tasking, although we might think we are.

Also in this part is a discussion of the cognitive dimensions of code bases (CDCB), these are ideas like the error proneness of code, how easy it is to modify, how easy it is to test in parts applied at the level of an application or library. There is an implication here that the language you use to build a library may change over the course of time, perhaps starting with Python when you are roughing things out quickly, adding in type hinting when the library is more mature and shifting to Scala or Java when the design is stable and better performance is needed.

Finally, there is a small piece on onboarding new developers to a project, here the ideas of cognitive load repeat. Often when we are onboarding a new developer we show them the code, introduce a load of people, draw diagrams and so forth – all very fast. Under these circumstances our ideas about cognitive load tell us anyone will be overwhelmed.

I enjoyed this book, it feels like a guide to getting better at doing something I spend a lot of my time on. It is an area, learning in the field of programming, that I have not seen written about elsewhere.

Hopefully this book will change the way I work a bit, I’ll try to learn more syntax, I’ll not worry about reusing the same variable names, or even using Hungarian notation. I’ll try to remember the roles of variables. And I’ll try Hedy out with my son, Hedy is the teaching language Hermans wrote while also writing this book.

Book review: Natives by Akala

nativesA return to the Black Lives Matter theme with Natives by Akala. Natives is an autobiography which illustrates many of the points made in Why I am no longer talking to white people by Reni Eddo-Lodge and Black and British by David Olusoga. Akala highlights that his working class origins are as much an issue as his race.

Akala is a rapper, poet, journalist, songwriter, author and activist – see their wikipedia page here. I don’t know what the etiquette is for using someone’s "birth name" when they publish under a pen name. Although I had not heard of Akala previously, I am familiar with the work of his older sister Ms Dynamite.

Akala has a white Scottish-German mother and a black Jamaican father. He grew up in Camden in the late Eighties. As he points out this is as some of the overt racism in Britain, which his fathers generation had experienced, had started to recede. He went to Jamaica once as a child but subsequently has visited many times. Alongside Black America, Jamaica and Shakespeare are his major cultural influences. He visited also visited the family in the Outer Hebrides, finding Scotland less racist than England.

He clearly remembers the occasion on which he realised that his mother was white, talking about coming home school having been racially abused at the age of five by another child. For racists there is no mixed-race, no being a little bit Black – for them it is all or nothing. This is reflected in the South African apartheid era laws. So although Akala is mixed-race this is pretty much meaningless since he is considered Black by the white world. Interestingly there are gradations in the Black community where in the Caribbean the paler skinned are seen as a higher social class (I think the same may be true in India), and in South Africa being successful is "acting the white man". At secondary school a teacher once stated to him in an argument that "The Ku Klux Klan stopped crime by killing black people" – this incident gets a whole chapter, you perhaps won’t be surprised that there were no adverse consequences for the teacher.

As a child Akala was academically gifted, going to various extra classes and a pan-African school at the weekend. This was a result of his mother’s drive but does not seem to have been uncommon for Black families.

I think the thing that really hit me was that when my (white, middle-class) son, aged 9, demonstrates his academic ability we get an email from his teacher praising him. When Akala achieved academically at school he was criticised (and was actually in a special needs class at one point). A recent incident with a friend of ours suggests this attitude for children who are not white has not completely gone from the teaching profession.

Despite these academic talents he still fell into something of the gang culture for a period, as he describes it he simply snapped out of it at the age of about 25 – something he says is typical. His less fortune cohort were either imprisoned or killed by this point. This is an odd juxtaposition of someone who has friends who are classical music composers and hospital consultants, but at the same time know people who are in prison or have been killed in street violence. 

Why was Akala and his cohort susceptible to gang culture? He sees it as a working class problem, rather than a race problem – citing the high levels of gang violence elsewhere in the UK where the black population is small. A second factor is the utter distrust of the police in the black community, driven by years of prejudice. They simply don’t see the police as there for them (with pretty good reason).

You can see this happening today in the UK. There is a steady stream of stories in the press of successful black people stopped in their cars (car not registered here, this car looks too expensive for you to own it), and stopped in the street (crime by a man matching your description). As a middle aged white man I don’t get stopped by the police because I don’t look right.

Tony Blair was happy to talk about "black on black" violence, although he would never describe violence in Northern Ireland or in Glasgow or Newcastle as white on white violence.  In fact I was surprised to learn that violence in Glasgow is a bigger problem than in London but the media like to report the violence in London and imply it is about the black population. The Labour party are happy to talk about the difficulties of "white working class boys" ignoring the fact that this is largely down to class not colour.

Akala talks a bit about South Africa and Cuba, it’s interesting the emphasis that he puts on the role of Cuba in ending apartheid with their military support against the South African regime in neighbouring countries. Overall his view of Cuba is more positive than mine. I think I have been corrupted by 50 years of anti-Castro propaganda. On Mandela and the ANC he is not quite so positive as your average middle-aged white man.

I found Natives a useful complement to Black and British by David Olusoga and Why I’m no longer talking to white people about race by Reni Eddo-Lodge because it talks of the individual impacts of what these other books described in a more abstract way.

Book review: Index, A history of the by Dennis Duncan

I came to indexIndex, A History of the by Dennis Duncan via a review in New Scientist. It is broadly a history of the book centred on indexes.

Duncan starts by talking about alphabetical order, and how it first came about – people have been writing their ABCs for approaching four millennia. The first catalogues or subject indexes date to the 3rd century BCE by Callimachus in the Great Library of Alexandria. The Greeks were more keen on alphabetisation than the ancient Romans. At this time writing was in scrolls, so there were no page numbers – making indexing somewhat difficult. An interesting language aside, the Greek "sittybos" was a parchment tag used to indicate the contents of a scroll from which we get the word syllabus, index is the Latin word for the same thing.

The next phase of evolution of the index was driven by the Church during the Middle Ages. Monasteries and nunneries valued reading, and the pope decreed that cathedrals should teach in 1079 which led to the creation of universities. The codex (essentially a book) had displaced the scroll as the primary format for writing by 600AD. Reading and teaching, and preaching, led to a need to find specific parts of large volumes of text hence the index.

The Bible was divided into chapters around 1200, verses were added in 1550. This is important because in the age of the handwritten manuscript pagination is variable – chapters and verses are a substitute for page numbering. Distinctios were created which drew together Bible references to make a theme for a sermon as well as more complete subject indexes, and word indexes.

A word index, or concordance, lists every occurrence of each word in a document. Here we are seeing the struggle to find the right size for an index, a concordance is too big, a table of contents, a sort of index, is not big enough. Hugh at the Dominican friary of St  Jacques in Paris produced the first concordance of the Latin bible in around 1230. The subject index is in between the concordance and table of contents in size but finding the right size is a job for skilled humans to this day.

At the same time as the Bible was being indexed and concordance-d Robert Grosseteste was creating a great index which spanned multiple books. It is always a bit difficult to determine whether historical figures have been enormously before their time, or whether an author is casting that historical figure with the present very much in mind. This struck most firmly with Grosseteste’s great index which looks to us very much like Google’s index of the internet.

Although there were a couple of experiments with page numbers on manuscript pages prior to the invention of the printing press in around 1440, it was a while before they were commonplace. Page numbers are a bit awkward to print because they fall outside the main body of the text, so there was some experimentation with using the folio marks used by the printer to compile a book properly. Sometimes in the 15th century readers were instructed to write the page numbers into the index themselves!

A recurring theme is whether reading an index is "cheating", whether it takes away from the activity of reading fully a book. Duncan also cites Socrates’ Phaedrus where it is argued that speaking is superior to writing/reading. We see a similar argument today as to whether Google has replaced our ability to read. Thinking of my own reading of non-fiction, I don’t make much use of indexes but I do have an Evernote of books like this with page number references – as you can see here – I use them when writing these reviews, so in a sense they are my own index.

In the 17th century the index as satire was invented, it was a time when political pamphlets were all the rage, and a format was found for the satirical index. I was entertained by the story of William Bromley, and the election to Speaker of the House in 1705. Just prior to the election his enemies published an index of his travelogue Remarks in the Grand Tour which cast him in a poor light, highlight errors of fact, statements of the obvious and hints of popery. He subsequently lost the election.

A genre I’d never seen before is the fictional index, that is a work of fiction which features a fictional index or even a work that is entirely a fictional index such as Nabakov’s Pale Fire or The Index by JG Ballard. Erasmus started this in 1532. Although there were experiments with indexing fiction, ultimately these never really took off.

Universal indexes in the manner of Grossetestes’ made something of a return in the 19th century, with Jacques-Paul Migne’s collected works of the Church Fathers. Later in the century there was an abortive attempt to index everything stemming from J. Ashton Cross’s presentation to the Conference of Librarians in 1877. A longer lasting effort was William Poole’s An Alphabetical Index to Subjects Treated in the Reviews and Other Periodicals perhaps this worked because its scope was smaller.

The final chapter covers the impact of computers on indexes, so far computers have been more dumb companions rather than creators in making indexes. They are able to generate concordances very quickly but even the best software struggles to identify appropriate subjects: what to index and what not to index. The problem is that computerised search provides and adequate index, so publishers are less inclined to spend money on an index – which is a separate, specialised activity to the authoring of a book.

I was worried that a history of the index would be a bit dull but I really enjoyed this book.

Book review: Empireland by Sathnam Sanghera

empireA return to reading about race with Empireland by Sathnam, subtitled How Imperialism Has Shaped Modern Britain. I think the best way of thinking about this book is as a perspective on the British Empire and its impact on present day Britain by a British Sikh. Although the coverage is global there is a focus on India, which reflects Sanghera’s background. I’m used to reading history by white British or American authors, so this is a refreshing change.

The signs of Empire are all around us, not least in the multicultural, multi-ethnic society we find in Britain which impacts our food, our religious observances and our art. A range of quintessentially British companies had their origins in the trade with India such as Shell who originally sold shells from India! Or Liberty original founded for the India trade. There are also a range of processed foods which were developed for the empire, to remind the colonists of home or taken up following colonial origins (rum, pale ale, madeira, gin and tonic). There is some argument that our welfare state had its origins in Empire, in providing "men fit to fight" which was a concern after the Boer War. We also borrowed a significant number of words into English from the empire: bungalow, shampoo, zombie, toboggan… 

The Empire, and Imperial history is not clear cut, there are two very broad phases – the American and contemporary phase and the 19th century India and Africa phase. The Empire was not the result of a strategic plan, or governed in a unified manner, in contrast to the Roman Empire. As John Robert Seeley said: "We seem, as it were, to have conquered and peopled half the world in a fit of absence of mind". It seems also that the Empire was not front of mind for the British public for almost its entire span, in the days before a global media with relatively few British people involved with the Empire in Britain or even in the Empire this is perhaps unsurprising.

A recurring theme is how British actions in the empire were criticised at the time, on issues like the Jallianwala Bagh massacre, and the looting of Tibet. Key figures in the Empire, like Robert Clive and Cecil Rhodes were similarly criticised. The rehabilitation of Edward Colston is a case in point – he was not greatly celebrated during his life and the subscription to raise his statue some 200 years after his death was not filled. It is only with the recent en-harbouring of his statue that he has gained support. History that seeks an unalloyed positive view of the Empire just isn’t history. 

Looting gets a whole chapter of its own, it focuses on the case of Tibet which was invaded by the British in 1903/4 – interestingly the invasion was commonly referred to as the "British Expedition to Tibet" or the "Younghusband expedition to Tibet" – note the rather passive language. It is clear that looting was seen as part of military operations and was formalised. There is a degree of greyness in the process since troops were on occasion censured for looting, and there were budgets for the purchase of artefacts. However, there were clear processes for the handling of artefacts looted during invasions and the sums set aside for purchasing artefacts were completely incompatible with the amount of loot returned to Britain. In Africa human body parts were taken by British soldiers as trophies, something which caused disgust in Britain at the time.

The sad thing is that most of the looted artefacts in British museums are not actually on display, and in the more distant past they were scarcely valued at all. Sanghera points out that the British establishment finds it impossible to return looted artefacts from British museums to their rightful homes but has quite the opposite attitude to people with established lives and families, as long as their skin is dark.

Immigration was often at invitation, citizens of the British Empire were just that but whilst white members of the Commonwealth have always had a welcome in Britain, those of colour have not. Conversely Britain has a large emigrant – outbound – population. It is part of the deal. Sanghera writes a bit about Britons abroad, the Brit transplanting their lifestyle to Spain is seen as a continuation of the colonial times.

Sanghera talks about racism and white supremacy in the British Empire. This is pretty explicit, the leading figures in the Empire were very clear that they saw the white British as superior and indigenous populations as naturally inferior, in need of the firm hand of white rule. White rule, sometimes meant massacre or even genocide, as was the case for the indigenous Tasmanian population.

Sanghera ends on a somewhat positive note, although Britain is not at the forefront, countries like Germany, France and the US have started talking about the return of looted artefacts, reparations for slavery, and some degree of contrition for their actions during their colonial period. The British government is trailing in this, although the public Black Lives Matters protests, and private initiatives to return looted artefacts, and discuss more frankly our troublesome past are taking place.

I think this was a useful step on my journey in understanding my country, and all the people that live here.

Book review: Much ado about mothing by James Lowen

mothingExcited by my recent purchase of a trail camera to observe the wildlife in our backgarden (mainly foxes), I was draw to moths (and mothing), like a moth to a flame or a pheromone lure (it’s the modern way). Much Ado about Mothing by James Lowen speaks of a similar attraction, structured into a book.

Much ado about mothing is based around the idea of finding 120 target months over the space of a year. It is divided into chapters that track through the seasons and through different ecosystems such as heaths, beaches, salt marshes, forests and so forth. I was pleased to see my home county of Dorset, particularly Portland and the heaths around Purbeck where I grew up, featuring heavily. Over the period of a year Lowen ran a light trap in his back garden in Norfolk on 151 nights, capturing 15,000 individuals from 466 species as well as travelling far and wide in Britain to find moths.

Moths are the super-group in which butterflies are a subset. They are more numerous in terms of species than butterflies by a large margin – perhaps 40 times as many moth species as butterflies. Many of the females are flightless (making them more difficult to find). 90% of moths are nocturnal.

Unlike butterflies, moths are quite docile when trapped and can be handled. The Victorians used sugar and wine mixtures on ropes ("roping") to trap their moths, as the 20th century progressed it became possible to use portable lights and most recently pheromone lures to trap moths. Pheromone lures are used in crop protection and are specific to a species, they mimic the pheromones that females emit to attract males.

As well as the moths with which we might be familiar there are innumerable micromoths typically with only a Latin name, there’s a discussion amongst moth-ers on how (and if) to give them "common" names.

It seems many moth-ers got there from birdwatching, and many RSPB centres double up as centres for mothing. Perhaps it is the easy abundance of moth species which attracts them and the rather better accessibility than birds – you can keep moths in your fridge to share with fellow moth-ers! Around the country there are a number of conservation projects focused on moths these seem to be coordinated by the charity, Butterfly Conservation.

The picture for moths as a group is mixed, many species are in decline as a result of habitat loss. In addition to draining of marshlands, agriculture and rising temperatures, many have very specific host plants, so the loss of the host plant leads the loss of the moth. I wonder why this specificity is favourable from an evolutionary point of view. There are new arrivals though, and territories expanding as temperatures rise.

I found myself Googling pictures of the moths mentioned, there are colour photos of some of the moths but they are all bundled together in the centre of the book. Lowen works hard to describe moths in many varied and interesting ways. You might want to follow the @BritishMoths twitter account for a regular fix of moth content. You can get an overview of British moth species on the Butterfly Conservation A-Z page, species mentioned in Much ado include Clifden Nonpareil, Elephant Hawk-moth, Kentish Glory, New Forest Burnet, Oak Eggar, Buff-tip and Merveille du Jour. I recommend this page as a perfect supplement to the book!

Much ado about mothing is more in the style of a travelogue than a nature book but I suspect this means it sneaks in many facts about moths which you wouldn’t find by reading a moth identification guide. I have learnt that Batesian mimics are those species that mimic other, toxic, species whilst Mullerian mimics are genuinely toxic. This I learnt in the discussion of Clearwing moths, a group of moths that mimic wasps.

The other prominent aspect of the travelogue style is the people he meets, mothing seems quite a sociable sport. Sometimes this is because the fellow moth-er is a warden at a nature reserve but other times it is a group of friends, or moth  enthusiasts who share sightings and information – as well as camping out in all manner of locations to look after moth lights.

I think Much ado has done its job since I’m now keen to start my own mothing. I bought a telescope as summer approached – it doesn’t get dark until really late and we had a small child – so observing the night sky was tricky. I’ll not make that mistake again! Moths are most common during the summer months, there is little point in buying a moth trap for Christmas so I will get mine in late Spring.