[PRL] Contracts vs aspects

Mitchell Wand wand at ccs.neu.edu
Thu Apr 28 21:44:24 EDT 2005


>> I don't know if you have a specific theoretical model of contracts in
>> mind, but I could certainly write this in PLT contracts.  Contracts
>> can contain arbitrary predicates, so they can also use and maintain
>> mutable state recording whether foo has been called since the last
>> call to bar.  This is before even considering adding new contract
>> primitives for this kind of invariant.

PAS> Right; you'd have to setup the machinery to 
PAS> establish the evidence of the prior call to foo() 
PAS> to feed into the appropriate predicate. 
PAS> What I meant was, there's no ready-at-hand 
PAS> construct that does this for you, as far 
PAS> as I know.

What's interesting about this, I think, is that it illustrates the
distinction between aspects and advice.  

Aspect = Advice + State

In
http://www.aspectprogrammer.org/blogs/adrian/2005/04/aspects_as_auto.html, 
the aspect uses a state machine to keep track of the state.

Advice and contracts are rather different ways to attach actions to
procedure calls and returns, but both need separate mechanisms to
handle stateful concerns.

Now, one of the things we know and the imperative folks don't is the
virtues of using binding rather than state whenever possible.  Can you
come up with an example where contracts+binding does better than
advice+state?

--Mitch 





More information about the PRL mailing list