Saturday, December 1, 2007

On Handling Errors

I don't like to create accounts just to leave comments in other people's blogs, so I answer them here. The Catty Critic asks about error handling when writing code, and the rule (my rule, the rule, same thing) is surprisingly simple (and probably unoriginal by now):

Don't attempt to handle errors you don't know how to handle. You'll only mess things up.

Her specific question is about a subroutine that was passed a value it wasn't prepared to handle. The only correct way to handle this error is to write code that patches the caller code to make sure it doesn't happen again. This being next to impossible, the next best thing is to alert the programmer to fix it - by crashing or some other spectacular failure.

Let me repeat: handle only errors that you expect and know what to do with. Don't pretend you know what to do with every little thing that may potentially go wrong. Because that's my opinion.

Tuesday, November 13, 2007

Good Thing!

A sure sign that you are a third world country is when high officials have to do very tedious things. For example, following an apparent bombing at the congress that killed a congressman, President Gloria Macapagal-Arroyo of the Philippines had to order the authorities to hunt down the perpetrators, and directed government doctors to help all the victims now being treated in various hospitals.

Good thing they have a president. Otherwise the police would just watch when congress is bombed, and the doctors will just gaze sympathetically at patients.

Saturday, October 13, 2007

Sakura Wars Figure II

This is Iris Chateaubriand, another figure from Sakura Wars. The figure is much smaller than the one of Shinguji Sakura, so the gloved hands are not molded as well. The arms also don't fit very well in their sockets, for some reason.

Spared the Knife

I had been reading a book called Coronary: A True Story of Medicine Gone Awry by Stephen Klaidman. The book digresses a bit too much for my taste, but his documentation of two doctors who performed hundreds of grossly unnecessary heart operations was just bone-chilling.

I was also supposed to be undergoing oral surgery to have my wisdom teeth removed, and since my consultation was over a year ago, they required me to get a fresh one before the operation. The surgeon looked me over, and said that I didn't need it. I didn't have major problems (such as pain or decays) with them, and I am apparently in a 15% segment of population with enough jawbone space to hold them. He decided that the loss of chewing surface wasn't worth the gain, and sent me home, turning away at least a couple of thousands dollars for the clinic.


Friday, August 17, 2007

Are You Old?

The Compact Disc turns 25 today. Its creator Philips estimates that 200 billion have been sold worldwide. At 1.2 mm thick each, this means that if you stack them all up they'll form a plastic cylinder 240,000 km high, quite a bit more than halfway to the moon.

But more importantly, if you remember the CD as a new thing, ha ha, you're old.

Sunday, August 12, 2007

Why United Is Doomed

So for no real reason at all, I gave United Airlines a chance when considering an upcoming trip. Here's what it thought was a good idea when I allowed it to consider all San Francisco area airports:

It wants me to fly from San Jose to Los Angeles, and then back to San Francisco. SJC, for those who don't know, is 33.8 mi (54.4 km) away from SFO, perhaps 45 minutes' drive in moderate traffic.

What if I just catch the SFO-TPE flight like a sane person would? Well, avoiding the idiotic 6-hour-long SJC-LAX-SFO side trip will cost me US$44 more.


Friday, June 29, 2007


The iPhone starts shipping today. I warmed up to it slowly, but it really is a pretty awesome product. Ratatouille also opens today, and Mabel and I hope to catch it tonight.

Oh, and Brent, if you still had a job, maybe you'd be able to afford a real iPhone, too. Pffft.

Wednesday, February 28, 2007

Some Cheese With That?

Shaquille O'Neal just became the seventh player in the NBA to have scored 25,000 points and grab 10,000 rebounds, but his team still lost the game to the New York Knicks, 93-99. After the game, he lamented, "I am kind of disappointed in myself because if I make free throws I'd be at 30,000 rather than 25,000." O'Neal has attempted 9,826 free throws in his career and missed 4,642 of them.

I'm a pretty bad basketball player, Shaq, but even I know that unlike many things that life deals you, free throws are something that you can dramatically improve with practice. So stop being a baby, and go practice.

Friday, January 26, 2007


We went to the naturalization interview on Wednesday. We arrived early, but I lined up at the wrong entrance so ended up one minute late upon check-in at the reception desk. And then waited for maybe 45 minutes for a short interview, in which the most difficult part (no, really) was writing my name in cursive letters. You see, I haven't really written in cursive for nearly twenty years (I blame Lindsley), and the two signatures didn't really look alike.

No matter, we passed (actually, aced) the test and will become US citizens when we swear in next month. To celebrate, we had dimsum at Yank Sing. Somehow I don't really feel American yet, whatever that's supposed to feel like. My colleagues tell me now I can be partially blamed for everything.

Thursday, January 11, 2007

Absolute and Relative

Something I just realized while looking around for reactions to the iPhone. Geeks are appreciative of history, and therefore are concerned about how innovative a new product is over existing ones. Normal people are more concerned about whether the new product meets a certain absolute threshold of quality, usability, price, and other factors. If it does, they'll buy one even if it's just 2% better than existing ones.

Geeks see it as a mere 2% better than existing alternatives. Normal people see the existing products as 1% below their expectations, and the new one as 1% above.

Tuesday, January 9, 2007

The iPhone Cometh

The iPhone was announced today at the MacWorld keynote, so I was looking around for reactions. On I find this gem:

I surf the web on my 1 inch ms smartphone now, and it works fine.

If it did I'd still be working for Openwave. I didn't have much to do with the iPhone, though.

Monday, January 8, 2007


According to dnScoop, is worth US$874! Let's see what some of my friends are worth:


Tom is the man!

Complete Your Classes

One important feature of C++ and other object-oriented languages is the grouping of code and data into "classes" or "objects." They have language structures that allow a user-created type to behave just like a built-in one, but it requires that the writer of the class fill in all the blanks.

One such blank in C++ is the copy constructor. It is the responsibility of the writer of the class to provide one, even when you cannot imagine when it will be needed. If you don't, then somebody who doesn't have intimate knowledge of the class may have to write one later, and that's where mistakes are easily made. There are probably a few exceptions (a singleton, or a class for which a shallow copy will do, would certainly be exempt), but have a better reason than just laziness. Forcing your users to peek into your class to figure out how to make a copy of it destroys the whole point of encapsulation, because your class is no longer a black box that just works.