4 ms·
The mentioned technical paper about assertions states: "The assertions are primarily of two types of specification: specification of function interfaces (e.g.
by jraedisch 12y ago
The mentioned technical paper about assertions states:
"The assertions are primarily of two
types of specification: specification of function interfaces (e.g. consistency between arguments,
dependency of return value on arguments, effect of global state etc.) and specification of
function bodies (e.g. consistency of default branch in switch statement, consistency between
related data etc.)."
from http://research.microsoft.com/pubs/70290/tr-2006-54.pdf http://research.microsoft.com/pubs/70290/tr-2006-54.pdf
Is there somebody here, who could elaborate on this, ideally with some small examples?
- qznc 12y agoYou want to have examples for assertions? Consistency between arguments: memcpy "The memory areas must not overlap." Dependency of return value on arguments: max returns one of its arguments. r = max(x,y); assert (r == x || r == y); Effect on global state: printf might change the global errno variable.
- jraedisch 12y agoSo this means embedding small tests into the production code itself while accepting minor performance loss? And you somehow get a feeling for when this will help through experience? I wonder, whether this impacts all programming languages the same.
- qznc 12y agoIt is not necessarily about runtime tests. Often assertions are only used for debug builds. Java requires an extra flag to enable assert statements. Alternatively, assertions could be invariants or pre/post conditions for your formal proofs of correctness. I'm too lazy to check the actual paper, if they clarify their understanding. ;)