On Tue, Jul 22, 2014 at 3:38 PM, Brian Knapp <brianknapp / gmail.com> wrote:
> I got into Design By Contract with Obvious (http://obvious.retromocha.com)
> in Ruby and ended up writing my own concept of contracts in Ruby. I find
> them to be useful simply because they give you runtime type guarantees that
> you don't get normally with Ruby.

Adding DBC to Ruby is quite a fundamental change. I'd say, if you feel
you need to retrofit DBC functionality to Ruby which does not even
feature static typing then you're using the wrong language; then you
are probably better off with Eiffel.

That does not mean DBC concepts cannot be used in Ruby. You can use
them for reasoning about code and even include them, e.g. as method
comments.  Knowing the concept helps understand how methods interact
with each other and what are the critical things to reason about and
to define.

> Without a stronger notion of interfaces in
> Ruby, you have to lean harder on your unit tests to provide some kind of
> guarantees about certain behaviors. With contracts, you actually write a lot
> fewer tests because your contract specifies and ensures more correct input
> and output.

I am not so sure whether that statement is actually true.  You might
rid off some unit tests but "a lot" seems too optimistic to me.
Depending on the contract there may still be a lot of legal and
illegal variants of behavior that need verifying.

> In general, with stronger guarantees around input and output, you have to
> write fewer tests.

If you put it that way I agree. :-)

Kind regards

robert

-- 
[guy, jim].each {|him| remember.him do |as, often| as.you_can - without end}
http://blog.rubybestpractices.com/