Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Eiffel > Re: Modular Pro...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 12 Topic 876 of 917
Post > Topic >>

Re: Modular Protection vs Assertions ...

by Colin LeMahieu <clemahieu@[EMAIL PROTECTED] > Jul 29, 2007 at 01:08 AM

Exceptions are used to handle cases where the failure result could not
have been predicted beforehand.  A network communications failure
cannot be tested for and you can only observe its occurrence once it
has happened.

Contracts are used to reduce the domain and range of a function in to
terms valid for that function.  A range constraint on the function
is_even(source: INTEGER) would be result implies source \\ 2 = 0.  A
domain constraint on the function sqrt(source: REAL) would be source >
0.  It can be determined beforehand that source should should not be
negative or that an even number should have no remainder when divided
by two.

Contracts should be fleshed out in debugging and testing.  Exceptions
can occur during normal program execution and should be anticipated
and able to recover but only used to recover from things that could
not have been tested beforehand.

I hope that clears up their distinct uses.

On Jul 28, 8:40 am, bravegag <brave...@[EMAIL PROTECTED]
> wrote:
> Hi all,
>
> After reading Bertrand Meyer's OOSC book I find a little bit blurred
> the line between using proper exception declarations in public methods
> vs using asserts for precondition checking.
>
> It is confusing to me the fact that:
>
> - Bertrand remarks the need of "Modular Protection" which is not
> clearly stated but I assume it also applies to Software-to-Software
> communication i.e. between modules. Therefore module boundaries or
> module public API must rely on proper exception handling for argument
> checking and in general precondition checking (instead of using
> assertions for that purpose). I find "Modular Protection" to be
> somehow similar to "Defensive Programming".
>
> - On the other hand Bertrand Meyer also remarks a valid thing which is
> that excessive checking can be very harmful performance-wise.
> Therefore recommends using assertions that are enabled only during
> development, testing and debugging and disabled once the system is
> delivered in production.
>
> Another fact is that (somehow contrary to Bertrand Meyers view) Sun
> assert usage guideline dictate that "Do not use assertions for
> argument checking in public methods"
seehttp://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html#usage
>
> So I can only make the conclusion that:
>
> - Assertions should be used even in public methods as long as those
> methods are not part of the public API of a module i.e. assertions are
> not an input checking mechanism for module boundaries. Bertrand Meyer
> has a section in the chapter "Design by Contract" and the headline is
> precisely that but then he remarks it is intended only for Human-to-
> Software communication or Outside-World-to-Software communication.
>
> - Proper exception handling should be the solution to use within
> module boundaries so that not only the public API of a module
> establishes a contract but also allows the client modules to
> gracefully retry or at least recover from serious faults as
> consequence of precondition violations in production time.
>
> I would greatly appreciate your feedback or insights into this subject
> or even pointers to further discussion.
>
> I have seen situations where faults may lead to a total software chaos
> just because they used assertions within module boundaries for input
> checking rather than proper exception handling.
>
> TIA,
> Regards,
> Giovanni




 12 Posts in Topic:
Modular Protection vs Assertions ...
bravegag <bravegag@[EM  2007-07-28 06:40:53 
Re: Modular Protection vs Assertions ...
Colin LeMahieu <clemah  2007-07-29 01:08:25 
Re: Modular Protection vs Assertions ...
llothar <llothar@[EMAI  2007-07-29 04:24:56 
Re: Modular Protection vs Assertions ...
Ulrich Windl <Ulrich.W  2007-07-31 08:59:00 
Re: Modular Protection vs Assertions ...
Ulrich Windl <Ulrich.W  2007-07-31 08:54:06 
Re: Modular Protection vs Assertions ...
llothar <llothar@[EMAI  2007-07-31 11:26:53 
Re: Modular Protection vs Assertions ...
bravegag <bravegag@[EM  2007-07-31 23:57:33 
Re: Modular Protection vs Assertions ...
bravegag <bravegag@[EM  2007-08-01 00:14:09 
Re: Modular Protection vs Assertions ...
Ulrich Windl <Ulrich.W  2007-08-02 10:47:43 
Re: Modular Protection vs Assertions ...
llothar <llothar@[EMAI  2007-08-01 01:39:38 
Re: Modular Protection vs Assertions ...
llothar <llothar@[EMAI  2007-08-01 01:42:00 
Re: Modular Protection vs Assertions ...
Colin LeMahieu <clemah  2007-08-01 07:27:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 4:44:05 CDT 2008.