How is the Racket "design by contract" scheme different from Eiffel?

I know that both the Eiffel (grandparent) and the Rocket need to implement the functions of “Design by Contract”. Unfortunately, I do not know how to differ from another. Eiffel DBC relies on the OOP paradigm and inheritance, but how does Racket, a completely different language, explain such a mismatch?

+7
source share
3 answers

The main claim to a rocket for contract glory is the concept of guilt, and dealing with the ho function is a big part of what Racket definitely does for everyday programming.

You can also check the first two sections of this article:

http://www.ccs.neu.edu/scheme/pubs/oopsla01-ff.pdf

+13
source

First of all, your best source of information at this point is the Rocket Guide , which is intended as an introductory text, not a reference guide. In particular, there is an extensive chapter on contracts that will help. EDIT: Also see the article Robbie pointed to, he's the main guy from Racket.

As for your question - I know little about the Eiffel contract system, but I think it precedes the Racket system. However (and this is again "IIRC"), I think the Racket contract system was the first to introduce higher order contracts. In particular, when dealing with higher-order functions, assigning the correct fault becomes a little more complicated - for example, if you take the function foo that has an X? -> Y? contract X? -> Y? X? -> Y? , and you send it a value that does not match X? , then the client code that sent this value to foo is blamed. But if your function (X? -> Y?) -> Z? , and the predicate X? if it fails, then the fault goes to foo itself, and not to the client (and if Y? fails, then it's still the client’s fault).

+9
source

I think you are asking how a contract system can work without OOP and inheritance? As a Racket user who is not familiar with Eiffel, I wonder why the contract system will have anything to do with OOP and inheritance. :)

At a practical level, I think of Racket contracts as a way to get some of the benefits of static type declarations, while maintaining the flexibility of dynamically typed languages. Plus, contracts go beyond just types and can act as assertions.

For example, I can say that a function requires one argument, which is an exact integer ... but also say that it must be an exact positive integer or a union of certain specific values ​​or practically any arbitrarily complex test of the passed value. Thus, contracts in Racket combine what you can do with declarations of type (a) and (b) statements, for example, in C / C ++.

One of them with contracts at Racket is that they can be slow. One way to deal with this is to first use them in development, and then remove them selectively, especially from the "internal loops" of function types. Another approach I tried is to enable or disable wholesale: create a couple of modules, such as contract-on.rkt and contract-off.rkt, where the latter provides macros with nothing to do. Your modules require a .rkt contract, which provides all of any -on or -off files. This is similar to compiling in DEBUG vs RELEASE mode.

If you are coming from Eiffel, maybe my C / C ++ tilt of the Racket will not be useful, but I would like to share it anyway.

+8
source

All Articles