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
2
votes
1answer
139 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 ...
0
votes
1answer
65 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 ...
5
votes
2answers
230 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": "...
4
votes
4answers
740 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
3answers
322 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
vote
0answers
129 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
2answers
399 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)...
4
votes
1answer
987 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 ...
1
vote
2answers
601 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
3answers
363 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
1answer
230 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 ...
3
votes
1answer
106 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
4answers
298 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
2answers
252 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
0answers
160 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 ...
0
votes
3answers
184 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() { ...
1
vote
4answers
132 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
1answer
171 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 ...
6
votes
1answer
754 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 ...
5
votes
3answers
514 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
2answers
436 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
2answers
610 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, ...
3
votes
2answers
498 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
2answers
795 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. ...
8
votes
3answers
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 ...
40
votes
9answers
4k 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 ...
41
votes
10answers
25k 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 ...