To interface or not to interface

Walter Bright newshound1 at digitalmars.com
Wed May 26 12:20:51 PDT 2010


Jason House wrote:
> So you're favoring an isXXX as well as a requireXXX?  Such duplication is
> both annoying and error prone. Making isXXX use requieXXX under the hood
> ishigher implementation complexity. I don't know about others, but I was
> drawn to its simplicity over C++. Many have praised its ability to make
> template programming simple. This feels like a step backwards.

In C++, the concepts design died. There's nothing you can do in C++ about the 
bad error messages. Furthermore, compile time error checking in C++ is limited 
to types. If something cannot be expressed as a distinct type, it cannot be 
checked in C++. (BTW, interfaces in D have the same problem, you can only check 
the type with them. With templates, you can check behavior and other 
characteristics.)

The fundamental problem is a compiler can only see a worm's eye view of what a 
component is supposed to do. There's no algorithm in the world that can take a 
block of code and have the compiler figure out that this is a hash map 
collection class, and give lucid error messages in those terms rather than low 
level operations.

As a component designer, however, D gives you the ability to detect usage errors 
at compile time in ways that go far beyond just type errors, and inform the user 
about them in high level terms.

You're right in that D doesn't do this automatically, just like a browser cannot 
automatically make attractive web pages. You as the component designer have to 
write the code to make it work the way you want.


More information about the Digitalmars-d mailing list