From: Twylite <tw...@cr...> - 2008-12-02 09:21:20
|
Further feedback on error matching: It looks like glob matching is not going to cut it. List prefix matching will be a similarly-powerful and generally safer approach. Looking at the functionality of other exception matching systems, we can see that Java (with single inheritance) is the equivalent of matching against a tree, and C++ (with multiple inheritance) is the equivalent of matching against a Directed Acyclic Graph. Neither string matching nor list prefix matching nor element-wise list matching give the functionality of a tree match. Example: In Java you may define a MyIOException extends IOException (extends Exception extends Throwable). Code using your API will catch (MyIOException e) { // handle it } You can safely subclass MyIOException and throw these subclasses without breaking code that catches MyIOException (as in the example above). You can also safely introduce a new superclass between IOException and MyIOException (MyCompanysGenericIOException) without breaking code that catches MyIOException. In C++ you could introduce a completely new base class to MyIOException via multiple inheritance, without breaking existing code. With glob/list/prefix matching you can support either subclassing or superclassing the error, not both, and not MI. You cannot use glob/list matching safely to allow for superclassing (don't got there -- think of the pattern "Throwable * FormatException *" and how many third party APIs are going to have something called "FormatException" and you'll understand the folly of this approach). So while element-wise list matching may SEEM really powerful, its just a knapsack with a big gun and rope. Similarly a glob match may seem flexible, but in most cases its going to be used a prefix match, and often used incorrectly such that it prevents subclassing of errors in future. So, in the absence of an approach to tree/DAG matching, a list prefix seems like the most sensible option. More to come. Regards, Twylite |