Questions tagged [design-by-contract]

Design by Contract (DbC) or Programming by Contract is an approach to designing computer software. It prescribes that software designers should define formal, precise and verifiable interface specifications for software components, which extend the ordinary definition of abstract data types with preconditions, postconditions and invariants. These specifications are referred to as "contracts", in accordance with a conceptual metaphor with the conditions and

Design by Contract (DbC) or Programming by Contract is an approach to designing computer software. It prescribes that software designers should define formal, precise and verifiable interface specifications for software components, which extend the ordinary definition of abstract data types with preconditions, postconditions and invariants. These specifications are referred to as "contracts", in accordance with a conceptual metaphor with the conditions and obligations of business contracts.

Because Design by Contract is a registered trademark of Eiffel Software in the United States, many developers refer to it as Programming by Contract, Contract Programming, or Contract-First development.

216 questions
6
votes
5 answers

api documentation and "value limits": do they match?

Do you often see in API documentation (as in 'javadoc of public functions' for example) the description of "value limits" as well as the classic documentation ? Note: I am not talking about comments within the code By "value limits", I mean: does a…
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
6
votes
1 answer

Does Perl 6 natively support Design by Contract?

It is listed as a language with native DbC support on the Wikipedia beside Eiffel and Spec#, but I can't find any mention whatsoever in the docs or in the test suite.
catemperor
  • 163
  • 2
  • 6
6
votes
1 answer

Is Spec# stable enough to use?

Does anyone here use Spec# regularly? I would like to know if it is stable and powerful enough before I start using it everywhere. It looks like the syntax is influencing c# 4.0, which will hopefully make it easier to upgrade once 4.0 is released.…
cbp
  • 25,252
  • 29
  • 125
  • 205
6
votes
3 answers

What are preconditions and postconditions?

I'm learning how to program but one thing I can't quite get my head around is preconditions and postconditions. Is an if statement before calling a function considered a precondition, or is there a separate more efficient way of doing this in most…
5
votes
5 answers

Design By Contract, writing test-friendly code, object construction and Dependency Injection putting all together best practices

I have been trying to figure out the best practices to write test-friendly code, but more specifically the practices related to object construction. In the blue book we discovered that we should enforce invariants when creating objects to avoid the…
5
votes
3 answers

Design by Contract in C for use in Automated Theorem Proving

I'm working on a couple of C projects and I'd like to use automated theorem proving to validate the code. Ideally I'd just like to use the ATP to validate the functions contracts. Is there any functionality in C/gcc or external…
machinaut
  • 495
  • 2
  • 4
  • 17
5
votes
5 answers

Should my classes restrict developers from doing wrong things with them?

I am trying to understand where good contracts end and paranoia starts. Really, I just have no idea what good developer should care about and what shall he leave out :) Let's say I have a class that holds value(s), like java.lang.Integer. Its…
0andvoid
  • 65
  • 1
  • 4
5
votes
3 answers

DDD: the Repository contract

I've read in various places that one important requirement in DDD is to have a bounded contract for the Repository: findByName(string name) findByEmail(string email) etc. And not provide a generic query interface: findBySpecification(Specification…
5
votes
3 answers

Is there a design by contract framework for php?

Is there a framework or library for php that will help me implement design by contract in my applications? In the best case it would use javadoc like annotations in the comments.
Doctor Who
  • 97
  • 1
  • 6
5
votes
2 answers

Why I still get Code Contracts : Ensure unproven warning?

Below is a very simple example. When I turn on the static analysis warnings, I still get Warning CodeContracts: ensures unproven: Contract.Result() != string.Empty on the line return string.Format("{0}, {1}", movie.Title,…
Simon
  • 53
  • 3
5
votes
4 answers

Argument Exceptions should be Unit Tested?

I know this question is pretty similar to others that have been posted before but I would like to discuss this topic in a proper way. Do you think that the "obvious" exception should be unit tested? With obvious exception I mean for example…
TheSENDER
  • 175
  • 1
  • 1
  • 3
5
votes
2 answers

What to do when using Contract.Assert(true) and the method must return something?

I have a bit of code with the following logic: //pseudo-code foreach (element in elementList) { if (element is whatever) return element; } } In theory, there is always one element that is whatever, so this method should pose no…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
5
votes
1 answer

What's the most widely-used open source project that uses design by contract?

I'm curious about how much design-by-contract is used in practice outside of the Eiffel community. Are there any active open-source projects that use design-by-contract? Or, to recast the question into one what that has a single answer: what's the…
Lorin Hochstein
  • 57,372
  • 31
  • 105
  • 141
5
votes
3 answers

Design by contract and assert statements

I am interested in the Design by Contract approach. It seems that for preconditions checked exceptions must be used to enforce them. But for post-conditions and class-invariants I think that assertions are preferred. Am I right? If I am correct, why…
Cratylus
  • 52,998
  • 69
  • 209
  • 339
5
votes
1 answer

Usage of javaagent with Android

I've recently became interested in DBC methodology. As Java is my "native" language I've looked at cofoja and more recently java-on-contracts. I mainly create Android software, so naturally I'd like to be able to use contracts on my phone. Both…
kajman
  • 1,066
  • 11
  • 24