A problem with D contracts
Jonathan M Davis
jmdavisprog at gmail.com
Sat Jul 31 20:33:34 PDT 2010
On Saturday 31 July 2010 19:47:10 bearophile wrote:
> Automatic verification of contracts is an important feature, that can be
> made much harder (or impossible) to implement if contract contents aren't
> clean and simple. Putting print statements inside contracts is just wrong.
> As in future probably a second documentation system will be added/used
> to/in D, a second unit-testing system too, probably eventually a second
> contract system too will be added/used, because the built-in ones are not
> designed in a serious way, all three of them are just toys :-) "keeping
> their usage simple" doesn't hold when they lack essential features (I have
> discussed about missing parts in unittest system recently).
Actually, truth be told, I wouldn't consider automatic verification to be all
that important at all - particularly because it would be so hard to do ands so
few people would likely use it. I totally agree that it would be a good feature,
but I doubt that it's one that will ever materialize - or if it does it won't be
any time soon. Besides, if you assume that contracts are pure or have something
that verifies that they are, then you could still do those checks. Enforcing
purity would be a serious impairment. Putting print statements in contracts for
debugging purposes is a major and positive feature. Now, I agree that outside of
debugging a problem print statements have no business in contracts - they
certainly shouldn't stay there longterm - but it would impair debugging to
disallow them.
I really don't understand what your problem with contracts or unit testing is.
What we have works quite well. I'm sure that it could be improved, but it works
well. And honestly, I don't see automatic verification as being particularly
practical or useful any time soon - not to mention that it wouldn't be all that
hard for you to have assertions in there that couldn't be verified statically
anyway. What we currently have is extremely practical and does its job.
What we have in D is a major step forward, and with D2 stabilizing, you're not
going to get it changed in any big way. And in this particular case, I really
don't think that you're going to win any arguments - certainly not with folks
like Walter or Andrei. Purity in contracts is definitely not one of the goals,
and IIRC it has been explicitly stated by Walter and/or Andrei that enforcing
purity in contracts would be bad for D.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list