| 
     
      
      
      From: Twylite <tw...@cr...> - 2008-12-01 19:40:02
      
     
   | 
Neil Madden wrote:
> Thanks for this. I think it looks good -- covers the basic cases and 
> isn't too complicated. I still have some reservations about 
> glob-matching as the only option, but it'll do.
You and me both ;)
In all seriousness, I've already encountered some situations that lead 
me to believe there will be teething problems, and some careful thinking 
about what conventions to adopt for -errorcode.
Case in point: we have an API for accessing a hardware coprocessor 
(let's call the API "ABC").  The coprocessor returns numeric error 
results in the range 1 to 99.  So we defined the -errorcode to be [list 
ABC $errnum], e.g. "ABC 4".
A little while later we realised that error 4 is quite special -- it is 
allowed to return an extended error information field (the coprocessor 
had to maintain the use of error 4 for backwards compatibility, but 
there were times when knowing the exact cause was important).  So we 
extended the -errorcode in this case to [list ABC $errnum $extra], e.g. 
"ABC 4 F".
So two hours in this is the position: Any "trap {ABC 4}" no longer 
works.  Changing this to "trap {ABC 4*}" won't work either because it 
will also trap errors in the range 40-49.  Using "trap {ABC 4 *}" will 
work, but would be incompatible with the older version of the API - 
that's not a problem right now because we can do a simple find & 
replace, but if you're intending to maintain the API over a long period 
of time it would be an issue.
A glob against errorcode doesn't work like an OO is-a relationship.  You 
can't arbitrarily subclass the error and maintain compatibility unless 
you plan for it.  That means that you must always have a "*" in the 
glob; most likely you'll be doing a prefix match.  It also means that 
your errorcode must end with a delimiter (like a space) so that you can 
distinguish between classes and subclasses of error (so that "ABC 4 *" 
can only be a subclass of "ABC 4", and not confused with "ABC 42").
My 2c.
Twylite
 |