To interface or not to interface

Jason House jason.james.house at gmail.com
Mon May 24 15:52:43 PDT 2010


Walter Bright Wrote:

> Steven Schveighoffer wrote:
> > I'd ask the naysayers of interfaces for dcollections, and also the 
> > supporters: what is the point of having interfaces in D?  Are interfaces 
> > pretty much obsolete, and I am just nostalgic about their utility?
> 
> Interfaces are for runtime polymorphism, rather than compile time polymorphism. 
> They are especially useful for things like:
> 
> 1. runtime plugin interfaces
> 2. designs where strict implementation hiding is desired
> 3. to have binary libraries (shared and static)
> 4. to support Java/C# style coding
> 5. reduced code memory footprint
> 6. experience shows they are an excellent fit for user interfaces

7. Compiler-assisted verification.

 
> Compile time polymorphism, such as what templates provide, are most useful for:
> 
> 1. maximum performance
> 2. minimal data memory consumption
> 3. better compile time checking
> 
> 
> I believe the tradeoffs for collection types favor compile time polymorphism 
> because:
> 
> 1. performance is often critical for collections
> 2. C++ STL has shown the success of this approach
> 3. collections must fit in naturally with ranges, and ranges are compile time 
> polymorphic

How does error message quality compare between failing to conform to an interface verse conforming to an isXXX template? Anything that increases the time gap between code writing and code verification is bad. Does Phobos consistently use an isXXX template-based self-check that other writers of ranges can copy? Certainly, inheritance syntax is easier in this regard.



More information about the Digitalmars-d mailing list