Suggested Change to Contract Syntax

FatalCatharsis via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 10 15:31:22 PST 2016


On Thursday, 10 March 2016 at 22:57:41 UTC, Jonathan M Davis 
wrote:
> I don't think that out contracts are worth much anyway, since 
> in almost all cases, unit tests do that job already, and it's 
> usually much easier to write test that specific input gives 
> specific output than it is to have a general test at the end of 
> the function.

This is a very good point. I was already using unittests and I 
guess they make 'out' contracts redundant considering that you 
are ensuring the result of a function is correct anyway.

> If/Once we get more features in the compiler which take 
> advantage of contracts, then I'll likely change my tune on that 
> one, but for now, IMHO, they're really only of value in classes.

I'm curious, what kind of features might come out of contracts in 
the future? They seem somewhat helpful in terms of QA and 
organization, but what kind of compiler or performance gains 
could you gain from this system?

I'm going to take your advice and just stick to assertions at the 
beginning of the function and unittests to verify correctness of 
output. I'm already overjoyed with the easiness and integration 
of the unittest system as it is :) .


More information about the Digitalmars-d mailing list