[945] in java-interest

home help back first fref pref prev next nref lref last post

Assertions in Java

daemon@ATHENA.MIT.EDU (John D. Mitchell)
Tue Aug 15 20:11:18 1995

Date: Tue, 15 Aug 1995 13:49:46 -0700
From: "John D. Mitchell" <johnm@CSUA.Berkeley.EDU>
To: andycarlson@attmail.com (Andrew Carlson)
CC: java-interest@java.sun.com
In-reply-to: <winATT-2.5.1-andycarlson-174>

Andrew Carlson writes:
[...C Preprocessor and Assert macros...]
> My minimum request would be the ability to do something similar in java,
> i.e. an ASSERT which can be switched out of released code with no
> overhead.

Other than syntactic sugar, is there any other reason why *not* to just use
a 'static final' flag and an if statement?  I don't know if the current
Sun Java compiler does it or now but it's certainly possible to make that
generate no code if the flag is false (and to get rid of the entire if test
if the flag is true).


> My ideal would be to have a facility something similar to the Eiffel
> language, i.e. the ability to specify preconditions and postconditions on
> methods and specify invariants for the class. Maybe the ability to do
> this at an interface level would be also beneficial, allowing clients of
> an interface to be sure about what they could expect of the
> implementation.

I'm certainly no Eiffel expert but there are some interesting constraints
on the language given the pre-/post-conditions in Eiffel (i.e., more of the
unescapable co- versus contra-variance stuff).  I've not thought about the
cost of adding those features to Java.


> In my opinion these facilities would allow java developers to enforce much 
> tighter interface contracts, thus improving quality and could be added to
> the language without breaking existing code.

How so?  The interfaces in Java only specify methods and types (and
constants).  There's no state information to base the conditions on.


Hope this helps,
		John
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post