Tuesday, August 30, 2005

More on Canon

This Business Week article includes a quote from the S&P 500 analyst who recently downgraded Canon: "'Canon has been one of the few electronics companies able to maintain double-digit margins, but [Canon's second-quarter operating profit] shows that even Canon isn't immune to price pressure,' says John Yang". The other concern seems to be who might replace CEO Fujio Mitarai, who is 69.

According to SmartMoney.com's DCF calculator, Canon's current price assumes about 1.5% earnings growth. The article suggests 6 to 7% growth which works out to about $60 an ADR. Given more productivity gains and a return on the company's R&D investment, I think Canon is a good value.

Thursday, August 18, 2005

Writing good error messages

A good error message should say:

  1. What the program was trying to do.
  2. What it expected to have happen.
  3. What actually happened.
This is the same requirements of a good bug report, except that there is no need to show the code used. And actually, the location of the code (source file and line number) should also be included in an error message unless it's completely obvious. This is such a common requirement, many systems include source location automatically:

$ perl -e 'die' Died at -e line 1.

The more difficult thing, surprisingly, is knowing what errors to report. Most system errors should be reported, but not if the code tries to work around the problem.

Wednesday, August 17, 2005

Bad error messages

Error: can not locate file....

What am I supposed to gain from reading that message? Any information at all would help. What file? I know the program must know what file it tried. Why the ellipsis and the "Error: " string? This error resulted from a failed stat call, which normally means the file doesn't exist. But what if it were a permissions problem or a self-reference symlink or the path argument exceeded PATH_MAX? That's why we have errno and strerror.

Fortunately I had access to the source and changed it to:

Can not stat /path/to/file: No such file or directory

The orignal code made this more difficult by using this custom function:

int error_msg(char *error)

I know varags is a pain, but it really does have a place. There is no reason error messages can't provide more than enough information to debug any problem.