[1007] in java-interest
Re: Assertions in Java
daemon@ATHENA.MIT.EDU (Andrew Carlson)
Wed Aug 16 18:48:09 1995
Date: Wed, 16 Aug 1995 11:58:40 +0000
From: andycarlson@attmail.com (Andrew Carlson)
In-Reply-To: your message <199508152049.NAA26793@soda.CSUA.Berkeley.EDU> of Tue Aug 15 13:49:46 -0700 1995
To: java-interest@java.sun.com, johnm@CSUA.Berkeley.EDU (John D. Mitchell)
John D. Mitchell writes:
>Andrew Carlson writes:
>> 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).
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?
[Eiffel style Preconditions, Postconditions & Invariants]
>> 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.
In my opinion, the behaviour of a class (and in java, an interface too) should
be fully definable in terms of its public interface. The conditions could
therefore be based on the results of public interface functions.
Lifting an example from Bertrand Meyer's OO Software Construction Book, the
postcondition for a push operation on a stack involves an assertion that the
object at the top of the stack (accessible via a query method) is the
parameter to the push operation. Such a condition says (and enforces) much
more about what a method DOES than simply relying on the method name and
parameter types.
----------------------------------------------------------------------
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