enforce()?

bearophile bearophileHUGS at lycos.com
Sat Jun 19 13:55:19 PDT 2010


Sorry for not answering before, I was quite busy (despite in the meantime I have written few posts and bug reports).

Thank you to all the people that have answered in this thread, and expecially Walter that has given the first answer that I have understood in the thread.

In the beginning I didn't like the enforce() but now I can see that it's meant for a quite different purpose. I was also worried of possible negative performance impact coming from its so widespread usage in Phobos.


Regarding the exception hierarchy I think I agree with Leandro Lucarella. A deep and complex exception hierarchy can be negative and overkill, the opposite extrema, that is having zero specialized exceptions in Phobos, is bad. Using just single-exception enforce() is bad, there is a small number of well chosen exception types (organized in a flat or mostly flat list) that are useful to have.

In my dlibs1 I have defined a flat list of few exceptions that I used:

ArgumentException     
EmptyException        
ExceptionTemplate     
IndexException        
IOException           
KeyException          
MissingMethodException
OverflowException     
RangeException        
UncomparableException 


Inside Phobos2 I have counted about 160 usages of the "body" keyword. I think contract programming can be used more often inside Phobos2 (and maybe some usages of enforce() can be turned into contract programming because they are more similar to program sanity checks).

Bye,
bearophile


More information about the Digitalmars-d mailing list