[974] in java-interest

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

Assertions in Java

daemon@ATHENA.MIT.EDU (Andrew Carlson)
Wed Aug 16 00:45:55 1995

Date: Tue, 15 Aug 1995 11:20:37 +0000
From: andycarlson@attmail.com (Andrew Carlson)
To: java-interest@java.sun.com

I'm pretty new to java, but may I be so bold as to make a feature suggestion 
based on my experience with C++.

We have implemented a great deal of C++ code which relies on the presence
of the preprocessor - a feature which is not present in java. I don't 
consider this too great a loss except for one thing. We have a macro called
ASSERT which (guess what) blows away the application if the associated 
condition is false, but only in the debug version. A release build generates 
no code for the ASSERT. This is similar to the facility in assert.h but gives 
more diagnostic information.

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.

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.

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.

I suppose java code might be passed through the 'C' preprocessor as an 
alternative approach, but that makes the developer's life harder and is a 
fairly error prone approach.

Apologies if there is something blindingly obvious already in the
language, but I can't find it.

Comments Please!

Andy
----------------------------------------------------------------------
Andy Carlson. AT&T ISTEL                Tel: +44 1527 494358
E-Mail: andycarlson@attmail.com         Fax: +44 1527 494318
-
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