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
1
vote
2 answers

PyContract check functions in an imported module

I am using PyContract (not PyContracts) to implement design-by-contracts for my genetic algorithms framework. The main module is GA.py, which calls a function from crossover.py (let's call it foocross). I have written precondition and postcondition…
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
1
vote
1 answer

Can Microsoft.Contracts' static checker be used without Team System?

Aside from the requirement on Visual Studio Team System to be able to install Microsoft.Contacts with the static checker, is it possible to run the static checker without team system? Or, does it depend on an API exposed by studio's team system…
John Gietzen
  • 48,783
  • 32
  • 145
  • 190
1
vote
1 answer

Design by Contract: Can you have an Interface with a Protocol?

I'm pretty new to the concept of Design by Contract, but so far, I'm loving how easy it makes it to find potential bugs. However, I've been working with the Microsoft.Contracts library (which is pretty great,) and I have run into a road block. Take…
John Gietzen
  • 48,783
  • 32
  • 145
  • 190
1
vote
2 answers

How do I know which contract failed with Python's contract.py?

I'm playing with contract.py, Terrence Way's reference implementation of design-by-contract for Python. The implementation throws an exception when a contract (precondition/postcondition/invariant) is violated, but it doesn't provide you a quick way…
Lorin Hochstein
  • 57,372
  • 31
  • 105
  • 141
1
vote
0 answers

Microsoft Contracts: Assembly load resulted in metadata import warning

I'm trying to learn my way around the Microsoft Code Contracts libraries, and I have the following simple function: internal static Engine CreateBuildEngine(Microsoft.Build.Framework.ILogger logger) { Contract.Requires( logger != null ); …
0
votes
3 answers

Handling switch statement

What's the preferred way to handle the following case: switch (numberOfActualBytes) { case 1: return something1; case 2: return something2; case 3: return something3; case 4: return something4; } I know for certain that…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
0
votes
1 answer

Using Cofoja with Wicket (or even with just Maven)

I am trying my darnedest to get Google Cofoja to run in my Apache Wicket application which uses Maven2 as seems to be standard. The project was initially generated using Leg Up with the Archetype "Wicket 1.4.12, Guice 2.0, WarpPersist 2.0…
elsom25
  • 71
  • 5
0
votes
0 answers

How should I document a bean that's only supposed to be managed by CDI?

Here is my class: @Stateless @Transactional public class PostService { @Inject private PostRepository postRepo; @Inject private UserRepository userRepo; @Inject private SectionRepository sectionRepo; @Inject private LoggedInUser…
cidra
  • 374
  • 1
  • 4
  • 16
0
votes
1 answer

Weak precondition and strong postcondition problems?

in last exam, I've had question, I was unable to answer sanely. Question was "what problems might arise from too weak precondition?" Another question was "what problems might arise from too strong postcondtition?" How to go about answering that…
0
votes
1 answer

Benefits of using 'Design by Contract'

I am studying the 'Design by Contract' development methodology. However, I am having a hard time seeing its advantages. For example, it is said that one of the characteristics of this methodology is that the preconditions of a function can be…
Mike
  • 1
  • 2
0
votes
1 answer

rescue how to raise further or forget an exception

How do I raise an exception further in eiffel? I have 3 cases I want to retry a_feature local l_retries_count: INTEGER do some_potential_failing_feature rescue if l_retries_count <= 3 then …
Pipo
  • 4,653
  • 38
  • 47
0
votes
1 answer

Understanding Eiffel loop variant/invariant

I was trying to have a structure which talks himself about variants and invariants into Eiffel loops, but don't understand the variant part! from l_array := <<1,2,30,60>> l_index := l_array.lower invariant valid_local_index:…
Pipo
  • 4,653
  • 38
  • 47
0
votes
1 answer

eiffel: a statement for explicitly executing code when assertions are on

Sometimes the checks and contract constructions need an elaboration which wants to be avoided when assertions removed to improve performances and avoid doing useless things with the "only" work of the compiler. I refer for ex. to job in loops checks…
Pipo
  • 4,653
  • 38
  • 47
0
votes
2 answers

Design Dilemma - Context or Contract? (Java/Kotlin)

I have an Activity, a Presenter, and a Contract which both the Activity and the Presenter implement. The Activity will have some unique UI stuff, which must be called from within the Presenter. The Presenter must also be able to make a call to the…
El Sushiboi
  • 428
  • 7
  • 19
0
votes
1 answer

estudio does not check `require` when it should?

Eiffel Studio seems to pass through my requirements even if I have them enabled on project settings. And as far as I remember I was able some time to put a break point into the requirements... I don't understand what I'am missing here, as you can…
Pipo
  • 4,653
  • 38
  • 47