Future of contract-based programming in D

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 7 11:30:15 PDT 2015


On Tue, Apr 07, 2015 at 06:20:06PM +0000, w0rp via Digitalmars-d wrote:
> I'm a big fan of contracts, and for me it's one of the D features I
> love.  The syntax really doesn't bother me. Given the rest of the
> syntax in the language, it's not possible to reduce it much further.
> Then again, I'm not one to care about syntax too much anyway. I tend
> to care more about semantics.
> 
> I think if you don't like contracts, they just take some getting used
> to.  After you use them enough, you might find yourself writing
> contracts quite a lot. As far as bugs with contracts and classes go, I
> don't know. I don't write many classes or interfaces in D myself.

D doesn't force anyone to use contracts, but they're there for people
who want/need to use them. I'm not a DbC person, but I do use D
contracts every now and then as a safety measure in my library code, to
prevent accidental regressions or API misuses.

The current DbC implementation is a little disappointing in some areas,
though, which limits their usefulness in serious DbC use cases. One
especially annoying one is the fact that contracts are compiled and
linked into the callee (library) rather than the caller (user code),
meaning that an optimized, release build of your library will not
contain contracts, whereas shipping the library with contracts means the
user can't turn them off even if they compile with -release.
Fortunately, I'm not a big DbC user so what D currently has is Good
Enough(tm) for me.


T

-- 
Life would be easier if I had the source code. -- YHL


More information about the Digitalmars-d mailing list