Design by Contract

What ever happened with ‘Design by Contract’ in Ruby? Is there still plans
for it being implemented in a future version?

IIRC, the dbc module below works by opening up the Ruby source file
and scanning the the pre/post/inv assertions. It works, but with a
little language support the process can be much improved. The Seattle
Ruby Brigade has been conducting a langauge audit. comparing Ruby
features with those of other languages. Here is a list of features
that Python offers but Ruby does not:

···

Python

Syntax/Semantics

The following would require changes to the language/interpreter:

  • Real traceback objects.
  • Much better object and runtime reflection:

— Code Objects (name, argcount, nlocals, varnames, code, consts,
names, filename, firstlineno, stacksize, flags
— Frame Objects (back, code, locals, globals, builtins, restricted,
lineno, lasti, trace, exc_type, exc_value, exc_traceback)
—Traceback Objects (next, frame, line, listi)

  • Doc strings available at runtime

  • keyword arguments (**keys)

  • selective import (include in ruby)


The second set of itmes (better object and runtime reflection)
includes Code Objects replete with name, argcount, firstlineno, etc,
which if added to Ruby would facilitate Design by Contract, in
addition to a host of meta-programming issues.

If Ruby were to adopt these features, Design by Conduct could be
re-wrtitten to take advantage of built-in language-support facilities
rather than scanning text to locate the pre-conditions,
post-conditions and invairants within a method.

Any thoughts?

— J J jj5412@earthlink.net wrote:

Any interest/thoughts on implementing simple design
by contract in Ruby?
Maybe adding Kernel.assert at least? I’ve written my
own assert, but think
it might make a good addition to the language.

You might want to check out Andy Hunt’s
implementation:
http://www.pragmaticprogrammer.com/ruby/downloads/dbc.html

Chad

Ruby Brigade has been conducting a langauge audit. comparing Ruby
features with those of other languages. Here is a list of features
that Python offers but Ruby does not:

I hope that you know that it exist programming language with a name not
beginning by P :slight_smile:

Ruby | zenspider.com | by ryan davis

Now if I look at this page, I see

   Core Libraries

     [etc, etc, ...]

personnaly I prefer to have a small distribution, associated with
something like RAA, rather than have to load 10 Gb just to have an
interpreter

Guy Decoux