[1039] in java-interest
Re: Assertions in Java
daemon@ATHENA.MIT.EDU (Hansruedi Heeb)
Thu Aug 17 11:40:10 1995
To: java-interest@java.sun.com
In-Reply-To: Your message of Wed, 16 Aug 1995 12:03:43 PDT. <199508161903.MAA01912@soda.CSUA.Berkeley.EDU>
Date: Thu, 17 Aug 1995 14:22:33 +0200
From: Hansruedi Heeb <heeb@diagonal.ch>
Your message dated: Wed, 16 Aug 1995 12:03:43 PDT
>Andrew Carlson writes:
>[...if + flag vs assert...]
>> I think I get the gist of what you are suggesting. Is this something that
>> can be done with java as it stands?. If so, could you possibly give an
>> example to clarify things?
>
>How about something like:
>
>class TA {
> static final boolean debugMode = true; // or false
> ...
> public void checkMe {
> if (debugMode) {
> // Code of 'assert' here...
> }
> ...
> }
> ...
>}
It's hard enough to teach co-workers the use of (frequent!) asserts.
Like this it becomes unacceptable. Since I cannot live without asserts
anymore this would mean going back to a preprocessor.
PLEASE, PLEASE think carefully before you decide *not* to offer an assert
mechanism, it might mean that part of the old messyness creeps back in
(hunting for #ifdefs ...).
Asserts are extremely useful! They also make the code much more readable,
e.g.
if (complex cond) {
...
} else if (complex cond) {
...
} else if (complex cond) {
...
} else if (complex cond) {
...
} else {
assert(complex condition);
}
is much easier to decipher than without the assert. The same holds for
Eiffel style asserts at the beginning and end of methods.
Hansruedi
_/_/_/_/ _/_/_/ Hansruedi Heeb
_/ _/ _/ DS Diagonal Systems AG
_/ _/ _/_/ +41 1 905 60 60
_/ _/ _/ heeb@diagonal.ch
_/_/_/_/ _/_/_/ http://www.diagonal.com/
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com