Death by radix

This post is reinforcement of a programming trap I should avoid in future, and punishment for selecting poor test cases. It’s not a bug of epic proportions, so move along if you have better things to laugh at than a bug in my Daily WTF-candidate code.

I threw together a simple booking calendar that uses a touch of JavaScript to make it a little more animated than a basic web form on cheapo PHP hosting. Part of the magic of this calendar is that it creates a string of the form “Your booking is for one night from Wednesday July 13th 2011, departing Thursday July 14th 2011” to help reinforce to the user that the correct dates have been understood by the booking system.

When I implemented this booking calendar it appeared to work nicely. Nonetheless, I wrote test cases for it. When there were plenty of tests and they all passed I was feeling smug that my JavaScript was probably provably better quality than most of the JavaScript in existence given it had tests.

It operated for a few months with no complaint. Then there were several reports in one week that the code wasn’t generating the correct weekday.

“Inconceivable!” I thought.

I tried it myself with the dates users complained about and found it was generating crazy weekdays. I checked, and my regression tests were passing just fine. I then plugged the reported problem dates into my test suite. My old test cases succeeded and the new ones failed.

So, down to diagnosis.

The “bulk” of the code is pulling the date string apart so I can use date-related utility functions. The problem was my use of parseInt().  

parseInt() parses a string and returns an integer. I discovered that it works fine for some months (01, 02, 03, 04, 05, 06, 07, 10, 11, & 12) and not for 08 and 09. This is because parseInt() assumes that if the string it is parsing begins with a 0, then it’s an octal number. That works for 01-07 because they generate the same number whether you parse them as octal or not. 11 and 12 work because parseInt() correctly guesses that they are base 10. 08 and 09 are automatically detected as octal, but they fail to parse as octal numbers. I used the error return value to populate the month in a Date object which dutifully interpreted the value as December. The weekdays were right… for December.

Sure enough, none of my test data contained a date in August or September.

The main fix is that the parseInt() function takes a second optional argument that sets the radix to use and stops it from guessing.

I’m still trying to think of a situation when you might want parseInt() to guess the radix for you.

Improved boot times: Vista vs Windows 7

I think it was Andrew who pointed me to Soluto as a method of improving boot times on Windows PCs.

I have mentioned before that my Vista-running X61 tablet takes a while to boot. Soluto measured boot time at just over 10 minutes. I followed its advice, and through delaying and removing various crapware and legitimate startup programs I got boot time down to 5 minutes and 10 seconds.

Emboldened, this weekend I took some advice from Ian’s comments on my last post and shelled out AU$300 for a copy of Windows 7 Professional (upgrade).

Now, with a few tweaks recommended by Soluto I’m recording a consistent boot time of 1 minute 35 seconds.

My aging tablet feels like new again (during boot).

Update: Actually, it feels pretty snappy since the Windows 7 makeover and some hybrid SSD drive loving. Boot time is now a shade under a minute and application launches are snappier than they’ve ever been.

iPhone 3GS

I can’t review my new iPhone 3GS. Frankly, I haven’t used it enough. I’m still waiting for my old carrier to port my number so I can use it as something more than a very expensive iPod Touch.

One of the first things I did after getting it was to sit down with a couple of our kids and show them the maps, video camera, photos, some Wall-E, Phineas and Ferb and then an iPhone version of Peggle which they had played on PC extensively.

When I had decided that demo time was over my 3 year old daughter insisted that the iPhone was hers. To encourage me to hand it over she started ripping up and throwing things around the house with some impressive, wanton, and very primal, rage.

This experience has brought me to the realisation that slavish iPhone desire is nature, not nurture.

I’m seriously considering buying a decoy.

A short review of Adobe Soundbooth CS4

It crashes a lot.

I’ve been using Soundbooth to clean up speech from about 10 people recorded in a conference room, on a tiny digital recorder, while it sat next to a projector’s fan, under an air-conditioning outlet, in a slightly echoey conference room, open to a common area where people gather to take the elevator.

Cleaning up the audio was a reasonably fast, if crashy, experience.

Once I had a reasonably clean recording I thought I’d try out the automatic transcription feature. This feature performs some cursory speech recognition on an audio file to produce tags that match recognised words to their location in the audio file along with the speaker’s identity (e.g. speaker 2). As it’s only 75% accurate (for my samples, forgivably, it was much worse) it’s more useful for finding points of interest in an audio file than as an auto-transcription service.

I don’t think it ever completed the transcription task. At some random point it would offer to send Adobe a copy of a crash report.

Though it doesn’t have transcription capabilities, I think I prefer Audacity.

Levelling up

Tomorrow, December 5th 2008, marks the 20th anniversary of my starting work in “the industry.”

This calls for five minutes of reminiscing.

I turned up for my first day of work as a trainee systems programmer at a big Australian bank’s EDP department. I recall being more than a little shocked at having to be at work before 8:06am each day. I was introduced to everyone I’d be working with shortly before being sent off to North Sydney to do MVS and IBM System/360 Assembler training for a few weeks.

At training I learned that the most powerful instruction in Assembly language was the no-op. The coding standard dictated that you sprinkle them throughout your code so that smarter programmers than you could patch your code, in memory, while running by overwriting your no-ops with useful code and then adding a statement to branch to the patch code over the defective instructions.

The bank had some great people. Some were consummate professionals and some were real cowboys.

Towards the end of my time at the bank I was introduced to the pointy-end of the economics of software development and process improvement.

A colleague returned from a long liquid lunch and let me in on the “big secret.”

He said only fools write good code. Code has to break for you to get called in. Being called in gives you overtime and visibility. Overtime is extra money. Being called in is heroism. Develop skill in writing bugs that are serious enough to call you in about, yet easy enough to fix soon after you get into the office. Overtime was paid for in four hour minimum units. Nobody notices people who write reliable code because they never get to perform heroic acts. Notice that the people who get promoted are those that handle high stress situations. Notice that the people handling these high stress situations are generally responsible for creating the high stress situation in the first place.

It was good motivation to find a new job.

iPhone application idea

Regrettably, I don’t have an iPhone. I do, however, have iPhone envy. I can tell, because I have dreams about accelerometers and iPhone apps I’d like. Also, I have nightmares about dropping my imaginary iPhone.

Given I don’t have the necessary equipment to develop an iPhone application, I hereby give you, The Internet, my idea for an iPhone application. My envy-inspired dreams have resulted in an idea for an App whose sole purpose is to add a little levity to those near-miss moments when you think you’ve accidentally destroyed your iPhone.

My imaginary app patiently waits for the accelerometer to report extreme acceleration events, such as when the phone has fallen to the ground. Shortly after the high-G event, the app plays an audio file that says “Well that was close!”

That’s it.

No additional logic is required for the case when the G force is so great the iPhone stops working. Those moments are best kept levity-free.

Our Apple TV experience

As mentioned previously, we recently acquired an Apple TV and a fairly standard 720p 66cm LCD TV.

What problem was I trying to solve?

After spending some time in the US, we have Australian and US iTunes Store accounts. For the last year the majority of our TV came from one iTunes store or another (mostly one). We grew tired of advertising and DVDs. J & I promised that when we gave up our roughly $100/month cable subscription a few years ago that if legal downloadable content became viable we’d be happy to pay at least half that amount on content we could select for ourselves, watch at our leisure, and enjoy without advertising.

We’ve also recently boxed a few hundred CDs and put them in storage. This came about after we realised we’d purchased a shedload of music, but only about one physical CD per year for about 2 years. We needed a more convenient method than an iTunes library on a NAS to access our music collection.

What’s good?


We’re paying to be hostages to iTunes DRM. It’s not great. We got over it.

Convenient and sexily-presented access to all of our music

It’s an always-on jukebox of all our favourite hits which is easier to use than a CD player and doesn’t become scratched and unplayable when handled by children or visiting Luddites.

Consumer-grade access to video content

Fewer hours spent fiddling with PCs or digging for DVDs. Just cursor around and watch. Bored? You can drop a few bucks on a hire movie and watch straight away with little chance of there being a big fingerprint on the final chapter that stops you from enjoying your purchase.

What didn’t I know before I bought it that I should have?

Hard disk size

I got the 160GB version, and not the 8040GB thinking that I had to be able to manually carve up our 220GB of content and I’d prefer to have as much of it available as possible to avoid having to make too many decisions about content. Truth is, you don’t really need to go overboard with hard disk space. I have about 40GB of audio, and when you set the Apple TV to decide what to sync for you, it seems to allocate enough space for my entire audio collection and uses the rest of the space on what video it divines I’m likely to want t watch.

Automatic sync settings

Automatic sync works by constantly updating the content of the Apple TV with the iTunes libraries on your network to try to make sure the content you care about is online when the iTunes libraries aren’t. If your iTunes library is online, the Apple TV shows the content of those libraries as available through the menu system and if you play something that isn’t on the Apple TV’s hard disk, it begins to copy the content onto its hard disk and starts playing when it’s confident there won’t be a break in transmission to re-buffer.

The bad?

Getting started

The Apple TV seems to be hard or slow to wake up after a rest. Often you have to poke away at the remote for 15-30 seconds to get it to display or utter the first "bloops" of evident wakefulness.

Very occasionally the Apple TV appears to thrash like a computer and be consistently unresponsive. Twice I’ve had to switch it off and on to restore sanity and responsiveness.

The resync

"While Apple TV is playing back video content, the syncing of content from iTunes is temporarily paused. Syncing will automatically resume shortly after you stop playing video content. " (

What this doesn’t tell you is that for some reason, when you’re paused in the middle of an Apple TV-purchased movie, your Apple TV also likes to do resyncs if you accidentally leave your iTunes running on another PC. I suspect it’s zealously syncing where you’re at in the movie so it can restart you from that point on any other iTunes instance. The problem with this is that resyncs while you’re in the middle of a TV show or a movie cause the Apple TV to become unresponsive or sluggish and stuttery for a time. It seems to take upwards of a minute to recover from a resync commenced when you paused a feature-length film. The unit becomes unresponsive, eating remote control clicks or misinterpreting them as click-and-hold commands. I typically spend some time after the Apple TV has recovered from sluggishness trying to find my way back to where I originally paused.

This is probably the biggest disappointment. It seems to me to be a bug. Resyncs should be transparent to the user of the Apple TV and certainly shouldn’t affect usability or response time. Fingers crossed for a fix.

"Automatic" sync almost works as I’d expect

With Automatic sync the Apple TV loads up on video content you haven’t watched yet and content you have watched tends to be deleted to make way for new content. The downside of this for us has been kids’ content. We have Dora the Explorer on high rotation, and the Apple TV liked deleting Dora in favour of other content. Now that Dora has been watched a few hundred times Apple TV has taken the hint, but having to boot up a PC to get Dora on the air was a little more tiresome than I expected. It would be nice if you could explicitly hint that you’d like to prioritise some content for caching on the Apple TV.


Apple TV is visually polished, extremely well integrated with all things iTunes, yet suffers the same poor responsiveness of other computers that pretend to be HiFi equipment (I’m lookin’ at you Media Center PCs). It’s not as polished and predictable as I expected.

On the whole, as an iTunes-dependent family we’re hooked and find it indispensable. Without an iTunes addiction it wouldn’t make a lot of sense.

Fossilized Amiga bones

I was foraging around in some old boxes when I found a small collection of things that used to be in Amigas I have owned.

Here’s what might be the original Motorola 68000 processor from my Amiga 1000:

Motorola 68000 processor

I believe this might be the processor I swapped out for a 68010 in a vain early attempt at a speed upgrade (the Amiga 1000 was architected to be synchronous with PAL and NTSC video frequencies so overclocking wasn’t even a dream back in the day).

I recall severing one of the pins during some overenthusiastic and too-frequent brain transplanting, but the one you see above is bent up a bit yet doesn’t have any missing pins. It’s in better condition than my own brain’s recollection of where this processor came from, it seems.

The 68010 was mostly indistinguishable in performance from the 68000 and screwed up many of the games of the day, possibly because of their reliance on the 68000’s loop speed as a precision timing mechanism. I used to pop it in and out while I was searching for the 68010 emperor’s new clothes.

Eventually the 68000 and 68010 gave way to a 16MHz 68020 & 68881 LUCAS board, which provided excellent bang per buck in terms of performance and ram upgrades, and allowed the 68000 to be switched back in for games compatibility.

This is the “Agnus” chip from either my Amiga 2000 or someone else’s Amiga 500:

Commodore Amiga "Agnus" 8371 chip

This was the chip responsible for most of the bling in typical Amiga graphics demos. It contains a hardware blitter, video coprocessor, DMA controller, and a bunch of other functionality. I can’t recall the fault, but I can recall that replacing it made life a little better.

I believe this is the Intel 8088 (actually made by Siemens) that occupied the strange little expansion box called an Amiga Sidecar:

Intel 8088

The Amiga Sidecar was an IBM PC clone in a box that, as you can tell from the Wikimedia image, did not make the Amiga any prettier, but it did provide an inconvenient and expensive way to run PC programs and a relatively inexpensive route to hard disk capacity. If I recall correctly the PC ran independently but through “Janus” software the PC screen was accessed through a program running on the Amiga Workbench. There were also a bunch of utilities for sharing data and text between the two computers.

The processor above was supplanted by the almost perceptibly faster NEC V20 processor.

SCSI controllers and drives were insanely expensive, if technically superior, when the Amiga 1000 was ascendant. With a Sidecar you could get a relatively cheap PC hard disk controller and PC hard disks to share with the Amiga side.

All of this brings painfully to mind the startup scripts that I used to write and debug to deal with booting from a floppy, and handing off to the hard disk with subtle timing and software incompatibilities between booting with the Sidecar and LUCAS boards in different modes.

Is Optus making iTunes Music Store usage unmetered?

I’m going out on a limb. I think Optus is going to be giving more than just iPhone users unmetered access to Apple’s Internet properties.

Yesterday I downloaded Season 2 of the best TV ever.

Best TV Ever, Season 2

Thankfully HBO have been gradually adding seasons of The Wire to the US iTunes Music Store, and I’ve been buying them and making my way through them.

I was a bit concerned with how big a season is. 7.5GB is a good chunk of my 30GB quota. Not too big a deal but last month iTMS Daily Shows & Colbert Reports, work VPN and random tinkering put me over the 20GB mark.

I checked the Optus web-based usage meter how much of my quota I had used in the first 5 days of July: About 2.5GB.

I set off and downloaded four episodes. About 2.5GB of files. When they had finished downloading I waited a couple of hours and went back to check the Optus usage meter. It had registered 259MB of activity. Maybe it was being particularly slow to update. Anyway, I downloaded the remaining 5GB, watched two episodes and went back to check my usage: 3.8GB.


Because I needed to put one of my Office 2007 Home licenses on the kids’ PC, I downloaded it (298MB) and checked usage again: 4.1GB and holding steady.

7.5GB of “The Wire” from iTunes cost me about 1.3GB in usage quota. 298MB of installer from Microsoft (via Digital River) cost me about 298MB of quota.

Cue Twilight Zone theme.

I’ve hunted through my contract and I can’t see anywhere where it says Apple is some Internet usage metering haven. My only explanation is that Optus can’t, or won’t, just give iPhone users free access to Apple Internet resources and they’re engineering their network to treat everyone like an iPhone user.

I can’t think of any explanation for why Optus is charging me somewhere between full rate and zero in quota. Is there something I’m missing? Secret Optus brownie points for not using BitTorrent? Most people who complain about the Optus usage meter say it over-counts their traffic.

Tablets, Tablet PCs and software development

For a long time I thought that if I were better able to quickly construct illuminating diagrams to make a point or communicate a concept then I’d be a much more effective communicator. Effective communication is a boon to software development, so improving my ability to rapidly pump out neat diagrams was a noble goal worthy of investment.

I thought that if I had a tablet I’d be able to pick up any drawing package and quickly render those few boxes, circles, arrows, classes, use-cases and swimlanes with a pen in double-quick time. Surely a pen is the natural way to draw, and therefore faster and easier.

I had my eye on a Wacom tablet for a while. I had used a few casually and found them awkward. Designer friends told me that it takes some getting used to and a rigour about the way you set up and use applications. I had also worked with a UK-based engineer who used one for illustrating and annotating shared applications, presentations and documents during design collaboration conference calls. I was convinced my first impressions were wrong.

“Cool” I thought. “Let the tablet-led communication-effectiveness and R&D begin!”

After I saw that Julian had a tablet, I abandoned rational thought and cool-headed evaluation while toy envy took over. I dropped about AU$100 on a cheap Wacom-like tablet to figure out if it was a worthwhile addition to my professional and home-tinkering life.

After getting used to looking at the screen and not the tablet, and making the mental switch from mouse-relative pointing to tablet-absolute positioning seem relatively natural I worked on using a few applications.

In a week or so of trial use I came to the following conclusions:

  • EverNote is way cool for doing shape-drawing, but I was still about half as fast at constructing diagrams with the tablet as using a mouse and keyboard. I also made lots of mistakes with the tablet that were kind of painful to correct. I wish more applications had EverNote’s (and the Apple Newton’s) shape recognition/fixup mode.
  • Visio is kind of awkward with a mouse, and even more awkward with a pen.
  • Few applications have big enough icons that can also be positioned conveniently enough for tablet use.
  • Unsurprisingly, the best applications are painting programs like Photoshop and Paint Shop Pro. Primarily it’s because with a tablet the curve you render on the tablet is the curve you see on the screen. With a mouse, you have to convince your body to implement a kind of feedback and control system to modify your physical action to produce the curve you want to render.
  • Tablets are cruel and frustrating.

I gave up on the Wacom-style tablet, though I’m not sure that I gave it a fighting chance. I got to a point where my frustration was greater than the residual value of my AU$100 investment and abandoned it.

Time passed… and the opportunity to get a tablet PC at less than extortionate prices presented itself. Quite apart from the X61 being a tablet PC, it’s far more portable and usable than any laptop I’ve owned since my Mac PowerBook 170.

In summary, in the contest between tablets and tablet PCs, tablet PCs win.

Direct manipulation of screen pixels is much more approachable than separate tablet hardware. They’re more portable, convenient for more applications and they don’t get your colleagues confused about whether you’re a graphic designer or a developer.

That’s not to say tablet PCs are the perfect tool for diagramming.

Bear with me while I offer some completely un-benchmarked productivity estimates.

When it comes to drawing diagrams with perfect boxes and lines in an application like Illustrator or Visio, I’m about 20% faster with a mouse. If the requirement is for nicely typed text, then the mouse and keyboard wins by about 50% over the tablet PC.

But there’s a diagramming mode where the tablet PC shines: freehand diagrams.

If the boxes, lines and arrows don’t need to be perfect, and if the text is handwritten, and if the diagram won’t need to be maintained, then drawing freehand using OneNote or EverNote on the tablet PC is probably 50% faster than using a keyboard and mouse.

After recognising this my primary use of the pen mode on my X61 Tablet has settled into these tasks:

  • Quick and dirty diagrams to capture notes or communicate information, often projected on a meeting room display or web conference, and sometimes to be later transcribed into a “proper” UML tool or Visio.
  • Annotation of documents, spreadsheets and presentations with Office 2007’s pen reviews.
  • Note-taking & annotation of typed notes.
  • Painting.

For me personally, the dream of being able to use any illustration package more effectively with some kind of tablet is gone, yet note-taking with freehand illustrations is something I now find indispensable.