concepts and interfaces

James Dennett jdennett at acm.org
Tue Apr 10 20:15:01 PDT 2007


Don Clugston wrote:
> James Dennett wrote:
>> Craig Black wrote:
>>> This may sound a little retarded, but wouldn't making concepts
>>> obligatory make generic programming more complex and hence more
>>> difficult?  In my opinion this may do more harm than good.  A huge
>>> appeal of generic stuff in D is that it's easier to work with than
>>> the C++ stuff.  More powerful, yes, but also easier.  IMO this is
>>> very important.
>>
>> Concepts appear to make generic programming simpler and
>> hence easier, with more meaningful diagnostics.
> 
> But I think Craig's point is valid (and interesting) -- concepts will
> have a huge benefit for complicated C++ template code, but since D
> templates are easier to work with already (and we have static
> if/is/static assert), in D, concepts are at a totally different point on
> the cost-benefit curve. Are they still worthwhile?

I don't have enough D experience to speak authoritatively,
but the improvements made to C++ by concepts don't have
much to do with syntax (which is largely where D improves
on C++'s templates).  The big benefits are (a) a compiler
can verify that generic code only uses the interfaces it
intended to use, so that it does not accidentally place
additional burdens on client code, and (b) a compiler can
test from the specified required concepts that template
arguments passed by a client are suitable, and can give
very concrete diagnostics if not.  It would seem to me
that both of these benefits would map directly across to
D, though D's explicit support for metaprogramming would
tend to mean that the error messages it produces in the
absence of concepts are not *as* convoluted as those
generated by significant uses of TMP in C++.

-- James



More information about the Digitalmars-d mailing list