----boundary-LibPST-iamunique-442727410_-_-
Content-type: text/plain
On Mon, 12 Jun 2006, Marco Ciot wrote:
> The intention of the programmer when placing an ASSERT should never be to
> halt the program at that point but to assert some important condition for
> the subsequent program code.
What do you mean by "assert some important condition"? What should a
program do when the assertion fails? Right now it halts. If this is not
what you want, then what action are you proposing instead?
> AND it is a wise thing to place ASSERTs whenever one is aware of such an
> important condition. This not only helps to detect programming mistakes more
> easily but also enforces code readability.
This is precisely the intention of ASSERT.
> And finally the checks (almost) never cause any relevant performance loss.
Here again it would be good to define "almost" and "relevant". Without
hard numbers the discussion becomes ill-defined. You will agree that
any check will cause some performance loss. Is "some" acceptable to you?
If not, then is "one half of some" acceptable? How much is "some"?
> In other words: if a program is correct no ASSERT in it will ever fail
> (and neither will any type guard).
As I already said, this statement is a definition of the term "correct".
It is a tautology. If you have an absolute certainty that your program
is "correct", then by the same token you know that it will never fail.
In such a situation you can turn off the checks. Have you ever seen this
kind of a situation in case of a substantial program?
It is well known and generally agreed that certain inner-most sections
of the code can be compiled without checks. An example might be a FOR loop
of the sort FOR i := 0 TO LEN (array) - 1 DO INC (array[i]) END;
Here you know that the index will never spill beyond the end of the array.
However, I doubt whether the compiler inserts any checks into the body
of the loop (but I did not look at the generated assembly, so I am just
guessing). Any code which is even slightly more complex should have checks
enabled and never turned off.
Even the above example is debatable, because one should think what happens
when the INC overflows the range of the argument. Should it quietly roll
over from MAX(INTEGER) to MIN(INTEGER)? Or should it halt? Or should it
ring a bell? Or should it turn off power to the entire building? There is
no universal answer to this question. It depends on the situation. There
might be a situation when the appropriate action is to turn off the power.
> This is why it is possible to drop the time consuming checks with a
> compiler option.
"Time consuming" is not an issue. If "some" is not acceptable to you,
but "one half of some" is acceptable, then do not turn off the checks
but rather buy a faster computer.
The issue is "what happens if a problem does occur". See the above
example which, at a first glance, seems non-problematic. But, in case
the values of your array are controlling a nuclear power station,
you definitely want to sweep "time consuming" aside from considerations
and seriously analyze the consequences of a possible exception.
> If a program WAS correct then no ASSERT in it would ever fail.
> Hence one could think of turning off the "time consuming" checks by a
> compiler option in order to increase performance for code portions that are
> assumed to be correct.
"Assumed to be correct" is a good statement. In reality one should not
assume anything even in a seemingly simplest case. It all depends on
the situation. To make it more clear, in the example above, is it your
goal to exercise the INC and print out the result? Then you can assume
it is correct. Or perhaps, are the values of the array controlling a
launch of ballistic missiles, which will be fired when the value changes
its sign from "+" to "-"? In such a case you cannot assume the code is
correct. You better exercise a check that such a change does not happen
automatically due to a pecularity of the INC instruction.
> Or again in other words: Turning off ASSERTs (and maybe even TYPE guards)
> would have no effect on correct programs, BUT could be FATAL for incorrect
> ones!
Again a tautology.
> (My opinion of course is to NEVER turn off such checks!)
Then why are discussing all this?
> > The conclusion is that if you place debugging statements in the code to
> cause halts you should always use HALT and not ASSERT.
> E.g.:
> IF a = 10 THEN HALT(99) END;
> and not:
> ASSERT(a # 10, 99);
>
> This is barely for the sake of readability and NOT bizzare at all!
Readability is in the eyes of the reader. To me it looks bizzare.
> Debugging statements more over should be RED and BOLD type faced.
Are we discussing the language or the features of the editor?
W.
--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy
----boundary-LibPST-iamunique-442727410_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIE9uIE1vbiwgMTI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