[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

DesignByContract (was RE: utilizing ++ and -- for comments

Peña, Botp

2/16/2005 9:31:00 AM

at [mailto:"neo.matrix.fr(at)"@wanadoo.fr] wrote:

// > The closest connection bw code and comments I can think of
//is (eiffel's) > pre/post condition.. if fully agree with you
//and I believe at 100% in pre/post conditions,
//class invariant, check clause... and in general in Design By Contract
//
//it answers well at the question : Who do what ? With wich
//garanties ? == The *most* important question to solve the
//issue of the quality of
//software ==

if memory serves me right (my mem misses many times :), I think Andy Hunt
started implementing something like this. I searched in raa but (sadly)
cannot find one though :(

//
//Ytoba
//

kind regards -botp


5 Answers

Jason Voegele

2/16/2005 1:12:00 PM

0


"Peña, Botp" said:
> at [mailto:"neo.matrix.fr(at)"@wanadoo.fr] wrote:
> // > The closest connection bw code and comments I can think of
> //is (eiffel's) > pre/post condition..
>
> if memory serves me right (my mem misses many times :), I think Andy Hunt
> started implementing something like this. I searched in raa but (sadly)
> cannot find one though :(

http://www.rubycentral.com/download...

--
Jason Voegele
"There is an essential core at the center of each man and woman that
remains unaltered no matter how life's externals may be transformed
or recombined. But it's smaller than we think."
-- Gene Wolfe, The Book of the Long Sun



Florian Gross

2/16/2005 9:19:00 PM

0

Peña, Botp wrote:

> at [mailto:"neo.matrix.fr(at)"@wanadoo.fr] wrote:
>
> // > The closest connection bw code and comments I can think of
> //is (eiffel's) > pre/post condition.. if fully agree with you
> //and I believe at 100% in pre/post conditions,
> //class invariant, check clause... and in general in Design By Contract
> //
> //it answers well at the question : Who do what ? With wich
> //garanties ? == The *most* important question to solve the
> //issue of the quality of
> //software ==
>
> if memory serves me right (my mem misses many times :), I think Andy Hunt
> started implementing something like this. I searched in raa but (sadly)
> cannot find one though :(

Yup, it's a bit out-dated, though. I'll have a look at integrating
Eiffel-style DBC (pre and post-checks plus invariants) with
ruby-contract (see http://ruby-contract.ruby...) based on Andy's
code soon, though.

I think I'll use an interface like this:

class MyArray
def pop() ... end

check :pop, :pre do
size > 0
end

check :pop, :post do # couldn't think of a better sample here
size >= 0
end

check :invariant do
size >= 0
end
end

I'm not sure about using "check" though -- I think that is to close to
type / signature checking which I already have implemented.

If any of you happens to have any alternative suggestions, feel free to
share them!

Its Me

2/17/2005 1:32:00 AM

0


"Florian Gross" <flgr@ccan.de> wrote in message
news:37hrmgF5cpfeaU1@individual.net...
>
> I think I'll use an interface like this:
>
> class MyArray
> def pop() ... end
>
> check :pop, :pre do
> size > 0
> end

Wondering if you have a way to do these ...

How would the check :pre get access to the method parameters?

And how would the check :post access the return, or the params, or the
initial values (instance vars etc.)?



gabriele renzi

2/17/2005 8:16:00 AM

0

itsme213 ha scritto:
> "Florian Gross" <flgr@ccan.de> wrote in message
> news:37hrmgF5cpfeaU1@individual.net...
>
>>I think I'll use an interface like this:
>>
>>class MyArray
>> def pop() ... end
>>
>> check :pop, :pre do
>> size > 0
>> end
>
>
> Wondering if you have a way to do these ...
>
> How would the check :pre get access to the method parameters?
>
> And how would the check :post access the return, or the params, or the
> initial values (instance vars etc.)?

I guess florian would overwrite the method #pop with a new one which
does bot the pre-code and the original code. Mauricio Fernandez showed a
nice approach to this which did not need eval() quite a long time ago
(even if he presented it as poor man's AOP)

Florian Gross

2/17/2005 1:25:00 PM

0

gabriele renzi wrote:

>> Wondering if you have a way to do these ...
>>
>> How would the check :pre get access to the method parameters?
>>
>> And how would the check :post access the return, or the params, or the
>> initial values (instance vars etc.)?
>
> I guess florian would overwrite the method #pop with a new one which
> does bot the pre-code and the original code. Mauricio Fernandez showed a
> nice approach to this which did not need eval() quite a long time ago
> (even if he presented it as poor man's AOP)

This would be the basic way of doing it -- note that I'm not sure about
having pre-checks access to arguments -- after all the signature is for
ensuring the basic consistency of those. It would still be nice to have
them, though.

Regarding in-variants: I'll probably end up wrapping all methods like
with the pre/post checks and having a method_added hook for wrapping
newly added methods as well.

I've not thought about all the details (what about inheritance) and so
on yet -- it will probably be easier for me to think about those once I
have a basic implementation I can toy with.