« | » Main « | »

The Hoax

Monday 20 August 2007

On the plane back from Denver, the movie was The Hoax, about Clifford Irving's fake autobiography of Howard Hughes. I enjoyed the movie a lot, it was basically a caper movie, with Richard Gere as the audacious Irving pulling the wool over everyone's eyes, counting on Hughes' legendary reclusiveness to keep him from being exposed.

I remember this story from the early '70s, I remember seeing sketches of the supposed meeting on top of a Mexican pyramid in Life magazine. I hadn't realized that it eventually touched on Watergate, which made the intrigue all the greater.

Toward the end of the movie, there's a shot of the beleaguered Irving in the back of a car being hounded by the press. I suddenly realized I had seen that setup before: on the day that Susan appeared on the Today Show, we walked back to our hotel, expecting just an ordinary Sunday morning New York stroll. But we came upon this scene:

Richard Gere in a car

We asked a police officer nearby if anyone famous was in the car, and she said, "Richard Gere", as if nothing unusual was going on. At the time I thought I'd have to keep an eye on Richard Gere movies to figure out which one it was, but I forgot all about it. It was cool to see the scene in the movie and remember the connection.

One more synchronicity: the Wikipedia page about Clifford Irving says that he now lives in Aspen, Colorado, where we had just been.


Sunday 19 August 2007

We spent the last week in Colorado. We sent Nat to a camp for autistic kids, an extreme sports camp for autistic kids, no less! The camp is in Aspen, so we all went out to drop him and an aide off at the camp, then the four of us spent the week tooling around Colorado.

It was quite an experience for a number of reasons. It was the first time Nat had been away from us overnight by himself, and he did fine with it. There were of course moments of anxiety for him, but nothing the staff couldn't handle.

We drove all over Colorado, putting 1350 miles on our rental car. We stayed in Aspen, Crested Butte, Telluride, and Cortez, with additional stops for meals in Glenwood Springs and Durango. Colorado is a big state, certainly compared to our native Massachusetts. In planning the trip, we were constantly having to sanity-check our plans. Looking at the map, we'd talk about "just driving over to Salida", and then realize it would take three hours. Add in the fact that the roads took us over difficult mountain terrain, and all of our driving instincts were off. Google maps did a really good job estimating drive times for us, and we learned to use it as a reliable predictor for each leg of the trip.

Driving the mountain passes was definitely a new experience for us. Going west on I-70, we crossed the Continental Divide and then headed downhill for miles, with "runaway truck ramps" appearing occasionally on the side of the road. That's not something you see in the East!

From Aspen to Crested Butte is about 25 miles as the crow flies, but driving it takes over three hours to drive the 105 miles of road, including Kebler Pass, easily the scariest driving I've ever done, and I routinely drive in Boston! This is a dirt road, at times bumpy, twisting and winding its way up the mountains, often with no lines or guard rails, and the occasional cow in the way. Due to our excellent planning, we drove it at dusk, adding to the excitement!

Except for Cortez, all of our stops were in mining towns turned to ski resorts, and it was interesting to see the differences among them. Aspen was clearly the most polished and up-scale, and Crested Butte the most authentic and gritty. Telluride hit a good middle ground, feeling like a resort, but with an approachable hippie charm.

We went to Cortez expecting to go to Mesa Verde. Google Maps said the fastest way to get back to Aspen for the end of the week was to detour out into Utah, which would take us right past Arches National Park, so we decided to do Mesa Verde one day, then Arches on the way back. In the end, we decided not to see Mesa Verde, because the park sounded a little too tightly controlled for our needs, but we did go to Arches to see the carved rock, which we loved.

All in all, the trip was an terrific escape from all of the usual stresses, even if it was occasionally to take on new and unusual stresses.

We took a ton of pictures, and Susan made a tabblo for each day:

Tabblo: Colorado Trip:  Day 1

Tabblo: Trip to Colorado:  Day Two

Tabblo: Colorado Trip: Day 3

Tabblo: Colorado Trip:  Day Four

Tabblo: Colorado Trip:  Day Five

Tabblo: From Arches to Aspen:  Day Six

Tabblo: Hike To Linkin Lake, Aspen:  Day Seven

Regular expression diversity

Friday 10 August 2007

I'm amazed at how many regular expression libraries there are, and at how each invents new syntax for some new feature. The Oniguruma library, for example, describes character class operators:

^...    negative class (lowest precedence operator)
x-y     range from x to y
[...]   set (character class in character class)
..&&..  intersection (low precedence at the next of ^)
  ex. [a-w&&[^c-g]z] ==> ([a-w] AND ([^c-g] OR z)) ==> [abh-w]

as well as greedy, reluctant, and possessive qualifiers? Yikes.

Two weak typing problems

Thursday 9 August 2007

Recently, I had two demonstrations of the pitfalls of weak typing.

First, my son Max was working on a simple Flash game. He asked for my help fixing it, because the character would move left, but it wouldn't move right. His code looked (roughly) like this:

if (Key.isDown(Key.LEFT)) {
    guy._x -= "10";
if (Key.isDown(Key.RIGHT)) {
    guy._x += "10";

The problem here is that the _x attribute is an integer. When subtracting the string "10" from an integer, the weak typing coerces the string to an integer, and the subtraction moves the character left. But when moving right, the integer is added to a string, which is a valid string operation, so the integer is coerced to a string, and the two strings concatenated. Setting the _x position to a string doesn't move the object, so the character doesn't move right.

Apart from the usual mystifying behavior of weak typing, the bizarre thing here is how two cases which seem completely symmetric in fact have very different results. Strings have a plus operator, but not a minus operator, so the helpful weak typing chose different paths for the two cases, resulting in the strange left-but-not-right bug.

Changing the "10" constants to integer 10's fixed the problem, of course, since it meant that all operations were the expected integer operations.

The second example was in some JavaScript code designed to speed up a slow calculation. The cache is a map from strings to lists of objects, but the calculation could return nothing, which was also important to cache, so a string object '-' was inserted in its place:

var answer = this.cache[question]; 
if (!answer) { 
    answer = long_expensive_calculation(question); 
    if (!answer || (answer.length == 0)) {  
        this.cache[question] = '-'; 
        return null; 
    else { 
        this.cache[question] = answer; 
        return answer;
if (answer == '-') {
    return null;
return answer;

This code speeded up the calculations, but still took much longer than it seemed like it should. The cache had a really good hit rate (99%), so we only had to look at the path where the cache found the answer. But all it does is look up a value in a hash, compare the value to a string, and return the value. How can that take too long?

The answer lies in the weak typing of that equality check near the bottom. The answer from the cache is a list of objects. To compare that against a string, JavaScript converts the list to a string, then compares the strings. That string conversion was consuming all the time, and was completely unnecessary. If the answer wasn't a string to begin with, we didn't need to do the comparison at all.

Changing the comparison to:

if (typeof(answer) == 'string' && answer == '-') {

sped up the function by a factor of about 10.

BTW: this function is more complicated than it had to be. The simpler approach, which avoids the sentinel value and its string comparison, is:

var answer = this.cache[question];
if (typeof(answer) == 'undefined') {
    answer = long_expensive_calculation(question):
    if (!answer || (answer.length == 0)) {  
        answer = null; 
    this.cache[question] = answer; 
return answer;

I use Python, which doesn't do these sorts of magic conversions, but it also forces me to explicitly convert ints to floats if I want a float answer, which is also a pain. I'd kind of like a middle ground: implicit conversion among numeric types is ok, but not between numbers and strings.

Literal answers to rhetorical questions

Saturday 4 August 2007

Over at the usually science-themed blog Recursivity, Jeffrey Shallit provides a few literal answers to rhetorical questions, riffing on a theme started by Paul Brians in his Mr. Gradgrind's Literal Answers to Rhetorical Questions. The comments on Recursivity give some more examples. Popular songs seem to be good sources for questions:

Why don't we do it in the road?

Apart from being a violation of traffic and public indecency laws in most jurisdictions, it's highly dangerous. In one study, 63% of fatal traffic accidents involving a pedestrian were considered to be the pedestrian's fault.

Glark and ack

Friday 3 August 2007

Two new grep clones: glark (written in Ruby), and ack (in Perl). Both specialize in searching trees of source files, and do cool things like color-highlight the results.

New client-side web tools

Thursday 2 August 2007

Quick links to new JavaScript-based tools:

¶  XRAY is a cross-browser bookmarklet for selecting an element and displaying its geometry and other info.

¶  YUI 2.3.0 is an update to YUI including a rich-text editor, a dependency-aware component loader, and other cool stuff.

¶  YUI Image Cropper is a nice implementation of image cropping, built on YUI. These seem to be available for all the popular libraries: for scriptaculous, for mootools, for jQuery, and so on.

¶  Exhibit is a slick library for displaying small databases interactively in the browser without needing any server-side support. From the Simile (Semantic Interoperability of Metadata and Information in unLike Environments) group, which has a bunch of interesting stuff.

« | » Main « | »