- ASSERT fault?

From: Marco Ciot <"Marco>
Date: Mon, 12 Jun 2006 12:06:19 +0200

----boundary-LibPST-iamunique-232021905_-_-
Content-type: text/plain

Apparently my explanation for the use of ASSERTs lacked some clarity.
I will try to add it:

> The intention of using ASSERT is never to HALT, but to assert a condition
for the subsequent program code.

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.
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.
And finally the checks (almost) never cause any relevant performance loss.

> In other words: if a program is correct no ASSERT in it will ever fail
(and neither will any type guard). This is why it is possible to drop the
time consuming checks with a compiler option.

Maybe this is clearer:
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.
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!

(My opinion of course is to NEVER turn off such checks!)


> 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!
Debugging statements more over should be RED and BOLD type faced.

Marco Ciot

-----Original Message-----
From: blackbox{([at]})nowhere.xy
Ciot
Sent: Sunday, June 11, 2006 10:57
To: BlackBox Mailing List
Subject: [BlackBox] - ASSERT fault?


It would be inconvenient if ASSERT(FALSE) wouldn't raise an error at compile
time already.

I often place ASSERT statements like:

ASSERT(LEN(array) >= maxItemCnt);

And of course I want the compiler to let me know immediately that the
assertion fails.

The intention of using ASSERT is never to HALT, but to assert a condition

for the subsequent program code. In other words: if a program is correct no
ASSERT in it will ever fail (and neither will any type guard). This is why
it is possible to drop the time consuming checks with a compiler option.


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);

Marco Ciot



-----Original Message-----
From: blackbox{([at]})nowhere.xy
Software
Sent: Sunday, June 11, 2006 04:48
To: BlackBox Mailing List
Subject: [BlackBox] - ASSERT fault?


This question arose in the process of porting some code from Gardens
Point Component Pascal to Blackbox Component Pascal.

The following statement:

  ASSERT(FALSE)

Results in the compiler error: 'ASSERT fault'

Why? I haven't been able to find any reason in the Component Pascal
Language Reference why it should not be allowed.

Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy



----boundary-LibPST-iamunique-232021905_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIEFwcGFyZW50bHkgbXkgZXhwbGFuYXRpb24gZm9y
IHRoZSB1c2Ugb2YgQVNTRVJUcyBsYWNrZWQgc29tZSBjbGFyaXR5LlxwYXINCkkgd2lsbCB0cnkg
dG8gYWRkIGl0OlxwYXINClxwYXINCj4gVGhlIGludGVudGlvbiBvZiB1c2luZyBBU1NFUlQgaXMg
bmV2ZXIgdG8gSEFMVCwgYnV0IHRvIGFzc2VydCBhIGNvb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50
IENvbXBvbmVudCBQYXNjYWwgdG8gQmxhY2tib3ggQ29tcG9uZW50IFBhc2NhbC5ccGFyDQpccGFy
DQpUaGUgZm9sbG93aW5nIHN0YXRlbWVudDpccGFyDQpccGFyDQogIEFTU0VSVChGQUxTRSlccGFy
DQpccGFyDQpSZXN1bHRzIGluIHRoZSBjb21waWxlciBlcnJvcjogJ0FTU0VSVCBmYXVsdCdccGFy
DQpccGFyDQpXaHk/IEkgaGF2ZW4ndCBiZWVuIGFibGUgdG8gZmluZCBhbnkgcmVhc29uIGluIHRo
ZSBDb21wb25lbnQgUGFzY2FsXHBhcg0KTGFuZ3VhZ2UgUmVmZXJlbmNlIHdoeSBpdCBzaG91bGQg
bm90IGJlIGFsbG93ZWQuXHBhcg0KXHBhcg0KQ2hyaXMgQnVycm93c1xwYXINCkNGQiBTb2Z0d2Fy
ZVxwYXINCmh0dHA6Ly93d3cuY2Zic29mdHdhcmUuY29tL2dwY3BccGFyDQpccGFyDQotLS0gQmxh
Y2tCb3hccGFyDQotLS0gc2VuZCBzdWJqZWN0IEhFTFAgb3IgVU5TVUJTQ1JJQkUgdG8gYmxhY2ti
b3hAb2Jlcm9uLmNoXHBhcg0KXHBhcg0KLS0tIEJsYWNrQm94XHBhcg0KLS0tIHNlbmQgc3ViamVj
dCBIRUxQIG9yIFVOU1VCU0NSSUJFIHRvIGJsYWNrYm94QG9iZXJvbi5jaFxwYXINClxwYXINCi0t
LSBCbGFja0JveFxwYXINCi0tLSBzZW5kIHN1YmplY3QgSEVMUCBvciBVTlNVQlNDUklCRSB0byBi
bGFja2JveEBvYmVyb24uY2hccGFyDQpccGFyDX19


----boundary-LibPST-iamunique-232021905_-_---
Received on Mon Jun 12 2006 - 12:06:19 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:27:51 UTC