Wednesday, 27 July 2016

Zetters

In the Clerkenwell district of central London, there's a very up-market hotel called The Zetter. It's an odd and unique name for a hotel. There must be some history behind it.

When I was 16, I needed a weekend job to make some pocket money. The typical job was in a shop, but my mother had another idea. While my brother was small, she had worked on Sundays, checking football pools coupons at what was then one of the biggest pools outfits in Britain, Zetters in London. This paid a lot better than working in a shop, so it was obvious for me to try it.

Football pools are a uniquely British institution (though they have spread to some of the former dominions). The basic idea is very simple. Of the 55 or so matches played on a Saturday, the objective is to predict 8 which are draws, i.e. where the two teams have equal scores. The coupon is a grid, where each row is a game. In each column you put 8 crosses, and if those 8 matches happen to be draws, you win a big prize. There are secondary prizes if just 7 of them are draws. That's why it's called the Treble Chance - you get a first dividend for 8 draws, a second dividend for 7 draws and an away win, and a third dividend for 7 draws and a home win. You pay a fixed amount (a fraction of an old penny back then) for each line.

If you want to cover a lot of possibilities, writing them all out individually would be an impossible task. You can write more than 8 crosses in one column, and you win if any 8 of them are draws. This rapidly increases the cost - 10 crosses will cost for 45 lines, while 12 will cost for 495 lines, and 14 gives 3003. (Mathematically, this is the function nCr, where n is the number of crosses and r is the number of matches - 8 in this case). This was called a "full perm" (although mathematically it is a combination, not a permutation). There were various subterfuges for trying to cover more matches at lower cost - more on this later.

I duly applied for a job, and went up to London for a test. This was fairly simple, especially under my mother's tutelage. I passed, and started work the following Sunday, arriving at 9 am. It was a lonely and quiet journey - trains that were jam-packed with standing passengers during the week were deserted on Sunday morning. Only at Farringdon station, on the Circle Line, would you run into fellow checkers all hurrying in the same direction.

Football results were announced late on Saturday afternoon (and what a ritual that was), so checking the entries took place on Sunday. Now computers can do it, but then only humans could, armies of them at each of the pools companies still in business: Littlewoods, Vernons, Zetters, and some smaller ones.

Zetters had a large five-storey building just off Clerkenwell Green. Most of the floors were one gigantic open-plan work area, with the checkers sitting close together at long, narrow tables, with just enough room to work. The building had a very characteristic smell, of stale sweat and old paint. Smoking was (luckily for me) not permitted, I suppose because of the fire risk. Coupons were brought around in bundles of 35, held together with wire and a lead seal. The only aid we had to speed things up was a piece of thin card, with the draws marked on them in red. Simple though it was, most losing coupons could be disposed of in a few seconds.

Potential winners were a different matter. Any line that had 7 or more draws in it was a potential winner. If the entry was a simple one, it could be marked immediately as a winner, by putting a coloured sticker on the top of the coupon. Many cases required further checking later on, and in that case a different colour sticker was used. When a bundle was finished, after ten or fifteen minutes, it would have a little forest of coloured stickers on the top.

Security was taken very seriously. It would have been very easy to introduce a winning coupon on Sunday, already knowing Saturday's results, and it would be impossible to search everyone entering the building. Each bundle of coupons was punched through with a unique pattern, during the week before the results were known. It would have been near-impossible to reproduce this, even with an example in hand. It was permitted, though discouraged, to visit the toilet during checking time - but the time spent was strictly monitored, so you couldn't go and hide for long enough to try and sneak a coupon into the system.

It was very important not to miss a winner. Football pools work by taking the income for the week, taking off a (large) margin for costs and profit, and dividing the rest amongst the number of winners. A missed winner ate directly into the profit margin. Punters would get their winnings during the week. If someone didn't hear by the following weekend, they'd write in. Every Sunday there was a "walk of shame" where checkers who'd missed winners would be called up to the supervisor's desk in front of everyone. It was pretty much impossible not to miss the occasional small one, but there was a cash bonus system which meant it was certainly worth making an effort. If someone consistently missed winners, they'd be summarily fired and walked out of the building, but this was very rare.

Missing a really big winner would be a different matter. The size of the payouts depended directly on the number of draws that week. Typically there were ten or twelve of them, which meant there would be lots of winners and the individual payouts would be quite small. A week with only seven or eight draws would generate the legendary "pools winner" payouts of tens or hundreds of thousands of pounds. That would make a big dent in the profits.

Fortunately, the amount of work went up directly with the number of draws. If there were very few, checking was quickly done, so there was time for a second verification pass over all the non-winning coupons. Even then we would often finish early, getting to go home at 5 o'clock or earlier instead of the usual 6. If there were a lot of draws, the opposite was true. In that case, work would go on until 10, with voluntary and well-paid overtime. I was delighted when this happened. Occasionally they would even ask people to go in on Monday if they could - though I never could since I had to go to school.

There was a a one-hour break for lunch. Some people went to the pub, but I always took a packed lunch that my mother had prepared - a sandwich, usually corned beef, and a bottle of that uniquely British concoction, Tizer. As a result I have never been able to eat corned beef since - the association with the Zetters experience is just too strong. That would leave time for a short walk around the neighbourhood, uninspiring at the best of times and completely dead on a Sunday afternoon.

A new hire started as a "grade 4" checker. There were three further grades, which could be reached by taking a test, though not more often than every six months. I passed the grade 3 test, covering some slightly more complex bets. That meant slightly higher pay, but I left before I could move up to grade 2. As far as I could tell there was never any difference in the work for grade 3. There were very few grade 1 checkers, but when I was there one of them was a certain Alan Solomon, at the time a PhD student at one of the London colleges. Later he went on to found Dr Solomon's anti-virus product and make a lot of money.

Mid-afternoon, the job changed. All the coupons that had earlier been declared possible winners now had to be checked to see if they really were. Mainly, this was about "plans". As I explained above, the simple way to cover multiple matches without laboriously writing out hundreds of lines is a simple "perm". In addition, all of the pools companies and popular newspapers published books of plans. The idea was that you would mark, say, 16 matches, and if any 8 of them were draws, you'd get at least a second dividend (7 draws correct). Or maybe if 9 of them were draws. There were all sorts of associated guarantees. They didn't actually give any greater probability of winning, but they gave the punters the impression of having a better chance.

There were hundreds and hundreds of plans, but only a dozen or so were frequently used. Zetters had their own, and Littlewoods Plan 2 was very popular for some reason. Each source had its own thick book. To simplify the job, all possible winners using say Daily Express plans were put together into bundles and checked together. I've forgotten exactly how it was done.

One thing that intrigued me at the time and still does, nearly 50 years later, is just how these plans were contrived. There is a whole mathematical discipline about it, called variously the "lottery problem" or the "football pool problem", but I'm pretty sure the people who did the job didn't have PhDs in group theory. It turns out there is still no algorithmic way to construct the best way to cover say 16 matches, nor even to know the minimum number of lines required. A few years back I wrote a program, using what I thought was a fairly sophisticated algorithm. The results were close to the published plans, but not as good as what was undoubtedly done by some old guy with a fag hanging out of his mouth, using no more than squared paper, a pencil and eraser. There is no literature on the subject, so it must remain a mystery.

There were other pools besides the Treble Chance, though few people did them. But something was needed to fill up the back of the coupon, so there was the Twelve Results, the Eight Homes, and others I've forgotten. Each of these had its own special checking technique. A few entries, maybe one in a hundred, were beyond the ability of a normal grade 4 checker. There was yet another coloured ticket, buff pink and marked "FC", which meant "further checking" - i.e. "this is too hard for me". I almost never used them, preferring the challenge of figuring out something like a no-consecutive perm, but there were checkers who put them on any but the simplest of entries. Occasionally someone would get in trouble for it. But since there was a productivity bonus, for checking an above average number of coupons, it was worth trying it on.

Zetters carried on the pools business long after my 18 month stint there. But the arrival of the National Lottery in the 90s was the beginning of the end. The prizes were a lot bigger and absolutely no skill was required. Zetters diversified into other gambling businesses and sold their pools activity in 2002. They didn't need a huge building full of checkers every Sunday any more. The building was purchased and converted to a luxury hotel. As you will surely have guessed, this explains the unusual name of the Zetter Hotel.


Sunday, 17 July 2016

Pensioners' Pals

My parents moved to my childhood home a couple of years before I was born, to a brand-new house on a brand-new estate just east of London. The London County Council (LCC) - predecessor to today's Greater London Authority - had an urgent program after the War to replace all the bombed-out housing in inner London. They embarked on a huge project,  building numerous estates around London such as our own Harold Hill, which was the largest. The new houses were luxurious compared to the Victorian slums they replaced, with modern conveniences like running hot water and even baths - despite the assertion by a Tory MP at the time that all the working classes would do was store coal in them.

These new estates included special provision for older people - Old Age Pensioners as they were called then, women over 60 and men over 65 (not that there were many of the latter). At the end of many of the terraces of houses were little bungalows with one bedroom, laid out for the mobility challenged, as well as what would now be called sheltered housing - and in the 17th century would have been called almshouses.

Part of the community support for the elderly was an organisation called the Pensioners' Pals, a voluntary effort to help the old people in various ways - visiting, doing shopping and odd jobs, and arranging the occasional social event. This was important because the whole estate was made up of people who had been ripped from their inner London roots, and didn't necessarily have family living nearby.

I'm not sure why my parents decided to get involved with this group, but they did. By the time I was old enough to remember anything, they were part of the leadership. My Dad loved the social events, and my Mum has naturally organised anything that moves for her whole life, so it made sense. I was only a small child, but for some reason these activities made a big impression and even now I remember a lot of it.

My Mum had "adopted" two of the old ladies. They lived in adjacent bungalows, a ten minute walk from our house. One, Miss Simpson (I genuinely don't think she had a first name), was barely older than I am now, yet she was without any doubt old. She wore old-person's clothes, she moved like an old lady - everything about her said old. It's trite to say "60 is the new 40", but when I think back to these old dears, it is absolutely true. In the 1950s, once you passed 60 you were definitively old. She was also a spinster. That's a word you never hear now, meaning a woman who has never married. It has a certain connotation, of primness and unworldliness, which exactly suited our Miss Simpson.

Our other adoptee was completely different. She was universally called Grandma. I don't think she had any actual names at all. She must have been close to 80, which back then was positively ancient, but she was still pretty active. She had a huge family who were always visiting her, and lived surrounded by clutter in her tiny house. Very clearly she had never been a spinster.

We would visit them once a week, always taking some little treat, making the trek up the hill. On one occasion I was off school sick, and I got into trouble with the school truant inspector because I was admiring his car, parked in the street outside - of course I had no idea who it belonged to. It was something very unusual, a very sleek looking royal blue French Panhard at a time when 95% of cars in Britain were British.

Then there were the social events. Maybe a couple of times a year, a hall would be booked for the evening, a band would be engaged, and things were all set for a re-enactment of the first decade of the 20th century. "Our" pensioners were typically born in the 1880s, and would have been in the full flush of their youth in the Edwardian era (1901-1910). No television, no radio, no cinema - the entertainment of the masses was the Music Hall, a kind of popular theatre with singers, dancers and comedians. And then there were dances, to the popular tunes of the day, the girls carefully chaperoned. The Pensioners' Pals' socials were an attempt to re-create some of this.

I still remember the words to those old songs - "Daisy, Daisy", "It's a Long Way to Tipperary" (from the First World War, that one) and so on. This was brought back to me forcefully when I recently visited my mother in the home where she now lives. They had an entertainer playing old songs, and I could sing along with all of them!

And then there was the greatest of them all, "Knees Up Mother Brown", a vulgar, raucous dancing song where everyone links arms and rushes in and out of a circle. What an excuse for some "accidental" groping back in those prim and proper days. Even now in England a "knees up" is a synonym for an unrestrained, noisy evening.

For some reason these events attracted all kinds of local notables. Our family doctor was often there, drinking away his sorrows - he was well known to be fond of a tipple or three. My father once said to him, "Good evening, Doctor." He replied, "I'm not a doctor tonight, not a doctor." With hindsight there must have been a lot of feeling behind that.

The mayor of Romford showed up from time to time, as well. He had a very grand car for the time, an Armstrong Siddeley - one of the many long-disappeared British marques. I think I even got a ride in it once.

The music for these events was provided by a Mr Button. He ran a radio repair shop, and brought along a gramophone to provide music when the band was having a rest. My mother must somehow have stayed in touch with him, because 40 years later when he died, I inherited his long-obsolete collection of valves (vacuum tubes) - I still have them in my garage.

Then there were the management meetings for the organisation. Along with my parents, there was a childless couple, Mr and Mrs Clark - he was the Treasurer. He had a very flat northern accent, something strange to me back then. Never an adventurous man, his favourite observation was "This is a time for consolidation" - in other words, doing nothing. Several years later, when my Dad had learned to drive, they acquired a car, an awful old pre-war Austin in terrible condition. They insisted on taking us out for the day in it. My Dad drove for some of the time, and afterwards said it was the most terrifying drive of his life. That was before Britain introduced the "MOT test", a way of weeding out the most dangerous of these old wrecks. I doubt that their car survived its first encounter with the test.

My memories of the Pensioners' Pals all stop when I was about six or seven. I don't know what happened, whether my parents just dropped out of it, or whether the whole thing ground to a halt. They didn't lose all contact though. One of the biggest surprises was Miss Simpson, the old spinster who lived in the bungalow, who got married. Approaching 70, she met a widower and they set up home together in Dagenham, a bus ride away from us. We went there to see them once. My Dad's observation was that her new husband had probably got rather more than he bargained for.

Oddly the name came back to life when I was a teenager, when I heard that some of the girls at school - we must all have been about 16 or 17 - were involved in a new incarnation of the Pensioners' Pals. But I doubt if they ever had concerts where all the old dears sung "Daisy, Daisy".

Tuesday, 14 June 2016

Telex - and me

A Model 7 machine with its operator, 1959
Before email, before fax, there was a way of sending written messages reliably and securely between distant offices. It was called Telex. It worked much like the telephone, there were numbers and exchanges (central offices), and you called whoever you wanted, anywhere in the world, to send them a message. Instead of a telephone, you had a teleprinter. As you typed, your message would appear by magic on the distant machine also. You could even hold a conversation, taking it in turn to type messages to each other on the same connection. The Telex network was at the heart of banking, shipping, trucking, insurance and many other industries.

The teleprinter was independently invented by several organisations in the early 1920s. Originally they were connected together in pairs, one at head office and one in a branch. The limitations of this are obvious, and a switched network allowing anyone to talk to anyone else was an obvious next step. The first public Telex network in the world opened in Germany in 1933. It really prospered in the 1950s. Only recently, with first fax, then various computer network technologies, has it been eclipsed. The UK network closed in 2008.

When I was 16, like all students I wanted to earn some money during the school holidays. I could type well, thanks to the typewriters my mother had at home when I was small. One summer I worked as a typist, but my mother's advice was that there was more money to be made as a Telex operator. Back then this was considered a special skill - a company wouldn't expect a normal typist or secretary to be capable of it. Telephonists were just the same, even a small office would have a dedicated telephone operator at the company switchboard. When I started work at DEC in 1974, we had three of them for an office of maybe 200 people.

There were agencies that specialised in this kind of staff. I chose one called "Three T's" - for telephone, telex and... no idea, probably not telegraph though. I got in touch with them, and went along for an interview.

My mother's office had a Telex - though no operator since my mother took care of it herself. Even the boss knew how to work the machine there. It would have been smart to have spent a couple of hours using it before I went for the interview. But I didn't. So when they sat me down in front of their brand new Post Office Model 15 Telex machine, it was quite literally the first time I'd ever set eyes on one. This wasn't really very smart, but using my mother's description of how it worked I was able to figure it out in real time sitting in front of the machine. I even got complimented on how well I knew the machine!

So that was it, my career as a telex operator was launched. The next day I was working at one of the big investment banks somewhere in the City. They were a real heavy duty Telex user, with a bank of half a dozen machines, and operators to match. Some of the machines were used for live traffic, while others were used to prepare and verify messages on paper tape. Each message was a financial transaction, sometimes involving truly vast amounts of money, so a lot of attention was paid to getting it right.

All of the permanent staff were female. This was nearly always the case, though occasionally I'd come across an ex-military guy especially in the banks. A lot of the ladies had been trained during World War II, so by now were of a certain age. At one place I overheard two of them grumbling about the new generation of machines: "Oh, they're trying to make it so any old typist can use a Telex, well we know that's not possible, it needs special training, that's what it needs." And so on and so on.

The WWII era machines did require a bit of special understanding. There were still quite a few of them around in 1969, though they were disappearing. They were originally designed in 1931. They had a hammer green enamel finish and a very stark external design, with no concession to aesthetics. Under the cover was a massive electric motor and equally substantial mechanical parts, whose job was to convert faint electrical pulses into the position of a typewheel.

Keystrokes were converted to the Baudot Code for transmission. This has only five bits per character. By the time necessary control characters like line-feed are included, there are only 26 possible characters - not entirely coincidentally, the number of letters in the alphabet. To include numerals and punctuation required shift characters. If you pressed the key marked with W and 2, what actually got printed (both locally and remotely) depended on whether you had last pressed the letter-shift or figure-shift key. The operator had to remember this. She (usually) also had to pace the typing speed exactly to the mechanics of the machine. If you tried to type too fast, letters went missing. But if you went too slowly, you wasted time and on the Telex network, time was very much money.

There was another version of the same machine that had a paper tape reader and punch, so you could prepare your message without connecting, check it for accuracy, and then send it at the full speed of the network (about 7 characters/second).

A collection of Model 15 machines
The newer machines, called the Model 15, were much more modern, with a smooth grey finish and black plastic keys. They all had paper tape readers and punches. They had a four-row keyboard, like a typewriter. You still had to select letter or figure shift, as appropriate, but the inapplicable keys were physically blocked, so you wouldn't end up sending gibberish. I'm not sure that a regular typist could use one without a bit of training, but they were a lot less daunting than the old green ones.

Both types had a separate box for managing the connection to the Telex network. This had a dial, and several buttons to do the equivalent of picking up the phone and hanging up. It was a good size, well over a foot long and weighing about 15 kilos. Inside it was packed with relays and other signalling equipment.

One of the great advantages of Telex was security. When you made a connection, you could send a special code called "who are you" (or WRU) which triggered a mechanism in the remote machine to send a unique preconfigured response, called the "answerback". You could also send your own, by pressing a key marked "here is". Once you'd been through this exchange, each end knew with certainty who it was talking to. Hence Telex could be safely used for large financial transactions and other expensive commitments like sending a giant container ship to the other side of the world.

A Model 7 with paper tape, revealing its insides and showing
 the easily-blocked "here-is" key just above the keyboard,
slightly to the left.
At least, that's what everyone believed. The truth is, if you knew what you were doing, it wasn't secure at all. It was very easy to defeat the answerback mechanism. On the Model 7, all you needed was a pencil. When the machine received the WRU signal, the Here-Is key, perched awkwardly above the keyboard, dropped down to start sending the signal. If you wedged a pencil under it, you were then free to type whatever you wanted. On the Model 15 it took a little more mechanical ingenuity, but it could certainly be done, a very tiny adjustment inside the cover which could as quickly be restored. Whether anyone took advantage of this to commit fraud, I have no idea (honest).

How did I know about this? Whereas the banks ran their Telex machines flat out, there were several places I worked where there was hardly any traffic. One in particular was a timber merchant somewhere in East London, maybe Hackney. I doubt that there were even half a dozen messages a day. No doubt for security, the machine and its operator were in a closed, windowless office. There was plenty of time for a mechanically curious youngster, fascinated by how these machines worked, to investigate. It was at this place that I stripped a Model 7 down to its component assemblies, discovering all its inner secrets. I'm sure this was a serious infringement of the Post Office regulations, but if anyone had asked I would have said it had jammed and I just happened to know how to unjam it. Nobody would have been any the wiser. Luckily no messages tried to come in while I had the machine in pieces.

Some banks had their own dedicated international circuits. I worked at one that had its own dedicated circuit to New York, which must have cost a fortune. But to save money, it had some electromechanical trickery that meant it ran at a quarter of the normal speed. The Post Office sold the other three quarters of the circuit to other customers. It was odd to watch it ticking away in slow motion. What was really impressive though was one of the operators - unusually, a man - who could type at exactly the right speed, just less than two characters per second, to match the line speed. This being the 1960s, he did it with a lit cigarette hanging out of the corner of his mouth.

I did the Telex gig for a couple of summers, as well as some of the shorter holidays. I never told the agency that the first time I ever saw a Telex machine was when I walked into their office. But it didn't seem to matter, because for years afterwards, long after I had my degree and was working as a software engineer for far more money than 3Ts could ever hope to pay, they would get in touch with me every summer and ask whether by any chance I was free to go and replace a holidaying Telex operator.

Tuesday, 7 June 2016

The Rag Trade

After the War (which is to say in 1945), my Dad got a job in a London shop selling "trimmings". It sounds like something unsavoury from the butchery trade, but actually it means everything used in making clothes except the cloth - cotton, buttons, zips, elastic, linings and interlinings, and a host of other things most people don't even realise exist. For fifteen years he would take the train to London in the morning, to the shop on Old Street just north of the City and close to the sweatshops of Islington and Hoxton.

Then when I was about eight, he returned from our ritual week's holiday with my grandmother in Dovercourt to be told, "Sorry Reg, business isn't good, I'm going to have to let you go." And that was that, no employment protection then. Luckily my mother worked, part-time, but we had a typical working class hand-to-mouth existence and this was a disaster.

My Dad had few really sellable skills, so finding another job wasn't easy. Like nearly all of his generation he left school at 14. After a few false starts, he was lucky to find someone else in the same business who was willing to pay for him to learn to drive, for a job as a combined salesman and delivery driver.

The firm had the very British name of "Shepperton's". But the owners were actually a Jewish couple called Ettinger, refugees from Eastern Europe in the 1930s. Why Shepperton? They'd seen it on a map somewhere and thought it would be better than a Jewish name, in the bigotted English society of the 1950s. Though I'm not sure why, because practically all of their customers were Jewish too - the clothing trade, or "rag trade" as the insiders called it, was entirely Jewish then.

Soon my Dad had a bright orange Minivan to drive home every night. The routine was simple: bring the van home at night full of that day's orders, drive up to London the following morning dropping the orders off to all the customers in Essex and East London, while taking orders for the next day. He would arrive at Shepperton's in time for a late lunch, then drive round the West End taking orders and making deliveries until 4 or so, when it was time to stock up for the drive home.

The van was a blaze of colour. The sides of all their delivery vans were covered in the logos of the products they sold, long-forgotten names like Lightning Zips - sadly, I'm sure there is no picture anywhere. It took a skilled signwriter several days to prepare each one. My Dad had a deal that as long as he paid for petrol, he could use the van at evenings and weekends - which was good, because we certainly couldn't afford a family car. We had many outings in that and later vans, my brother and I sprawled awkwardly in the flat load space at the back. One early trip I remember was to a farm in the depths of the Essex countryside to get my first and only hamster, Nibs. (I have no idea why I wanted a hamster. I don't think he lasted long).

When I was a teenager, he would sometimes take me along for the day during the school holidays. So it was that I got see his daily routine.

The first call was close to our house, at the end of a muddy track by the railway line. Then we would proceed, never more than two or three miles at a time, stopping at one little clothing factory after another. Everywhere my Dad was welcomed like family, offered cups of tea, taken into back rooms to meet someone new. He was a natural salesman, it's just a shame he never sold anything you could really make money from!

He was a natural raconteur and a brilliant stand-up comedian, though the only time he did that was if we went to that uniquely British institution, the holiday camp, for our summer holidays. He had a huge collection of jokes, which he was always happy to trade for new ones with his customers. These were all Jewish, who seem to be the biggest fans of gently self-deprecatory Jewish jokes, so his collection of those was especially vast. The factories were tiny - the biggest ones had maybe 20 or 30 employees. They have all long since disappeared, replaced by giant sweatshops in Vietnam and Bangladesh.

One of his daily treats was a slice of toast and butter with a cup of strong British tea. He had an exclusive selection of cafes in East London, chosen for the quality of their bread (it had to be the real thing, cut in thick slices from an actual loaf - and under no circumstances sliced bread), the generosity of their butter, and the strength of their tea.  I still remember stopping at one of these places for elevenses, and the sensation of the melting butter oozing from the toast into my mouth. Strong, sweet tea, on the other hand, has never really been my thing. But then I didn't live through the Second World War.

Eventually we would get to Shepperton's, just in time for a late lunch. They had a shop (though you couldn't just go in and buy stuff) on Hampstead Road, close to Euston Station. It's an area that has changed beyond all recognition. There is no trace of Shepperton's, nor of Pat's, the seriously greasy  spoon cafe next door - of which more in a moment. A few steps away was Laurence Corner, the famous military surplus store where, supposedly, the Beatles got the inspiration for the uniforms on the cover of Sergeant Pepper's. The shop itself was barely-organised chaos, with packages of zips and buttons all over the place.

First stop was Pat's Cafe for lunch, something seriously greasy like sausages, bacon, fried eggs, and fried bread dripping with grease. My Dad was never overweight until long after he retired, but I have no idea how, considering everything he ate while he was working. He was (again) a much favoured customer, and would always disappear into the kitchen for a long chat with the eponymous Pat and the kitchen staff. The other staff at Shepperton's complained that after lunch, he smelled so much of kitchen fat that they couldn't go near him.

The afternoon was very different, driving round the West End and the more squalid areas to the north like Camden Town and Kilburn - this was long before gentrification had been invented. I was fascinated by the London bus system so I was very happy to sit in the van while my Dad exchanged jokes with his friends inside, jotting down the buses I'd seen and their destinations in my little red notebook. (I wonder whatever happened to those notebooks?)

Sometimes I'd go inside with him. I remember one place where they made fabric-covered buttons. A dressmaker would order a gross of buttons for a particular design. Everything was done in dozens and gross - a dozen dozen  or 144 - and occasionally a great gross, a dozen gross or 1728. Never 10, 100 or 1000. He'd supply the fabric and specify the size, and this tiny specialized place would assemble the buttons out of metal blanks. I was allowed to make one myself, cutting the material carefully to size, placing all the components in the press, then trimming the edges to make a neat fabric-covered button. I was very proud of my button and kept it for a long time.

Around 4, we'd go back to HQ to load up the van for the morning's deliveries. There's only one person there I remember, the first openly gay person I ever met. He was called Derek. He made sure you could not miss him. It was still illegal in Britain until 1967, so this was either just before or just after. Either way it didn't seem to bother anyone.

Then, the van loaded up with long rolls of interlining (the stiff material that goes between the dress fabric and the lining, to give shape and rigidity), boxes of buttons and zips, and various other odds and ends, it was time to set off home. The orange minivan didn't last long, and my memories are mostly of a series of vans based on the Ford 105E Anglia (the one with the odd sloping-backwards rear window). These were bought to the absolute minimum spec. They didn't have a heater, and they didn't even have a passenger seat. The passenger (me, in this case) sat on the ledge at the front of the load-space, with no back support and absolutely no security. It is unimaginable nowadays.

My Dad has his private route across London, eventually joining the A12 out to Romford. At the time I never understood it, but three decades later when I bought my flat in London I recreated a very similar route, which by using obscure back streets shaves probably 30 minutes off the time it takes to get from Kensington to Leytonstone. Once we reached the "arterial road" (the name given to it when it was built in the 1930s, as an example of high-tech high-speed road design at its finest), we trundled along at a stately 50 mph, close the maximum speed for these minimally-engined vans.

We would arrive home in Romford at about 6.30, in plenty of time for dinner. Strangely, when my Dad was on his own, he'd get home an hour or so later. That corresponded to the time he spent in the bookmaker's, picking up his winnings from the horses (if any) and no doubt sharing jokes with his mates there.

Monday, 6 June 2016

Just Popping out for the Paraffin

...and other excuses from a just barely dissolute life.


My Dad was as close to a blameless existence as any human being ever can be. He didn't drink, except an occasional half of cider in the summer. He didn't have a shred of violence in him, and he certainly wasn't a womanizer. He smoked, but so did everybody then. He had just one small vice: the horses. Every Saturday he would study the form, place a few bets, watch the races on the television in the afternoon, and if he got lucky, he'd go and collect his winnings.

We lived very close to our local shops. It was only a two minute walk, and the bookmaker's (the bookie, or "Ernie's") was one of the closest. It was nothing to pop over there three or four times during the course of the day, as necessary. There was just one problem: my mother. She absolutely did not approve of him betting on the horses, though heaven knows it was a small enough vice and his bets were tiny - generally a shilling (£0.05) each.

So he couldn't just say, "I'm just popping over to Ernie's, back in fifteen minutes," and get the reply, "OK, see you soon". Instead he had to make a just-barely-plausible excuse.

Our house, like all English houses of its vintage, had no central heating. There was a coal fire, latterly replaced by a gas fire, for the living room. The kitchen was supposed to be kept warm by cooking, and in the bedrooms... you were supposed to be in bed anyway. I remember scraping ice from the inside of the windows during the winter. So in the kitchen and the bathroom, we had portable paraffin heaters. The ones we had were cylindrical, a couple of feet high and about a foot across, with a tank holding a gallon or so of fuel at the bottom. They needed constant adjustment and frequent maintenance, but no matter what you did, they stank. The very first thing to do on getting up on a winter's morning was to light the heater. By breakfast time the room would be just barely warm, and filled with a miasma of fumes and unburned paraffin.

For those who've never seen it, paraffin is a clear, greasy inflammable oil, a bit like diesel. Back then every house and workshop had paraffin heaters, and every hardware store had a big tank of the stuff, which they would sell by the gallon. To keep our heaters running, it was a weekly chore to go round with a five-gallon plastic container, returning with it filled. I occasionally did it myself, as a teenager, and I remember the weight lugging it home - 42 pounds, or about 18 kg, if my arithmetic is right (it weighs the same as jet fuel - these were English gallons, remember).

One of my Dad's excuses was this regular excursion, just before lunch, when he would place his bets. "I'm just popping out for the paraffin," he'd say, and he'd walk off up the three steps to the street, wrapped up tight against the chilly winter weather, the empty paraffin can in his hand.

The trip to the hardware store, waiting to be served, and coming home again, took about a ten or fifteen minutes. At least it did when I did it. My Dad took an hour or more, because, of course, most of the time was spent at Ernie's. I think it was as much a social occasion as anything else. He was a very social man, especially with people he knew but not all that well. He was a salesman by trade, and I think quite good at it although there wasn't much money to be made selling haberdashery.

That was the second trip of the day. The first, just after breakfast, was announced as "I'm just going to pay the papers." Like everyone back then, we had a newspaper delivered every day - the Daily Express, a favourite of the right-leaning working class. On Sundays there was the Sunday Express and - naturally - the News of the World, a titillating scandal sheet and favourite of the working classes right up to its own scandalous end a few years back, and the home of the phrase "then I made an excuse and left."

The papers were supplied on credit, and once a week there was a visit to the local newsagent (actually we had three) to stand in a long line of people waiting to pay their account. It was another fifteen minute round trip, which took my Dad an hour. I think his first trip was to study the form.

The afternoon was spent watching the races. I can still remember the noise and rhythm of the commentary, the stock phrases like "and now - now he's coming up on the inside! - and it's Bright Blaze, Bright Blaze by just a short head". Actually I hated it, and would hide away in the kitchen or my bedroom while it was going on, but like the football results later in the afternoon it was an inescapable part of every single Saturday. After the races there just might be some winnings to collect. In that case there would be some other domestic excuse for an outing - some cleaning product that needed to be replenished from the supermarket round the corner, another five minute trip that would take an hour.

Of course my mother knew perfectly well what was going on. In later years I learned that it annoyed her intensely, though I'm not really sure that honesty would have been any better a policy.

It wasn't only on Saturdays that things took longer than they needed. My Dad had a job that combined selling with delivering the things that he'd sold, and every evening he would drive a little delivery van home from the firm's base in the West End, full of odds and ends to be transformed into clothing in the sweatshops of East London. Occasionally in the school holidays he would take me with him. We'd leave just after five, and be home by 6.30 or so. Yet when my Dad was on his own he was never home until 7.30, an hour later. It's not hard to guess where the time went.

It was a blameless life, but still it needed a supply of excuses.

Wednesday, 11 May 2016

Grisou RIP

Grisou at his most felinely handsome. He always looked a bit of a rogue.
Our beloved Grisou is no longer with us. He went for his evening stroll around 7 on Sunday evening, and didn't come back. The following evening we heard that he'd been hit by a car on a busy road a long way from the house, far further than we ever thought he roamed, where we found his poor dead body.

Grisou's first day at our house
He was just barely a year old. By an awful coincidence, he was almost exactly the same age as Missy's brother Hercule was when he was also killed by a car, three years ago - thirteen months and a few days. He'd been with us less than a year, we were looking forward to celebrating the anniversary of his arrival on 21st May. That will never happen.

Poor Grisou. Poor, poor Grisou. He was a cat with an incredible character. His morning and evening strolls took him round our whole neighbourhood - and much further than we ever thought. Everyone knew him, he was a regular visitor to every garden.

But let's start at the beginning. After Hercule died, it seemed a good idea to get a second cat to keep Missy company. Whether cats need or want company is a big unknown, though she seemed very happy to be with Grisou once they got used to each other.

A good idea, but we worried how Missy would react at first. She is a very timid cat - unlike Grisou, probably no more than a couple of our neighbours even know she exists. As a result, it took us two years to act on the idea.

Isabelle saw a litter of kittens in the window of our local vet's office. Four were black, and two were grey. We went and held them, tiny tiny kittens that fit in the palm of my hand. We chose Grisou, rather than the other grey one, because even at just a few weeks old he seemed to have more character. He was tiny, about 800 grams (1.5 pounds), and liked to stand on my shoulder. For the first few days he hadn't quite mastered his hind legs, when he jumped he would land on his forepaws then not know what to do with the rest, landing in a tangled heap. He soon figured that out though.

The introduction to Missy was very tricky and painful. We kept Grisou in our spare bedroom, but he was desperate to escape - it was a challenge to open the door without him zooming down the corridor into the rest of the house. Missy knew he was there and would sniff at the door, miaowing. Our house has an enclosed atrium, open to the sky but not to the outside world. We would put Grisou in there and let Missy see him. Even though he was just a tiny kitten, she was frightened of him. She would stare at him for a minute or two, then retreat to the garden with her ears flattened.

Why Grisou? It's a French word, though nothing to do with cats - it means "firedamp" (methane) - but "gris" means grey. And it rhymes with "bizou", meaning kiss. He was a uniform medium grey all over, from his nose to his tail, with just very faint bands on his tail. His actual nose was a different shade of grey, which seemed to change all the time. He was beautiful.

Missy became more and more reluctant to enter the house at all until finally one morning I realised she hadn't even been inside to eat. I rushed to put her food outside and she ate with enthusiasm. She continued to eat outside for about three months. Very gradually she started to come back indoors, and to allow Grisou to get closer to her. He was full of enthusiasm and would chase after her, until eventually she would jump onto the fence leaving Grisou on the ground puzzled, thinking "How on earth did she do that?"

Eventually they settled down to a sort of clawed truce. They would play fight and hiss (well, Missy hissed) and chase each other around the garden or the house, but they never hurt each other (though Grisou would often have a bit of Missy's long fur stuck in his teeth). Then they'd settle down and snooze close enough to touch each other.

As soon as Grisou was big enough to go out, he started roaming the whole neighbourhood. He was a true "people's cat". We were shocked when, chatting with a group of our neighbours, we discovered they all knew him as a friend, a regular visitor to their gardens. We often saw him crossing our street, or just sitting at the side of the road - fortunately it's a very quiet street and nobody drives fast. One day we caught him teasing a dog who has a rather poor history with cats - an extremely bad idea, even though the dog was soundly tied to a tree. That was when I said, "It'll be a miracle if he lives to his first birthday." Well, he did, but only just, and not to his first anniversary with us.

Late last summer, we started keeping them both indoors at night. Partly this was just for my own sleep and sanity, since if I woke up in the night and one cat wasn't there I wouldn't be able to sleep. And also there were coyotes in the area, attacking and eating pet cats. It worked very well all through the winter. Both cats would be indoors by 8pm or so, we'd close the catflap, and have the security of knowing they were safe with us. They didn't seem to mind.

As the days got longer in spring, though, it got harder, and Grisou often wouldn't come home until bedtime. We knew he was touring the neighbourhood, though we had no idea how far we went. The furthest I ever saw him was half way to the main road - about 300 feet from the house. I really hoped that was the furthest he went - little did I know.

Whenever we travelled, we had a friend come by twice a day to feed Grisou and Missy and give them a cuddle. At first we wanted them to be indoors the whole time. We left the cat flap in its "entrance only" position, in case one got out by mistake. Then we had reports that they were both in the garden. We didn't know how until our friend saw Grisou lay on his back under the door, stick a claw into the plastic frame and pull it open inwards, then squirm out from underneath. We realised it was hopeless, so when we were away they had the freedom to come and go as they pleased.

We were away for a couple of weeks in March and April. After we got back, Grisou was out until the small hours a couple of times. He was quite a creature of habit. He would snooze indoors or close to the house all day, usually on his favourite footstool in our living room (where now there is nothing but a desperately sad cat-free space). Around 5 he'd start grooming, by 6 he'd be outside, and around 7 he'd disappear for the rest of the evening. Usually he came back before bedtime for a snack, and we'd close the cat flap. Then one morning recently we found that he'd figured out how to open it! He'd moved the heavy carton from in front of it then, most surprising, moved the stiff plastic catch that held it shut, opened it and escaped. I caught him trying to do the same thing late one night, after he'd popped in for a quick snack, so I put some heavy furniture in front of it. He was furious and spent the next hour complaining loudly. He almost never miaowed, only when he was cross. The following night, he simply didn't come in at all until about 3am.

Usually, he eventually accepted being shut in, and then he would settle down for an initial nap at the very back of a closet in our bedroom, almost completely invisible. At some point in the small hours he and Missy would have a ritual exchange of views, and then he'd settle down in his second night snoozing spot, on a cushion under some furniture by a window. He'd stay there often until 10am or later. Then he'd go out for his morning stroll, until 12 or so when he'd settle on the footstool for his daytime snooze again.

Sometimes he'd have a snooze at the top of the cat tree we got when Missy and Hercule were kittens. He'd leap to the top, his six kilos (13 pounds) very nearly toppling the whole thing, then curl up in the small space there. He never quite fitted, there was always a paw dangling out and his tail.

A few days before his birthday we had some sushi and gave him some of the tuna. He loved it. So his birthday treat was some sashimi-grade tuna from the Japanese supermarket. He loved that even more. His normal daily diet was dry cat food, with an evening treat of tinned tuna, and a morning treat of wet cat food. Missy too, though as far as we can tell she mostly only eats the dry food.

Some books say you should give your cats separate feeding places. So we did, we set up one in each of two bathrooms. The theory - our theory - was that one was for Missy and the other for Grisou. But they didn't take that seriously. For the last few days he was alive, they both ate "chez Missy la chatte", cleaning it out every night, while Grisou's place remained untouched.

Missy and Grisou in their respective snoozing places
A few days ago I came home early from work. It was so nice sitting in the garden in the evening sunshine with two cats, sometimes sitting quietly, sometimes chasing each other crazily around the garden, from one end to the other and back again. On Saturday afternoon I sat in my armchair, Grisou snoozing on the footstool and Missy on her favourite dining chair, both within reach. It was soporific, I wrote "There are few things less inducing to getting on and doing things than sitting between two snoozing cats". Perhaps I shouldn't have tempted fate.

Last Sunday, Isabelle returned from a trip to Europe. Both cats were waiting for her when we returned from the airport. Grisou seemed really happy to see her, demanding a cuddle and following her round the garden. Then in the evening he went off for his usual tour. The last time I saw him - alive - I remember he was licking delicately between the toes of his hind paws. He was so beautiful, so supremely feline.

He didn't come home before bedtime. I woke up at four, still no Grisou. I didn't get back to sleep. At 6 I looked everywhere for him, driving round all the local small streets. At lunchtime we put flyers in nearly 100 letterboxes, including places we thought were far outside his range. We still hoped, of course, that he'd show up - maybe after being shut in somewhere, or maybe deciding to get food and shelter in one of his many adoptive homes. We were sure of one thing - we'd looked everywhere and not seen a body by the road.

But were wrong. In the evening I got a text in response to the flyer, from someone who had found him dead in the main road. She'd called the police who had moved his body to the median where we hadn't seen it. So we walked down there, and there was his poor dead body, intact. You could almost believe he was just sleeping. But he wasn't. He was dead. And that is final. We carried his poor body home, to touch him one last time.

We used to speak French with him. When he showed up we'd say "il y un Grisou" (there's a Grisou) or "on a un Grisou" (we've got a Grisou). And I still say it to myself. But now it's not true, and it never will be, never again. And my keyboard is wet with tears.

The last ever photo of Grisou, the day before he died

Tuesday, 3 May 2016

The Importance of Virtual Destructors

Our system had a memory leak. It wasn't huge, but network software (unlike phones or laptops) has to run for months or years without failure, so it was unacceptable. Unlike most complex software in C and C++, we are not plagued by memory leaks, so this was a bad surprise. We make extensive use of smart pointers (though not the horrible shared_pointer class, which is an ugly accident waiting to happen) and the RAII paradigm. As a result, objects get deleted when they should, whether they are short-term temporaries or long-term configuration information. Yet, we were leaking memory.

The fix, once we tracked it down, turned out to be the addition of a one-line function with an empty body:

virtual ~query_helper_iterator_base() { };

How can an empty function fix a complex memory leak? Read on...

Our system (STM) keeps track of several very large collections, of potentially millions of objects: network applications, hosts, users, network routes and several others. It provides a SQL-like Rest API that can be used to retrieve them based on complex filters and other criteria. For example, you can say "find the top 20 applications ordered by traffic rate, and tell me their current traffic rate and flow count".

Our web-based GUI maintains several charts, which it updates periodically every few seconds via the Rest API. Many users can run their own copy of the GUI, so these complex queries can be seen several times per second. The problem is that they require the whole collection to be scanned, and every entry to be inspected. As you may imagine, this is very expensive in CPU cycles and memory bandwidth, and we found it was a performance problem for our larger installations.

All of these collections are scanned in the background every few seconds, to maintain performance information. It doesn't seem hard, as we scan the whole collection and have them in L1 cache, to preload a cache for common queries such as the one above. Hence we came to write the query_helper collection of classes. Thus armed, we can say to a collection "do you have a cache which matches this query?". For example, we keep a cache of the top 1000 applications by traffic rate. When the GUI asks for the current top 20, we simply look at the cache and pick the top 20 from it - much easier than scanning a million applications.

Different caches have different implementations, depending on the nature of the query they are designed to support. For example, some use a simple STL vector, while others, which are explicitly ordered, use an STL set. This implementation detail needs to be hidden from the internal user, who merely knows that they have been given a cache that matches their query. This is, of course, an obvious application of virtual functions and pure base classes. The user sees a query_helper object, whose implementation is hidden behind them. So far, so straightforward.

The problem comes when we consider the iterators for these collections. The normal usage is a range-based for loop, which has to create a concrete iterator over the collection:

query_helper *qh = collection->find_matching_helper(rest_query);
if (qh) {
    for (object *obj : qh) {
        ...

The type of the iterator must be known, in detail, at compile time, yet the full type of the collection varies dynamically at runtime. How can this be made to work?

The solution is to use a second level of iterator, to which the base class iterator simply contains a pointer. That can in turn use virtual functions to implement an iterator in terms of the specific implementation of the actual query_helper object. The outer iterator simply delegates every function to the corresponding virtual function of the inner iterator. The only complication is that creating an iterator requires a dynamic memory allocation, but in the overall scheme of the Rest API implementation this is small stuff.

By now you're probably wondering what this has to do with our memory leak. I need to explain another implementation detail. The caches are rebuilt from scratch at every scan of the collection. But what happens if someone is using one when this happens? How can we know when it is safe to delete the old cache? The answer is that our cache uses our generic intrusive reference count mechanism. The object contains a reference count, and the same "mixin" class (called reference_countee) that provides it also provides a class-specific smart pointer that manipulates the counter, deleting the object when the count falls to zero.

So all we have to do is include said smart pointer in the iterator object, and it will protect the old cache from being deleted until the iterator is deleted. No possibility of dangling references, and all taken care of by C++'s constructor and destructor system. Nothing can go wrong...

Except (as you've guessed) something did go wrong. In fact, any cache that got used during its brief lifetime was never getting deleted. Reading the code, everything should have worked. The outer iterator (for the query_helper base class) has a destructor, which in turn deletes the inner iterator it points to The inner iterator's destructor destructs the smart pointer, which in the process decrements the reference count and, if this was the last user, deletes the object. That mechanism - the same identical C++ source code - is used in dozens of places in the code, and it works.

This, finally, is where the empty one line function comes in. C++, because of its heritage in C, doesn't assume that a function is virtual. Unless it's explicitly declared to be, the compiler assumes it can safely generate a static call to the member function of the actual class pointed to, rather than incurring he extra cost of using a function pointer. The base class of the inner iterator has no content, so the automatically-generated destructor does nothing.

So... when the outer iterator was deleted, its destructor was called. That correctly called the destructor for its contained inner iterator (thanks to std::auto_ptr... don't get me started on why the new unique_ptr is a terrible idea). But, instead of calling the proper destructor for the derived class, which would decrement the reference count and hence allow the old cache to finally be deleted, it was just calling the trivial destructor for the base class.

It's not the code in our one-line function that matters, it's simply the fact that it exists and (most important) is declared virtual. That tells the compiler that instead of generating a static call, it must look in the object's virtual function table (vtable) to find the corresponding function in the derived class.

C++11 purists will say, correctly, that there is another way this should be caught. If we define a function whose sole purpose is to override a virtual function in a base class, it should be given the 'override' qualifier. This would have generated a compiler error since the base class didn't in fact have such a function to override. We consider our wrists duly slapped, and will redouble our efforts to ensure that such functions are duly qualified.

This is pretty hard to understand, so at risk of making it even harder, here are some code snippets to illustrate what is going on. (It's not quite right yet - it's very hard to get the blog system to handle angle brackets).

/************************************************************************
 * First the base type for the INNER iterator - the one that MUST have
 * the critical virtual destructor. All its member functions, like
 * operator++ shown below, are pure virtual, and there are no member
 * variables.
 ************************************************************************/

class subtype_iterator_base : public std::forward_iterator_tag
{
public:
    // virtual ~subtype_iterator_base() { }; // the vital virtual destructor!
    virtual subtype_iterator_base &operator++() = 0;
    ....
};

/************************************************************************
 * Now the base query_helper class. This is the only class seen by the
 * users of this function - they are never aware of any of its derived
 * classes.
 ************************************************************************/

class query_helper
{
    ....    
/************************************************************************
 * Now the OUTER iterator of the base class. It contains only one member
 * variable, an auto_ptr to the base INNER iterator which actually does the 
 * work. All its member functions simply delegate to the corresponding
 * virtual member function of the inner iterator.
 ************************************************************************/

    class iterator : public std::forward_iterator_tag
    {
    private:
        auto_ptr my_sub_iter;
    public:
        iterator &operator++() { my_sub_iter->operator++(); return *this; };
        ....
    };
    ....
};

/************************************************************************
 * Finally, a specific derived class of the query_helper class, in this
 * implemented (somehow) using an STL set. It defines an iterator class,
 * derived from subtype_iterator_base, which in turn has a smart
 * reference-counting pointer to the query_helper it is using.
 * 
 * Note the inheritance from reference_countee (using CRTP), which provides
 * both the intrusive reference count and the ::pointer smart pointer
 * class. 
 ************************************************************************/

template<class OBJECT_CLASS, class COLLECTION_CLASS>
class query_helper_xxx : public query_helper,
                         public reference_countee<query_helper_xxx>
{
private:
    std::set<OBJECT_CLASS*> my_items;
public:
    class my_iterator_t : public subtype_iterator_base
    {
    private:
        typename std::set<OBJECT_CLASS>::iterator my_iterator;
        typename query_helper_xxx<OBJECT_CLASS,COLLECTION_CLASS> ::pointer 
            my_qh;
    public:
        C *operator*() const override { return *this->my_iter; };
        ....
    };
    ....
};