Contract clarification
Posted: Wed Feb 17, 2010 11:31 pm
Cobra has support for contracts which are declared with keywords like invariant, require and ensure. The last two are used on methods and also known by the names preconditions and postconditions.
I want to clarify that contracts are considered part of the public interface of a type and they should not refer to local variables in methods. Instead, contracts refer to:
-- the state of the object
-- the arguments (especially for require/preconditions)
-- the "result" (for ensure/postconditions only)
If you want to verify something about your local variables such as "x < y" then feel free to use assert in the method's implementation.
Currently, Cobra lacks error checking for usage of local vars in contracts, but I'll be adding one soon.
If you want to read more about contracts, check out the HowTo and this forum thread which links to some reading material.
I want to clarify that contracts are considered part of the public interface of a type and they should not refer to local variables in methods. Instead, contracts refer to:
-- the state of the object
-- the arguments (especially for require/preconditions)
-- the "result" (for ensure/postconditions only)
If you want to verify something about your local variables such as "x < y" then feel free to use assert in the method's implementation.
Currently, Cobra lacks error checking for usage of local vars in contracts, but I'll be adding one soon.
If you want to read more about contracts, check out the HowTo and this forum thread which links to some reading material.