Questions tagged [design-by-contract]

Design by contract (DbC) 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.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
24 views

Contract Testing - Salesforce - is it feasable?

Has anyone ever used contract testing with Salesforce? Here's my use case: Salesforce is the provider, I need to consume its APIs from my service, and depending on what payload I send, I will have ...
3 votes
4 answers
368 views

Is design by contract useful without unit testing?

I read Bertrand Meyer's paper on design by contract yesterday and it is not very clear for me what is the relationship between DbC and testing, since it appears that without testing I cannot be ...
  • 2,594
1 vote
0 answers
53 views

Request and response validation

I am currently working on a project using Flask to make REST apis, blablabla. But, working with request validation tools that we use, I am thinking of whether it would be necessary to validate the ...
-2 votes
1 answer
55 views

How do you enforce API contracts across mutliple stacks?

For systems that are built on top of diverse tech stacks, including both static and dynamic types languages, what is in practice some ways to have the API contracts published and enforced? Some wiki ...
  • 297
2 votes
1 answer
167 views

Contract based programming with verifications

I have a large project that is build contract based, where all functions verify input parameters and return values. But there are also cases where they for example verify that a call to a function is ...
  • 130
0 votes
1 answer
82 views

API DESIGN: Store Table of function pointers in client or dynamically in api service

FIRST AND FOREMOST: Forgive me if the following question falls into the "off topic" category of this StackExchange, due to its slightly opinion polling nature. This is not my intention, I am simply ...
4 votes
3 answers
482 views

Concept to validate objects across languages?

An interesting question I've stumbled upon: Let's assume a java application creates a data model, converts this data to a json object with two fields and uploads it to a server: { "FirstName": "...
  • 723
6 votes
5 answers
2k views

Should I assert the preconditions of functions in a public API?

I am writing a library for some data structures in C that will be used in embedded systems. I have had issues designing and coming up with a solid error handling plan. This API is only subject to ...
4 votes
3 answers
459 views

How to loosen input contracts by inheritance?

According to LSP wiki: Substitutability is a principle in object-oriented programming stating that, in a computer program, if S is a subtype of T, then objects of type T may be replaced with ...
  • 1,141
2 votes
0 answers
192 views

Are there issues in using Design by Contract effectively within the typical software development process? [closed]

I'm in the early stages of learning design-by-contract (DbC). And I think that if followed correctly, it can produce very high quality software. This gets me wondering though... why isn't it used a ...
3 votes
2 answers
821 views

Is expecting the API user to implement an UnsupportedOperationException okay?

I'm writing a handler for download/import of data. After inserting data to the database, several import jobs can be called, but usually it is just one. So there are two methods to get the import job(s)...
  • 201
4 votes
1 answer
2k views

Is Design by Contract the same as using Interfaces to create a "contract"?

Does an OOP design that uses a Design by Contract mean the designer is using interfaces to create a "contract." The term "contract" is used quite often when discussing OOP interfaces, so I didn't ...
  • 3,629
2 votes
2 answers
929 views

Stack implementation by Design by Contract vs Defensive Programming

I am trying to write Stack code using the two techniques i.e Design by Contract vs Defensive Programming but I am not sure if I am doing right or not.I am not throwing any kind of exception or error ...
4 votes
3 answers
675 views

In design by contract, why preconditions should be ensured by a client and postconditions - by a supplier?

I'd heard about Design by Contract a long time ago and always was confused by this question. The approach uses real-world client-supplier analogy to describe caller-callee relationships. It stays, ...
5 votes
1 answer
305 views

Detailed Scope of Work.. Waterfall?

I have a client that's requested a detailed Scope of Work/Statement of Work. Upon looking into it, it seems they want timelines, costs, features, the whole nine. In order to do a detailed SOW, one ...
  • 2,642
3 votes
1 answer
139 views

What makes design by contract a tool?

Design by contract is based on Hoare logic where a proof of correctness of a program is established by reasoning over pre/post conditions and invariants. What are the means and prerequisites of a ...
4 votes
4 answers
600 views

Purpose of assertion messages

Some languages and libraries can associate assertion messages with assertions. Such assertion messages are included in error messages when the assertion does not hold. Examples are Java, Class::...
3 votes
3 answers
316 views

Writing your test assertions in your function comments (just before the code)?

I'm using PHP and PHPUnit. Something bothers me: the fact that the assertions are in another class (too easy to forget or to ignore, for any new programmer in the project). If the test assertions ...
0 votes
0 answers
246 views

Design by Contract and Defensive Programming Confusion [duplicate]

I have been interested in better coding practices/methods which makes the reliability and maintenance less painful effort. I read the chapter about Design by Contract on "Object Oriented Software ...
  • 109
0 votes
3 answers
215 views

Defining resource allocation in method documentation

I want to write a library with "no resource leak guarantee" feature. So I shall know whether each method allocates any resource or not. It may change the code. For example: void foo() { ...
  • 359
1 vote
4 answers
143 views

Does design by contract imply correct output?

Design by Contract says, in terms of the function talking: "you give me all the right parameters and I'll give you exactly this kind of data" ...in essence. So, given that, should I use up resources ...
1 vote
1 answer
186 views

Alternatives to JDT Annotation - License issues

I have used the JDT Annotation library in my Java project as I am quite fond of what it offers. To be more exact, I used the @Nullable and @NonNullByDefault annotations as I can use the synergy with ...
  • 123
6 votes
1 answer
1k views

Advantages of using the library PyContracts over assert statements

Today I stumbled upon the python package called PyContracts. However, python has the assert statement which seems to allow you to do exactly those things. What advantages do contracts have over assert ...
  • 341
5 votes
3 answers
645 views

What is the difference between dependent typing and contracts?

What is the difference between dependent typed languages and languages like Spec# and Eiffel that allow you to specify "contracts" for functions in your code for pre/postconditions? Is dependent ...
5 votes
2 answers
440 views

Earliest use of Comments as Semantically Meaningful Things in a Program?

In certain corners of the PHP meta-programming world, it's become fashionable to use PHPDoc comments as a mechanism for providing semantically meaningful information to a program. That is, other code ...
5 votes
2 answers
857 views

How are design-by-contract and property-based testing (QuickCheck) related?

Is their only similarity the fact that they are not xUnit (or more precisely, not based on enumerating specific test cases), or is it deeper than that? Property-based testing (using QuickCheck, ...
  • 163
3 votes
2 answers
609 views

Why is design by contract considered an alternative to the pseudo programming process?

Right now I'm reading Code Complete by Steve McConnell and in chapter 9 he talks about the Pseudo Programming Process (PPP). From what I've understood, the PPP is a way of programming in which the ...
5 votes
2 answers
884 views

Options for programming by contract in Java

I am working on a project (which includes JavaEE web apps and JavaSE apps) that has grown from a single developer to a team of three, and issues of readability and robustness are starting to emerge. ...
  • 159
9 votes
3 answers
3k views

Checking preconditions or not

I've been wanting to find a solid answer to the question of whether or not to have runtime checks to validate input for the purposes of ensuring a client has stuck to their end of the agreement in ...
  • 4,873
41 votes
9 answers
5k views

Why is there such limited support for Design by Contract in most modern programming languages?

I recently discovered Design by Contract (DbC) and I find it an extremely interesting way to write code. Among other things, it would seem to offer: Better documentation. Since the contract is the ...
54 votes
10 answers
34k views

Should a method validate its parameters? [duplicate]

Say you are designing a Square root method sqrt. Do you prefer to validate the parameter passed is not a negative number or do you leave it up to the caller to make sure the param passed is valid. How ...
  • 1,942