Friday, 27 May 2011

Jottings from Japan

(I wrote this back in November, on my way back from Japan, but for some reason never got round to finishing and posting it). More pictures here.

My second trip to Japan this year, for the usual reason: trying to spend some time with my wife as she zooms around the world, bouncing off of various cities such as (in this case) Belfast, Seoul and Paris, in that order. I'm burning up my collection of airmiles and so (poor me) the only way I could get the dates I wanted for this trip was First Class on Singapore Airlines. Summary: not bad! Unfortunately on the LA-Tokyo route, they aren't yet running the Airbus 380 - I would have loved to have tried that in First. But the 747 wasn't bad either. Though there are things they do which, in my opinion, create unnecessary stress for the passenger- such as having to choose between Dom Perignon and Krug.

I tried both, alternating every time I had a top-up. The Dom, I can report, was much lighter than the Krug - surprising since compared to lesser champagnes Dom has a lot of body. But it was almost spring-like compared to the Krug's biscuity heaviness. Both were pretty good though, as was the Griotte Chambertin I had with the main course. My only disappointment with the flight was entirely my own fault - I left a half-finished book, which I was thoroughly enjoying, on the plane.

I stayed, as usual, at the New Otani. This is a wonderful hotel, in my opinion the most agreeable in Tokyo. It's the only hotel in the world to have its own private 16th century samurai garden, which guests (and indeed anyone else) can wander around freely, or admire over breakfast from the restaurant. The story is simple enough: in 1964 Japan hosted the Olympic Games, but didn't have a large, modern, western-style hotel. Mr Otani, a successful industrialist whose statue can be found tucked away in a corner of the samurai garden, was asked to help. But where to find the land in super-crowded Tokyo? In addition to the Imperial Palace, Tokyo has a second palace used for visiting heads of state and such. What could be simpler than to use some of its vast grounds for the hotel? And somehow, Mr Otani managed to get the part containing the samurai garden. Incidentally the New Otani appears in the James Bond movie You Only Live Twice as the headquarters of the evil empire - construction was complete but the hotel had not yet opened when the film was made in 1964.

The first day I worked, visiting our Japanese reseller, a typical Japanese "fireside chat" type of meeting. Then in the evening I traveled down to Haneda, Tokyo's domestic airport, to meet my wife. Well, it used to be Tokyo's domestic airport. The Japanese government has finally opened it to international flights, as an alternative to the super-inconvenient Narita. Now there's a vast new international terminal, complete with its own subway station. Quite a change from a couple of years ago when I flew to Korea from Haneda - the terminal was a tin shed somewhere on the outskirts of the airport, with only an infrequent shuttle bus service.

The next day we took the train to Hakone, a journey I've already described here. But first we went to Shimbashi for sushi, to the same kaiten sushi restaurant we've been visiting now for nearly 30 years! It's a low-price operation for the salarymen in the area, but because the turnover is so high, the fish is wonderfully fresh.

Hakone was wonderful, we were incredibly lucky with the weather - the previous day had been overcast and damp, today was bright sunshine. We stayed at a traditional Japnaese ryokan, selected through the wonderful service of The bath was at just the perfect temperature, which means just bearable, the kaiseki dinner was excellent. And in the morning, looking closely at the prints which lined all the corridors, we realised that they were original Hiroshige - which means worth a small fortune, tucked away inconspicuously in a modest inn.

Hakone can be visited as a day-trip from Tokyo, and everything is organised for just that. The train ticket includes all of the various means of transportation required - a bus along a twisty mountain road to Lake Ashi (Ashinoko), a quick walk to find the ancient cedar avenue which was once the main road from Tokyo to Kyoto, then a lake steamer disguised - improbably - as a pirate ship, complete with swashbuckling pirate captain, photographer in tow. In the 25-minute journey the pirate captain walks around the whole boat, and just before you dock he returns with the pictures for sale.

One reason why Hakone is so popular is the fantastic views of Fuji-san, first from the lake and later from the cable-car that crosses the mountain. There's a change in the middle, at one of the surreal, hellish, sulphur-laden volcanic springs that are found only in Japan. But the journey isn't over yet - at the bottom of the cable car is a funicular, and then a tiny train that twists and turns around corners that even a car would struggle with, back to the mainline train station. Along the way we visited the Hakone Art Museum. There were two things to see there: the wonderful autumn foliage on the maple trees that fill the garden, and the throngs of photographers, all with the very latest cameras and extraordinary lenses, taking pictures of the wonderful autumn foliage.

On Saturday, we had the great good fortune to go along to a Japanese family event, the annual sushi party of the company where I used to work. It's difficult for westerners to get to meet Japanese families, and we're really very lucky to have such good friends who will invite us to something like this. Everyone was there, colleagues, spouses and their children. The food was truly amazing, and went on forever, and the company was wonderful too. I'm incredibly lucky to have such good friends in Japan.

I spent Sunday on my own - my wife had to return to another meeting in Europe. I went to Ueno Park and visited the Science Museum, recalling my first ever visit to Japan in 1982. It has changed a lot - for one thing it has doubled in size, and it is much more modern and visitor-friendly. Back then it was just a lot of dusty display cases. But one thing that hasn't changed is that there is absolutely no allowance whatsoever for non-Japanese visitors. Apart from a few signs in the hallways, nothing is labeled in English. Now - unlike then - I can just about read the signs, though it takes a long while. But it is reasonable enough when you consider how few foreign tourists there are in Japan, apart from Kyoto. A while back we went to the Museum of Modern Art, in another corner of Ueno Park, and
we saw just one other foreign visitor there. Of course it's self perpetuating - Japan apparently does want to attract foreign tourists but for as long as you need to be able to speak and read some Japanese to survive, it just isn't going to happen.

Finally on Monday it was time to return. As usual I took the bus out to the airport. At the first-class check-in desk the lady was very concerned - never a good sign, especially when you're using an airmiles ticket. There are just so many things to go wrong. She walked away, talked to colleagues with a worried look on her face, made a phone call. I feared the worst, beginning to envisage a hasty one-way ticket purchase and the uncomfortable return journey in economy. Finally she turned back to me.

"Mr Harper... did you leave a book on the aircraft when you arrived?" Well yes, I did.

"I'm very sorry, the book is in our office, would you mind waiting a few minutes while my colleague collects it?"

This could only happen in Japan! Once I left a valuable (to me) notebook on Swissair (yes, it was a long time ago), in Business Class. When I called, they said, "Oh, we never keep anything, it will have been thrown away." But Singapore Airlines - in Japan - even kept a $5 paperback for me, unasked.

It got better, too. As I was waiting in the emigration line, after security, someone came running up to me, apologising - I'd left my laptop behind at security... and they had to run after me to return it! If I'd done that at Heathrow it would already have been on E-Bay!

The return journey on Singapore in First was as good as you'd expect - there's really nothing to be said.

Friday, 20 May 2011

My Very First Linux System

Ubuntu rocks. For more, read on...

About a year ago, I converted my home desktop machine from Windows XP to Windows 7, hoping to improve its dire performance problems. That was not a success. Not only was the Windows 7 performance if anything worse than XP, but a number of other things stopped working as well. Based on my experience I cannot imagine why anyone would ever choose to run W7 instead of XP. W7 is full of poorly conceived "security" misfeatures, making it painful to use and even harder to manage. For example, it's impossible to save an image from a webpage to local storage. And I never did get the Cisco VPN to work.

I've been thinking for a while that it would be a good idea to have a Linux server at home. I've switched just about all my non-embedded stuff at work from Windows and Visual Studio to run on Linux systems. VS is actually quite decent but things need to end up on Linux anyway and keeping them dual-platform is too much trouble.

When I first used Unix, Linux hadn't even been thought of. I equipped my network architecture team at DEC with workstations in about 1988. Of course at DEC we didn't have the System Whose Name Must Remain Unspoken, we had Ultrix - which was just BSD Unix. And Linux is both our development and our production environment at work. Running Linux as a user is no issue, but I was worried about the sys admin aspect of the thing. My perception of Linux was of constantly having to build things from source, of irrenconcilable version conflicts and unfindable drivers and bits of operating system. So I kept putting it off.

Then a friend told me about a system they had just bought. Six-core 3.2 GHz AMD CPU, 8 GBytes of memory... all for under $500. That sounded too good to be true, but I went to the Tiger Direct web site and there it was. The temptation was too strong. It's difficult to buy a PC-type system without getting - and paying for - Windows, whether you want it or not. NewEgg for example won't sell you a barebones system like this.

A few days later it all showed up in several large packages. I've always bought assembled systems before, but this one came as a collection of parts - case, power supply, motherboard, CPU, disk, memory, and a few other bits and pieces. I was apprehensive about putting it all together but in fact it was easy. The only trickly part was getting the cheap-and-nasty metal plate around all the motherboard conneectors to fit propely. Functionally speaking, this isn't strictly necessary, but it would look funny without it.

Actually the system came without memory, because it was backordered, and also I'd ordered the wrong part for the CD/DVD drive as well. So it took a couple of trips to Fry's to get everything required. I'd also bought an Ubuntu book which conveniently had a CD in the back, avoiding the problem of downloading the distro and burning a CD - for which I'm not sure I have the software.

And then came the miraculous part. I put the CD in the drive and booted the machine. Ubuntu came up, and with a couple of clicks started to install itself. Nothing could ever have been easier! Once my new system was running, there were numerous things I wanted to install. For every single one of them, a single command and a short wait downloaded it, installed it and got it running. No scratching round trying to find ancient CDs, no complicated licence agreements, no complex configuration screens. And better yet, no Windows registry! Everything just installed and run.

I'd never used Gnome or any other Linux GUI before. Up to now, all my Linux usage has been from the command line - which I rather like, actually. I had low expectations of Gnome but I couldn't have been more wrong. It does everything Windows does, and without all the irritating bogus security misfeatures. I was especially pleasantly surprised by OpenOffice, which can read and edit all my Word, Excel and Powerpoint files. And it's free.

There was only one thing that gave me problems. No surprise, it was the interconnection with my Windows system which, for now anyway, I have kept in place. There is a piece of software, Samba, that allows a Linux system to provide a Windows file server. Unfortunately it has to accomodate all of the superfluous complexity and options of Windows, so configuring it is a nightmare and I just couldn't get it to work. Finally a friend pointed me to SWAT which straightened it all out for me. A key item is that the accounts and passwords for Samba have absolutely nothing to do with any other accounts and passwords on the system. Connection in the other direction, accessing Windows files from my Linux system, is still distinctly shaky. It kind of works, sometimes, but keeps running into all those security misfeatures that made me dislike W7 so much in the first place. I have yet to get it so the Linux machine can write files on Windows, even using the adminsitrator account.

One thing I wanted to do was open up the machine for very limited outside access, so I can retrieve my files from it. This was amazingly easy - install Apache and it just works. Then a little configuration on my Linksys router, five minutes to create an account with, and now I can (with a password of course) access my files from anywhere.

I love my new Linux machine. Next step: move Windows to be a VM under Linux. More on that later...

Tuesday, 17 May 2011

Cisco's Pearl Harbor

Even 70 years later, the Japanese raid on Pearl Harbor is an emotional topic for many Americans. But viewed dispassionately (maybe easier for me since I'm not an American, by birth anyway), it was a strategic masterstroke and a flawless piece of execution. Japan, a country with practically no natural resources, had created a vast Pacific empire. The US, reacting rather tardily, decided to slow them down by imposing an oil embargo which would be catastrophic for Japan's ambitions. What to do? The concentration of the US Pacific fleet at Pearl Harbor created a unique opportunity to destroy at a single stroke America's ability to enforce the embargo. It was not an easy thing to do - Hawaii is way out of land-based range for the aircraft of the time - but the raid was cleverly planned and rehearsed. Nobody can deny that it worked. Contrary to a common belief nowadays, it was not a "kami kaze" raid - the Japanese pilots and aircraft nearly all returned safely, ready to fly another day.

So, clever strategy, excellent execution. What could go wrong? Well, we all know what went wrong. Not surprisingly the US was seriously irritated (as we Brits would put it) by this devastating attack from a country that was not even officially at war - owing to the one execution failure, the incompetence of the Japanese ambassador in Washington. And over the following four years, and despite the complete destruction of the Pacific fleet, America fought back and of course eventually wiped the Japanese empire off the map.

I don't know the answer to the question, "X is to strategy as strategy is to tactics". I don't think we have a word for that - the kind of cosmic level above strategy - so let's call it "meta-strategy". While Pearl Harbor was strategically practically the only choice for Japan at the time, at the meta-strategic level it overlooked the fact that the US has such vast resources, both human and natural, that it simply cannot be beaten militarily. Until Pearl Harbor, Japan's empire was an annoyance to the US, a strategic threat, but not a reason for  military action. Afterwards, the US had no choice but to react in the most devastating possible way - and was able to do so.

What does this have to do with Cisco? By the mid-2000s, it had the enviable position of total dominance in its market, but had nowhere else to go. Hence the famous misadventure into the consumer domain. But there was something much more adjacent to its existing empire in the enterprise - the computing side of the data center. There were a few truly visionary people inside the company who could see this and tried to lead them there. There were a few false starts, but finally the acquisition of Mario Mazzola's Nuevo Systems spin-in/out in 2006 gave them a credible product to address this market. Since then Cisco has turned it into a $1B product line.

What could be wrong with that? Brilliant strategy to get the company out of a tight corner, excellent execution. Now maybe you can see the parallel with Pearl Harbor. Because shipping a product to compete directly with the traditional computing providers was a direct attack on them, the commercial equivalent of bombing their Pacific fleet into shrapnel. What's more - and this is where the analogy breaks down - IBM and HP were not just competitors, but also major sales channels for Cisco.

HP has taken this very badly. They couldn't just walk way from their Cisco partnership, but it's clear that a decision was made at the highest level that Cisco was now the enemy. Five years later we are seeing the result of this, even to the extent of hiring away Cisco's top techincal architects - not to mention acquiring 3Com. Curiously, it was HP who destroyed my previous large-company employer, DEC, after Ken Olsen's disastrous "snake oil" speech and outright rejection of Unix. Looks like they'd like to get Cisco, too.

As for IBM, whatever nice things may have been said in public, they never got over being driven out of the networking business by Cisco in 1999. There has never been much love there, and Cisco's move into their very own territory was just one step too far.

I don't know what Japan could have done if it hadn't attacked Pearl Harbor, and I don't know what "adjacency" Cisco could credibly have attacked if it hadn't been the data center. But the meta-strategic issue is the same in both cases. The US will come and get you if you annoy them enough - just ask Osama bin Laden. And so will IBM and HP.

Tuesday, 10 May 2011

Python, readline and insanity (mine)

A bit of a technical post here. For the last week or two I've been writing some financial modelling software in Python, to see whether it's really possible to make serious money from a rather clever scheme that a friend of mine came up with. When I came to put the command line interface (CLI) together, I wanted something with all of the usual Unix CLI stuff - recall, editing, completion, help. The standard way to do this for C/C++ code is using the GNU readline library, which is what the Linux shell uses for example.

I recently got round to doing this for another piece of software, written in C++. There, though, I couldn't use readline. Readline is licensed under GPL, which means, essentially, that if you use it in your code, everything you write legally enters the public domain. Luckily there is a non-GPL near-equivalent, called editline. This provides all of the useful functionality of readline - which actually is about 5%, like most software 95% of what it can do is unknown and probably incomprehensible to 95% of the people who use it (just like Word or Excel).

I had no such constraint with my Python code. Python provides a module for interfacing to readline which makes the basics - command recall and editing - incredibly simple to use. Simply importing the module changes the behavior of the console input function raw_input to provide all this. Nothing could be simpler.

But I wanted more. Specifically, I wanted tab completion and also Cisco-like help, where typing '?' prompts with what to enter next. In C, completion is done using a callback, and you can define different completions for different functions - in particular, you can have one for tab and another for '?'. But the Python mapping provides only a single callback. More on that later.

The implementation looked simple. One function call (set_completer) to register the callback function, another (parse_and_bind) to tell readline how to handle the special characters. I found a good example and pretty much copied it. That's where the insanity comes in. The example, cut and pasted into a file, worked perfectly. My code didn't. Hitting tab did nothing at all. Putting diagnostic code into the completion handler produced noting. Even deliberate errors - like using unassigned variables - did nothing. My code simply wasn't being called. There followed a couple of increasingly desperate hours of cutting and pasting, copying code from the working example to the non-working code and vice versa... all to no avail. The example worked, my code didn't - even when they were identical!

I'd set aside an hour or so to get all this stuff done, and by now I was into the third hour and still getting nowhere. I was just a little frustrated. Finally, by application of the Sherlock Holmes Principle ("once you have eliminated the impossible, whatever remains, no matter how improbable, must be the truth") I realised what was happening.

The Python interpreter makes heavy use of exceptions, both for intended cases (e.g. key not in a dictionary) and for programing errors (e.g. referencing an undefined variable). Normally, an uncaught exception - from an error - ripples right out to the outermost function, where the interpreter prints a stack dump. You know not only that something bad happened, but where. Things get different when C code gets in the way. Python passes the exception down into the C code, but what happens to it there depends entirely on the C code. And in the case of the readline library, the C code just swallows the exception and says nothing. So if there's a bug in the completion handler, it just fails silently.

Once I realised this, the solution was obvious - put a catch-all handler in the outermost completion handler function. That tells what the error is, though it doesn't give a stack dump. Once I did that, I could see the errors and quickly had things running.

There was another problem though, which I alluded to earlier. Writing in C, you can have a distinct callback for tab and '?'. In Python, there's no way to do this, and no other way to find out which character was typed since it doesn't get put anywhere. There's simply no way to know which it was. I did find a patch to the Python readline module which made this possible, but I don't want to deal with a special version of the code. So my compromise is to treat them exactly the same. If either occurs as the first character of a field, it's treated as '?', and generates a helpful message telling you what's expected. Once you've typed anything else, what you get is completion.

So, the moral of this is, always put a catch-all exception handler in the outermost Python callback function, and life will be good.

Sunday, 8 May 2011

It has a button to do WHAT?

I recently set up a new computer at home to run Linux. That's another story, soon to be told. (It's an excellent idea, by the way). In the process of finding room for it, running cables and so on, I accidentally pulled on a cable and sent a bunch of stuff tumbling off the back of my bookcase. There it hung by its cables for several days. Since everything seemed to work, I didn't pay much attention.

Today I needed to print something. No printer. Hmm. In sorting out the mess of USB cables for the new mouse and keyboard, I'd unplugged it. Getting to the cable required untangling all the stuff which fell off a few days ago. No problem - just the cable modem and the WiFi router, and their associated cables. I restored everything to its place, and even tidied up a bit, feeling extremely virtuous.

It wasn't for a while that I noticed I no longer had an Internet connection. A quick glance at the cable modem showed that its usual array of blinking lights had been replaced by just one steady orange light. I looked around and everything seemed to be cabled correctly, so I power cycled the modem. The lights gradually lit up, then started blinking - success, I thought. But then suddenly they all went out, back to the status quo ante. Hmm, again.

I tried all the usual things, power cycling, unplugging, checking software. All the machines could still talk to each other, just not to the outside world. I even checked the television, in case there was a problem with the cable itself. It was fine.

At this point I was getting desperate. Of course, it could just happen that Comcast had an outage at the exact time that I sorted out my little mess. Nothing left but to give them a call - not something I was looking forward to, 20 minutes listening to hold music, get cut off, another 20 minutes, then an operator in Islamabad trying to pretend he's in the US... ouch, especially on a Sunday afternoon. Plus which, the only way I know to get the number is... from their website. Which I can't reach.

So I took another look around. On top of the black plastic modem I noticed a tiny black plastic button. Well, who knows, it might do something. I pressed it and instantly - kaboom! - all the lights started blinking and all was well with the world again. Out of curiosity I pressed it again - no more blinking lights. I looked closer. The one orange light that stayed on is marked "standby" and... yes, so is the button, almost illegibly.

So, the modem has a button you can press which stops it working. It does it so thoroughly that it stays not working, even if you power cycle it. Obviously, I must have pressed the button as I was retrieving and rearranging my boxes. But... WHY? Why put a button on a piece of consumer gear, intended to be used by technically unsophisticated people, whose sole purpose is to stop it working in a mysterious and mystifying way? Apart from the inconvenience, it must generate quite a lot of support calls, from people like me who press it accidentally then can't get anything to work. Support calls cost money, even when you outsource them to Bangladesh.

Somewhere there is someone who thought this was a good idea, such a good idea that they convinced Comcast that it was worth the cost of all those support calls and the risk of a bunch of unhappy customers. I would love to meet him and have him (well, it's almost certainly a him, statistically speaking) tell me exactly what he was thinking.

Thursday, 5 May 2011

Culture in the Laundry Room

Like many Europeans, one of our minor surprises when we moved to the US was the laundry equipment. The top-loading washing machine with its vicious agitator swirling back and forth was not only three times bigger than anything we'd seen before, it also tore clothes apart three times as quickly. Maybe that's why casual clothing caught on so quickly in the US - anything with any kind of structure is rapidly reduced to a formless mess by the traditional top-loader. Another surprise is that the washer and dryer are considered to be part of the house, and are left in place by the previous owner - in Europe anything which isn't physically part of the structure moves with the owner.

Anyway, it quickly became urgent for us to replace the machines with something less destructive to our apparel. We bought a nice, civilized Bosch front-loading washer and matching dryer, and our clothes lasted a lot longer. It's true that when you find a dropped sock on the floor five seconds after starting the washer, a top-loader is handy. But having our clothes last for more than three washes made up for it.

All good things come to an end though. Our wash cycles started lasting longer and longer, until the machine was taking more than two hours to wash a few shirts. The service guy came, ran a bunch of diagnostics, and declared that there was noting wrong with the machine, but took $200 anyway. Then it started to smell bad. The service guy came again, took another $200, and declared that there was still nothing wrong with the machine. We certainly weren't going to pay him again, especially when a quick browse showed that we could buy a new machine for not much more money than we had already paid him.

A big surprise was the choice of brands: LG and Samsung. Pretty much nothing else is available. Bosch shows up on about page 10 of the web catalog, along with the traditional American brands like GE. Soon, we had a brand-new, non-smelly Samsung washing machine. Made for the American market, it is about twice as big as its predecessor, which is actually quite handy since it means you can stuff more washing into it.

One thing we weren't expecting was its cultural contribution to our household. We're used to things going beep - I've lost count of how many things beep. Most things beep when they've finished, like the microwave and the toaster. The fridge never really finishes, so it beeps if you leave the door open. I've never heard the garbage disposal beep, but there's probably some occasion when it does. So how is a poor appliance to compete in this melee of beeps? Well, Samsung has an answer. Whenever the washer wants attention - when it has finished, when it has started, and various other odd times as well - it plays the opening bars from Schubert's Trout Quintet.

This is sheer genius. Whoever would have thought of a washing machine that plays uplifting classical music? It really raises the bar for all of these appliances. The watery theme is perfect for a washer, though Handel's Water Music would be even better. The knife sharpener (if we had one - I prefer an old fashioned stone) should naturally play Katachurian's Sabre Dance when the knife is truly sharp. Haydn's Clock Symphony is a clear choice for the timer, and maybe his Miracle Symphony for the microwave.

But there could be more, much more. Twenty years ago nobody imagined there was a fortune to made in downloadable ringtones. Soon, all these appliances will be WiFi enabled, and you'll control your toaster from a web browser. Then, they can all have menus of tones for different things, and it can be monetized - a neologism which I'd hate if it wasn't so descriptively handy. For only $2.99, a choice of ten different tones for your bagel maker. Hmm, maybe I should patent it. But since I don't have the stomach for that (my last attempt at a personal patent got definitively rejected after I'd spent a serious amount of money on it), just consider this to be prior art.