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
4
votes
1 answer

Meaning of \old in ACSL post-conditions

I am a newbie user of Frama-C and have a few questions regarding assertions over pointers. Consider the C fragment below involving: two related data structures Data and Handle, s.t. Handle has a pointer to Data; a 'state' field in Data…
edrdo
  • 133
  • 5
4
votes
2 answers

What kinds of pre-conditions are sensible in Design by Contract?

Let's assume we have a class Student with the following constructor: /** Initializes a student instance. * @param matrNr matriculation number (allowed range: 10000 to 99999) * @param firstName first name (at least 3 characters, no whitespace) …
Niklas B.
  • 92,950
  • 18
  • 194
  • 224
4
votes
2 answers

What tooling do you use to do Design by Contract?

I used to use Microsoft CodeContracts for three weeks and now half of my code is just contracts. I have dozens of unproved places, I cannot use runtime-check because IL rewrite prevents coverage tool to show something and compile time is less then…
Mike Chaliy
  • 25,801
  • 18
  • 67
  • 105
4
votes
2 answers

Code Contracts in C# 4.0

I made a method like this class PersonCollection { [Contracts.CanReturnNull] //dont know if something like this exists? IPerson GetPerson(Guid personId) { if (this.persons.Contains(personId)) return this.persons[personId]; …
schoetbi
  • 12,009
  • 10
  • 54
  • 72
4
votes
3 answers

When to add a precondition and when to (only) throw an exception?

I am learning about preconditions and when to use them. I have been told that the precondition @pre fileName must be the name of a valid file does not suit in the following code: /** Creates a new FileReader, given the name of file to read…
Datoraki
  • 1,223
  • 13
  • 26
4
votes
1 answer

Storing input value to check wether postcondition holds true when applying Design-by-Contract

I make use of the assertthat package quite often to check postconditions in functions. When reading more about the idea of Design by Contract I stumbled upon the idea to make checks of output in comparison to input values. The most simple example is…
symbolrush
  • 7,123
  • 1
  • 39
  • 67
4
votes
2 answers

DbC (Design by Contract) and Unit Tests

I am using contracts with C# 4.0 and before I was using lots of unit tests (not with TDD). I am wondering if DbC eliminates the need to write external unit tests? Personally I find contracts better to make robust frameworks, as the contracts are…
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
4
votes
5 answers

How to define IEnumerable behavior by contract?

Consider this 2 methods that returns IEnumerable: private IEnumerable GetYieldResult(int qtResult) { for (int i = 0; i < qtResult; i++) { count++; yield return new MyClass() { Id = i+1 }; …
AntonioR
  • 584
  • 3
  • 6
4
votes
3 answers

How to enforce interface contracts (in C) at compile time?

Background: We're modeling the firmware for a new embedded system. Currently the firmware is being modeled in UML, but the code generation capabilities of the UML modeling tool will not be used. Target language will be C (C99, to be specific). Low…
Dan
  • 10,303
  • 5
  • 36
  • 53
4
votes
4 answers

How can I write a contract for an abstract method?

I am using contracts in my Java project. (Contract = doing checks at the start and end of methods) I am wondering if there is a nice way/pattern to write a contract for a generic method. For example: public abstract class AbstractStringGenerator{ …
lindon fox
  • 3,298
  • 3
  • 33
  • 59
4
votes
3 answers

What does Check.Assert(), Check.Ensure(), and Check.Require() do?

Please tell me what those functions do.
Krishna
  • 73
  • 2
  • 5
4
votes
1 answer

WCF Contract first: complexType has already been declared

I am using svcutil.exe to generate a service endpoint based on a contract from an external source. It seems to work as intended, but the service is not able to expose an endpoint to others. Specifically, when I try to GET the WSDL for the service,…
Jesper Lund Stocholm
  • 1,973
  • 2
  • 27
  • 49
4
votes
1 answer

Which 3rd party Code-by-Contract library is most like MS's .NET 4.0 library?

I want to jump into coding by contract. I got VS2010 (with the C# 4.0 compiler) but I have to target the 3.5 framework. What 3rd party code by contract library has classes and interface the most like the .NET 4.0 ones?
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
4
votes
1 answer

WCF Contract first: No methods are exposed

I have received a WSDL with a bunch of XSD's and I am using these to create a WCF-service. I am using svcutil.exe to generate the service class and everything basically works fine - except that the services does not expose any methods. The .cs-file…
Jesper Lund Stocholm
  • 1,973
  • 2
  • 27
  • 49
4
votes
1 answer

Clojure condition-map parameter provided as metadata of the arglist

In the the special forms Clojure documentation (http://clojure.org/special_forms) The condition-map parameter is described as below: The condition-map parameter may be used to specify pre- and postconditions for a function. It is of the following…
Matthew Gretton
  • 333
  • 2
  • 11