A
Andreas Leitgeb
There were recently some threads in which "assert" occurred,
and which raised a question in me about whether it would
be useful to have nested code blocks executed if and only if
the code was compiled to also do "assert"s.
e.g., I could already do this:
assert myDebuggingMethod();
and have a new method myDebuggingMethod(), that doesn't
do anything relevant to the algorithm itself, but does
some costly gathering of data to determine if the program
is still working as intended.
If this myDebuggingMethod() needed to read some local
variables as well, I'd have to pass each as an argument
to the method. Not to mention that the checking code
itself would not be in eyesight at the spot where it
would be (probably solely) used.
If there were a feature like:
debug {
int check;
// some costly code to determine some supposed invariant
assert check==42;
}
and the whole block would be compiled or ignored by the same
criteria as assertions are now, then I think this would be useful.
Has something like that been discussed already, did I miss
some strong arguments against it? Does anyone happen to agree
on its usefulness?
and which raised a question in me about whether it would
be useful to have nested code blocks executed if and only if
the code was compiled to also do "assert"s.
e.g., I could already do this:
assert myDebuggingMethod();
and have a new method myDebuggingMethod(), that doesn't
do anything relevant to the algorithm itself, but does
some costly gathering of data to determine if the program
is still working as intended.
If this myDebuggingMethod() needed to read some local
variables as well, I'd have to pass each as an argument
to the method. Not to mention that the checking code
itself would not be in eyesight at the spot where it
would be (probably solely) used.
If there were a feature like:
debug {
int check;
// some costly code to determine some supposed invariant
assert check==42;
}
and the whole block would be compiled or ignored by the same
criteria as assertions are now, then I think this would be useful.
Has something like that been discussed already, did I miss
some strong arguments against it? Does anyone happen to agree
on its usefulness?