Feb 13 2019

Book review: Eloquent Javascript by Marijn Haverbeke

eloquent_javascriptThis is a review of a more technical book, Eloquent JavaScript by Marijn Haverbeke. The book has the appearance of being about learning programming from scratch but I suspect anyone using it as such would struggle. However, if you have some background in programming it is something of a delight.

The book is divided into three parts, on JavaScript itself, the web browser, and node.js – where JavaScript can run without a browser. Along with a description of the core features of the language there are some significant examples, elaborated over full chapters.

These are quite engaging although a bit off the wall. One concerns were-squirrels, another crows, making a pixel art editor and a platform game seem rather tame in comparison. These examples show you how you should use language features, rather than just giving you a pile of bricks from which to construct your building.

JavaScript has evolved since it was first introduced in 1995 with a major update in 2015 including modules, promises, and generators amongst other things – Haverbeke covers these (highlighting what is new). This is useful to know since I started programming in JavaScript a while back where I observed, for example, that arrays were looped over by index, but now I find I no longer need to do this.

Coming to JavaScript from another language I find the event driven, asynchronous features of the language most difficult to understand, and the older JavaScript way of using callbacks to handle these features produces code which is difficult to read – certainly to my eyes. Promises offer a clearer way of implementing asynchronous code. 

Importing modules still feels like an area undergoing much needed development. Originally JavaScript had no built-in functionality to handle modules, but this gap was filled with third party libraries. Now module management has been built into the language but a lot of legacy code uses incompatible third party libraries, and node.js doesn’t fully support the new module features (as far as I can tell).  Haverbeke mentions how some of these difficulties are handled with the toolchain associated with JavaScript.

JavaScript seems to have some pretty wacky features: month numbers start at zero, exactly like absolutely no system of date description I have ever seen. The case-switch syntax seems really odd, although I understand it is inherited from C/Java like languages. JavaScript’s try/catch functionality is indiscriminate by default which is considered bad style in Python although there are workarounds for this. 

Although I’ve been working with browsers and JavaScript for the last 6 years or so, I still learnt new things about how browsers work. Such as the different applications of the onclick attribute and addEventListener, the former only allows for one listener per element.

One of the examples uses “long polling” to demonstrate how to update a web page at regular intervals, or when the content changes due to actions elsewhere.

The material on node.js was new to me. I’m aware I should probably be writing tests for my JavaScript code, and node.js is the easier way of doing this. node.js is based on the Chrome V8 JavaScript engine with extensions for handling Input/Output amongst other things, features which belong on the server side rather than the browser, client side.

I quite like that, in common with Python, JavaScript uses convention to make class methods private. Basically programmers agree not to use a method if it’s name starts with an underscore! 

Python (my favoured language) and JavaScript both have the air of being little things designed to smooth your path rather than serious languages for serious projects like C, C++, Java, Fortran, and C#. However, Python is arguably the most important language in data science applications and many of the big internet companies have significant investment in Python code. Whilst JavaScript is arguably the most important language in the world at the moment, almost everything that happens in a web browser has JavaScript behind it.

The book finishes with a chapter on performance, I found this really interesting. JavaScript engines have a multi-stage approach to compiling JavaScript into executable code. It starts with a quick and dirty compile, but then returns to do optimisations if code is run frequently. Somewhat disconcertingly different JavaScript engines handle the programmers attempts at optimisation differently i.e. you can optimise your code for Google Chrome only to discover it runs more slowly in Microsoft Edge.

There’s no description of the JavaScript dev environment or tool chain in Eloquent JavaScript. Although I missed this it is probably best not to include in a book such as this – tools change rapidly and what works for one developer doesn’t work for another both in aesthetic and practical terms.

I think this is one of the most enjoyable programming books I’ve read. It covers the core features of the language concisely but then goes on to illustrate how to use those features. It also discusses the key environments in which JavaScript runs.


Jan 30 2019

Book review: How brands grow by Byron Sharp

how_brands_growThe next book is another in my marketing theme How Brands Grow: What Marketers Don’t Know by Bryon Sharp. The core message of the book is that marketers have a lot of wrong ideas and empirical, scientific research can disabuse them of these notions, Sharp terms this new world “evidence-based marketing”.

I see a pattern in the form of the marketing books I have read: they both started with short form summaries of the main conclusions of the book. In Behavioural Marketing these were tweet sized chunks. In this book they are a set of laws: double jeopardy law, law of buyer moderation, natural monopoly law. The chapters discuss each of the laws in turn. The conclusion repeats these laws. It follows the scheme my PhD  supervisor taught me for academic presentation “tell them what you’re going to tell them, tell them, tell them what you told them”.

Sharp, who authors most of the chapters, works at the Ehrenberg-Bass Institute, perhaps it is following his own marketing advice but this seems to get mentioned in every chapter, several times.

The core of the laws is that much of the observed outcomes of brand performance really just come down to brand penetration (the share of the market that a brand has in terms of the number of customers and the frequency of purchase), and the essentially random behaviour of consumers. Loyalty to a brand is a bit of an apparition, brands maintain their position not because the same people buy from them repeatedly through loyalty but because consumers move from brand to brand somewhat at random but biased by the market share of a brand. So big brands gain and lose customers from sale to sale in greater numbers than small brands but as a proportion they do slightly better than small brands because an infrequent customer is more likely stumble on a big brand than a small one.

A second important feature is the distribution of buyer frequency. There are few frequent buyers of any brand, the shopper that buys Coca Cola 3 times a day, but there are many infrequent buyers – someone who buys Coca Cola a couple of times a year. Most brands have a distribution of consumers where the top 20% contribution at best half or so of the sales of the brand. This is rather less than the 80/20 Pareto law. It means that the long tail of infrequent buyers is important. Sharp is keen on citing the negative binomial distribution (NBD)-Dirichlet theory. It strikes me this isn’t a theory, it is a description of a distribution, the features of this distribution can be used to explain observed market behaviour.

Sharps conclusions on acquisition and retention are interesting, he argues that brands grow by acquisition rather than reduced retention. All brands lose some customers to their rivals at each purchase but acquisition and loss are generally proportional to the market share.

What surprised me was that even for brands with famous brand loyalty such as Apple, the degree to which “Apple buyers” buy other brands of computer is quite high i.e. 50% or so. And there aren’t really brand demographics, except in extreme cases such as rich people buying expensive items, and children watching children’s TV. There isn’t a “Ford buying demographic” and a “Renault demographic”. It isn’t even that there are generally customers committed to a particular price point, customers buying a premium brand are quite likely to buy a bargain brand as their next purchase. Niche brands turn out to be just a polite way of saying small.

Fundamental to all of this is that consumers care a whole lot less about brands, and their differentiating features, than you, the marketer, ever will. As consumers we just don’t care. And so the role of advertising is to shift the needle in terms of simple recognition. When it comes to my desire to buy a brown, sweet fizzy liquid to drink the special features of a particular brand are unimportant, the image a brand tries to project about itself is unimportant, the special demographic the brand tries to hit is unimportant. All that is important is that I remember the brand, the packaging and that it is on hand when I make my occasional decision to buy a brown, sweet fizzy liquid.

This seems to go against the idea of behavioural or targeted marketing, although perhaps the distinction is that the “bad” targeted marketing is based on demographics, age or gender, whilst the “good” targeted marketing is based on behaviour, abandoned baskets or opened emails.

I enjoyed this second foray into marketing, How Brands Grow is well-structured and relatively easy reading. I found the ideas it contained intriguing and the methodology is in tune with my background as a physical scientist.

Jan 20 2019

Book review: Hedy’s Folly by Richard Rhodes

Back to some history of technology with hedys_follyHedy’s Folly by Richard Rhodes. This book concerns the patent granted to Hedy Lamarr, Hollywood actress, and George Antheil, experimental musician, for the frequency hopping radio communications system. Originally it was intended to allow secure, jamming resistant communications between torpedoes and their control aircraft or ships, nowadays it is most notably the basis for Bluetooth and WiFi communications.

I’ve previously read Richard Rhodes “The Making of the Atomic Bomb”, which is a massive tome, Hedy’s Folly is a rather more modest affair. It provides some biographical material on Lamarr (born Hedwig Kiesler) and Antheil but only in as much as it leads to the patent of the title.

Hedy Lamarr was born in Austria in 1914, to a wealthy family – her father was banker who clearly cultivated her interest in how things worked. Following a brief career in European theatre and film she married Fritz Mandl in 1933. He was an arms manufacturer and one of the richest men in Austria. He didn’t want to see his wife continue her acting career. On the death of her father Lamarr resolved to leave her husband but in the interim she paid close attention to the technical discussions on armaments which she was party to. In all likelihood she was doing this throughout her marriage, despite his controlling nature Mandl clearly valued her opinions (even if he didn’t like them). Lamarr then moved to the States with Louis Mayer of MGM for whom was to make a number of films. In this milieu she met George Antheil.

Antheil in Trenton, New Jersey in 1900. He travelled to Europe in 1921 where he composed the Ballet Mécanique, originally intended as the score to a film it ended up twice the length of the film. As originally envisaged Ballet Mécanique required 16 player pianos and an aeroplane propeller – amongst many other sound making devices. Essentially Antheil vision was much in advance of what technology in the twenties and thirties could deliver. The player piano plays a part in the story. Player pianos were briefly popular as a way for everyone (who could afford one) to make music, they were automated pianos programmed using a paper roll with holes directing the music. The operator simply had to provide power and rhythm. They were supplanted by radio. The important feature was the ability to control sound automatically.

Antheil returned to the US, to Hollywood, in 1936 where he turned to writing film scores, his experimental music proving rather unpopular. It was here he met Hedy Lamarr.

The spirit of the Second World War in the US was that everyone would do what they could to help. Antheil had a sideline in writing about endocrinology, and made suggests on how to defeat the Nazis by this approach. Later in the war Hedy Lamarr was to do considerable work in encouraging Americans to buy government bonds to support the war effort, as well as volunteering at the Hollywood Canteen – entertainment for servicemen.

Lamarr was an inventor in her spare time, her background meant she knew the problems faced with torpedo guidance. So it was not unsurprising for her to work with Antheil on a frequency hopping patent for torpedo guidance. The central idea of the frequency hopping patent was to transmit radio instructions between controller and torpedo over a series of radio channels at different frequencies switching synchronously between channels. In the original patent the number of channels used is relatively small (less than 10), hops are relatively slow – of order minutes and were controlled by a player piano style roll.

The US Navy chose not to develop the patent, stating that the apparatus was too bulky. This seems to be a bit of a misunderstanding – the player piano inspiration was indeed quite bulky but could easily reduced in size using current technology. More likely was the fact that US torpedo performance at the beginning of the war was abysmal – 60% of torpedos experienced technical failure, so it was likely they had other priorities. 

Lamarr and Antheil’s patent on frequency hopping expired in 1959, the US military implemented several frequency hopping systems from the beginning of the sixties. As technology improved it evolved to so-called spread spectrum techniques. The difference between frequency hopping and spread spectrum is really just one of scale. These techniques finally became public in 1976.

Spread spectrum techniques eventually found important applications in Bluetooth and WiFi. Originally designed to be resistant to jamming – the deliberate use of noise to block signals – it is also resistant to unintentional noise. Furthermore it can be used with very low power transmissions so it can cohabit with other signals used for longer range applications and parts of the electromagnetic spectrum where there is a lot of noise.

Hedy Lamarr’s part in the development of frequency hopping is finally being recognised, and George Antheil’s more experimental music is finally being recognised too – technology has now reached the point where his original vision can finally be realised.

This is a fascinating little book, focused on one small invention with huge consequences. It isn’t a biography of Hedy Lamarr, and it isn’t a biography of her co-inventor George Antheil.   

Jan 19 2019

Book review: The Practical Guide to Modern Music Theory for Guitarists by Joseph Alexander

Continuing with the guitar theme here I reviewguitar_theory The Practical Guide to Modern Music Theory for Guitarists by Joseph Alexander. Reading the Beginner’s Course I felt I was missing out by not understanding why there were the notes there were and how they could be put together. The Beginner’s Course gave me enough knowledge to realise that generally songs were not just made by mashing a whole pile of notes together and hoping for the best.

My background is in physics, so I have very clear ideas as to what I consider to be a theory. Physics covers music somewhat indirectly, during training physicists are taught about “oscillations and waves” and “harmonic oscillators”. So to a degree I approach this book expecting to find a physics-like theory, music theory is not like physics theory.

The book is divided into two parts. The first part covers how musical scales are constructed, how chords are formed and chord progressions. The second part talks about each of the modes of the major scale, with fine names such as the Dorian, Lydian, Mixolydian and the Phrygian. Following some introductory material the second part of the book follows a regular pattern for each of this modes, so has the feeling of a reference section.

I found the first section jumped in a bit fast, I’ve not looked at musical scale notation for a very long time, and would have welcomed a bit more explanation. A guide to guitar tab notation would also fit well in here. The basics of both of these forms are straightforward enough but there are various symbols and conventions which are difficult to search for and could have been usefully collected here.

Indeed the existence of natural, sharp and flat notes is not explained. As I understand the natural notes A,B,C,D etc where discovered in antiquity to provide harmonious music. Although there are hints here that in the Western world we have all been trained to hear harmonious music in tunes composed from natural notes.

The natural notes represent musical sounds which have certain relationships in terms of frequency. The sharps and flats were added some time later based on a uniform division of the octave (a doubling of frequency) into 12 evenly spaced notes (in frequency). The notes on this scale fall approximately onto the natural notes but in addition provide some sharp and flat notes. The notes F flat and C flat do not exist which explains the irregular appearance of a piano keyboard and makes everything more complicated. The interval between a natural note and its sharp or flat is a semitone. The interval between two consecutive natural notes is a tone.

The C major scale comprises all the natural notes starting at C (CDEFGABAC), since natural notes are not evenly spaced in frequency this means that the steps between notes are not equal in size. No problem for a scale starting at C but if we form try to form a scale starting at a different natural note such as A (ABCDEFGA) then it sounds “wrong”, in fact this is a minor scale not a major one. To make a major scale we need to match the pattern in step sizes found in the C major scale which for A is (A, B, C♯, D, E, F♯, G♯). The non-uniform nature of the gaps between notes in the major scale makes the rules for forming scales very wordy.

I’m leaving it as an exercise for me to write Python code that constructs scales, this would help me see music theory as a more physical theory.

Chords are sets of three notes drawn from scale with the same spacing on the scale, so on the C major scale the C chord is formed of the first, third and fifth notes (CEG), similar we can make chords D (DFA) and E (EGB). Where there are whole tones between the first two notes in the chord is a a major chord, if there is only 1.5 tones then the chord is a minor chord. 

Early in the book Alexander makes reference to how the major scale is “too bright” for rock, this comment along with others later in the book discussing different modes and which forms of music they suit was intriguing to me but no expanded upon. Similarly with chord progressions (sequences of chords) there is clearly some theory as to moods that different chord progressions invoke but there’s no discussion of this in the book. This is where musical theory diverges from physical theories. 

Looking back I think I picked up this book too early. It feels like revision notes for someone taking a rather high level music examination. I’ve certainly learnt from it and I can see it as a useful reference in future but for me it raised more questions than provided answers.

Jan 13 2019

Book review: Justinguitar.com Beginner’s Course by Justin Sandercoe

This review is a bit of a departure for me, it is of beginners_courseJustinguitar.com Beginner’s Course by Justin Sandercoe.

I’m a big fan of book learning, so when I decided to learn how to play the guitar a book was the obvious place to start. To be honest I picked the justinguitar.com book largely because it was ring-bound, a quick search reveals many other options but envisaging how I would use the book a ring-bound version seemed to make sense.

It turns out this somewhat arbitrary method of selection has worked out quite well. The book is accompanied by a substantial website (https://www.justinguitar.com/), which includes free video versions of the lessons in this book, amongst much other, mainly video, material. The videos are typically less than 10 minutes long, which is ideal. Looking around similar video courses Justin Sandercoe is, by comparison, clearly a very good teacher. His videos are quite casual in their feel but focussed and well put together. There are also purely app based guitar course but that seemed a bit modern for my tastes.

The book is divided into 9 stages, in each stage new chords are introduced as well as associated techniques, such as rhythm patterns and in the later stages scales and fingerstyle picking. A key element of learning chords is “fingering”, which finger goes where.

I got on really well with the chord change aspect of each stage, you’re invited to record how many chord changes you can do in a minute – which is absolutely my thing! I have a spreadsheet recording how my pace has increased over time. I have made satisfying progress. I also feel somewhat triumphant that I can do apparently notorious F-barre chord although don’t ask me to change to and from any other chord at any great rate.

There is an associated songbook, each stage enables a few different songs. I haven’t made a great deal of use of this yet. I found each stage came with a list of 10 songs but I didn’t know which to focus on to improve my skills. Possibly the answer is “any of them”, choose the ones that appeal to your musical taste.

The emphasis is very much on the rhythm side of guitar playing which isn’t where crowd pleasing showing off lies. Sandercoe does have videos showing you how to play classic guitar riffs (like Smoke on the Water, Seven Nation Army, Creep) but these aren’t included in the book. I found these more motivating than the songbook.

It has taken me a couple of months to get through the first 6 stages of the book. I’ve jumped ahead for a few things – starting to play scales, experimenting with fingerstyle playing and playing a 12-bar blues shuffle. As it stands my chord change rate is a bit lower than the goal for the whole book and I’m not very good at strumming and changing chords, certainly not strumming anything but the simplest patterns.

Learning chords from the book works really well. I found learning strumming patterns required the CD sound tracks at the very least and really needed the video lessons, certainly for the more complex patterns.

Beginner’s Course includes listening exercises at each stage, I must admit I didn’t do well with these. I practiced them using an unrelated app which probably didn’t help – I felt I wasn’t making progress. The focus of the app was very much on the speed at which you could recognise chords rather than accuracy.

There’s a little bit of music theory included in this beginners course – simple stuff relating to where notes appear on the guitar fretboard but there’s no real discussion of how chords are constructed and the relevance of musical scales and chord progressions. I’ve looked elsewhere for this since I’m interested, I think Sandercoe actually introduces quite a lot of this material indirectly.

What I’ve really enjoyed in playing guitar has been managing to do a recognisable rendition of Seven Nation Army by The White Stripes within a couple of weeks, playing the 12-bar blues shuffle from the beginners course book, making a passable attempt at Creep by Radiohead. I think my next task is to hunt out the videos for songs that Sandercoe has done which appeal to me and give me motivation to practice some key skills. At the moment I have my eyes on Smells Like Teen Spirit (power chords), Jolene (finger style playing). Hey Joe (riffs), Thunderstruck (fast, simple riffs). It helps that these tracks will impress the girl in my life (Mrs H, aged the same as me).

This review is different from most of my book reviews, it is more about how this beginners course works for me than a review of the book in itself. Learning to play the guitar competently is the work of years, this book is a good start on the path.

Older posts «

» Newer posts