Suggestions how to use contracts
Aarti_pl
aarti at interia.pl
Thu Aug 30 02:06:18 PDT 2007
Hello!
I have a difficulty with defining strict boundary between
preconditions/postconditions and regular errors throwing by function.
Can you share your strategies? How to divide checks in proper way,
remembering that preconditions and postconditions are stripped from code
in release mode.
Example:
class Evaluator {
public:
int evaluate(char[] expression)
in {
assert(expression !="");
assert(m_active);
}
body {
}
private:
bool m_active;
}
Function evaluate can be called only when m_active is true. Should this
condition be checked from preconditions block or from body block with
if (!m_active) throw new Exception("Evaluator is not active.");
"m_active" depends on some other logic, either set by user or by other
classes.
BR
Marcin Kuszczak
(Aarti_pl)
More information about the Digitalmars-d-learn
mailing list