To interface or not to interface
jason.james.house at gmail.com
Tue May 25 06:03:34 PDT 2010
Walter Bright Wrote:
> Jason House wrote:
> > 7. Compiler-assisted verification.
> For interfaces, the compile time checking is limited to verifying that functions
> with the right signature are supplied. Templates can go considerably beyond that
> with the constraint checking.
constraints are more powerful, but they have downsides:
If a class is incorrectly defined, failure to use a type without a constraint check leads to errors in the code using it instead of the class definition. Usage isn't always guaranteed to be correct either, so the developer must spend extra time diagnosing the real error.
If a class is incorrectly, initial usage without a constraint may completely miss the error. Easy examples would be a typo propogated with copy/paste, or neglecting to use save.
If a class is incorrectly defined and usage uses a constraint, the developer will simply get an error that there is no matching call.
If a constraint is incorrectly defined and usage uses the constraint, the developer will simply get an error that there is no matching call.
None of these scenarios are particularly helpful for a developer creating/expanding a family of objects.
PS: The use of the word class above is for clarity instead of using type or object. I could have said struct as well.
More information about the Digitalmars-d