217 questions
1
vote
1
answer
105
views
How can I have more information in a Predicate_Failure?
I want to be able to include information about my type in the Predicate_Failure message. Here's what I have that works:
subtype Norm is Float range 0.0..1.0;
type Component is (Red, Green, Blue, ...
0
votes
2
answers
163
views
Ada design by contracts critical software
I have a question related to applying contracts in a critical environment.
Imagine I have the following function to divide:
function div (dividend, divisor : Float) return Float
with Pre => divisor ...
0
votes
0
answers
42
views
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 ...
0
votes
1
answer
271
views
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 ...
1
vote
1
answer
863
views
Strengthening and Weakening of pre and post conditions
I have been reading into the topic of Design By Contract and so far have the following notes written:
When strengthening a condition, it means to make it
more restrictive and weakening a condition is ...
0
votes
1
answer
360
views
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 ...
0
votes
1
answer
45
views
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 ...
0
votes
1
answer
372
views
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 :=...
0
votes
1
answer
39
views
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" ...
2
votes
1
answer
110
views
Custom condition failure messages in Ada 2012
Is there a way to specify a custom error/on failure message for pre- and postconditions, by analogy with Predicate_Failure for predicates? I can't seem to be able to find anything in the official ...
0
votes
2
answers
141
views
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 ...
0
votes
1
answer
43
views
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'...
0
votes
1
answer
3k
views
Node.JS service layer design
I have a very simple express js server that accepts a request from a client, performs some business logic and respond back to the client. The request - response pipeline is handled by a controller and ...
3
votes
1
answer
104
views
I need a basic concrete example on how to use TDD along with Design by Contract
I have seen many questions like this and this. Some people see there is overlapping between TDD and Design by Contract and others say they are complementary, I am biased to the second one, so I need a ...
1
vote
1
answer
175
views
Should precondition methods be public or private?
The precondition code in methods markStudent(...) and getUnitMark(...) makes use of other method of the class: isEnrolled(...) and hasCompletedAssessments(...).
import java.util.ArrayList;
import ...
1
vote
2
answers
88
views
How emphasize restrictions for input data in unit testing?
I have parametrized test, for example:
import pytest
from datetime import time
def get_next_hour(time_str: str):
t = time(*map(int, time_str.split(':')))
new_t = time((t.hour + 1) % 24, t....
0
votes
2
answers
791
views
Tool/Technique for Automatic Unit Test Generation based on Method Pre-/Post-Conditions
I wonder if there is any tool that automatically generates unit tests based on a method's pre- and post-conditions (and class invariant).
To be precise, suppose we are given pre- and post-conditions (...
1
vote
1
answer
238
views
Is it possible to enforce Design by Contract checks at compile time?
Reading Design by Contract tutorial I stumbled upon the following line:
Contracts in Eiffel are not just wishful thinking. They can be monitored at run time under the control of compilation options....
0
votes
2
answers
117
views
Returning Null vs Exception vs Contract
What would be considered an acceptable way of dealing with returning a record from a DB with the following 3 potential outcomes:
Db connection works, finds a user and returns a populated user object
...
0
votes
1
answer
124
views
Eiffel: Unknown identifier on attached check into require statement
require
valid_item: attached item as l_i and then l_i.valid_for_insert or l_i.valid_for_update
why do I have an unknown identifier here with l_i??!!!
0
votes
1
answer
88
views
Eiffel: is there a way to express a double implies clause in eiffel?
Like double bind in psychology, is there a way to tell that one expression implies another and reversely?
valid_last_error: attached last_error implies not attached last_success_message
...
-3
votes
2
answers
109
views
Can I rely to ISE Eiffel as a programming language to offer web services through a DB connection [closed]
I'm actually working for a little company of 10 people on the area of solar panels solutions in Chile. Am working on linux since 20 years now. When I studied programing I studied a lot with Eiffel ...
0
votes
1
answer
122
views
Dbc - anyone actually dare not to check preconditions in the called routines?
I know that DbC mandates that the caller is responsible for the precondition (parameters or maybe values of member variables) and I have just read, in one of the books, that actually few people are ...
4
votes
1
answer
55
views
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 ...
0
votes
1
answer
316
views
Java Cofoja not working in eclipse
I tried to setup Cofoja in my eclipse project as described here.
When I try to run my project with Cofoja I always get an IllegalArgumentException.
[com.google.java.contract:agent FATAL ERROR while ...
2
votes
1
answer
860
views
Code Contracts is not supported in Visual Studio 2017, How to implement it with PostSharp?
At the time of writing this question CodeContracts by Microsoft, the Visual Studio extension that implements Design by Contract for .NET is not supported in Visual Studio 2017.
Looking at the ...
4
votes
1
answer
2k
views
How can assertions be placed before a class initialisation list?
Is it possible to assert something about the parameters on a class constructor before the initialisation list is called?
class Foo
{
int m_lower;
int m_upper;
unsigned int m_delta;
...
0
votes
3
answers
1k
views
Should a Repository throw an exception if no change is to be stored?
During the stipulation of the contracts of my Repositories I started to wonder about an essential contract of any Repository:
What happens if Update is called with a an entity on which no change is to ...
0
votes
1
answer
365
views
Spring Cloud Contract: Access hostname and port in contract response for URL generation
we are trying to provide a contract with the following characteristics:
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method(GET())
url("/v2/...
6
votes
1
answer
346
views
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.
2
votes
1
answer
126
views
How to configure Eclipse (Java) to recognize custom assertion when checking against potential null pointer
I have the following piece of Java code:
public void silence(final Object key) {
final Chain chain = (Chain)getChain(key);
checkPrecondition(chain != null);
chain.silence();
}
The ...
1
vote
3
answers
216
views
Is "A requirement that should be satisfied by the function before it ends." a right definition for postcondition, in Python?
In "Think Python: How to Think Like a Computer Scientist", the author defines postcondition as:
A requirement that should be satisfied by the function before it ends.
He also states:
Conversely,...
0
votes
1
answer
2k
views
Preconditions and postconditions in interfaces and abstract methods
I'm trying to implement my own programming language, and i'm currently doing lexing and parsing. I'm nearly done and want to add native support for class invariants, preconditions and postconditions.
...
2
votes
1
answer
2k
views
Making sense of non-null and nullability annotations
I am not clear about how we properly use the annotation about nullable i.e. NonNull and Nullable.
I am not really comfortable with something like the following:
public void foo(@NonNull ArrayList&...
1
vote
2
answers
590
views
Validating input parameters
I'm trying to decide if I should use exceptions, asserts or boundary checks in some of my code.
The program contains a lot of calculations that is dependent on user input. The program is running on ...
1
vote
1
answer
179
views
Design-by-contract finding pre-conditions
I have to create a Calculator in Java, based on this Interface.
public interface CalculatorIF {
int add(int x, int y);
int sub(int x, int y);
int mult(int x, int y);
//double div(int ...
0
votes
2
answers
568
views
Liskov Substitution Principle (LSP) violated via Design By Contract (DBC)?
I'm writing a framework in PHP, and have run into a pattern which smells bad. It appears that I'm implementing a contract (q.v. Design By Contract) that violates the Liskov Substituion Principle (LSP)...
2
votes
0
answers
63
views
Nemerle - How do I write a method signature with a generic constraint and "requires" condition?
Using Nemerle, I want to create a method that has a generic type constraint and a 'requires' pre-condition. What is the proper order/syntax for these, with respect to the return type of the method?
...
0
votes
1
answer
406
views
How to document/assert when inheritance induces a precondition for some final types only
Consider this simple base class Foo having a function foo calling a pure virtual function foo_, documented with Doxygen :
class Foo
{
public:
/** \brief This function logs x and does the job */
...
0
votes
1
answer
215
views
Iterate through a matrix with openJML
I have a class with a matrix initialized with all 0 and 1 in a specific position:
public class MatrixTest {
/*@ spec_public @*/ int[][] griglia;
//@requires true;
//@ensures griglia[2][3]...
1
vote
1
answer
249
views
Is an exception a valid postcondition?
Consider the following interface:
public interface AISPI
{
public Path getPath(Entity entity, Entity target, World world) throws NoPathException;
}
Granted that entity, target, and world are all ...
1
vote
1
answer
72
views
XML inside an string element vs independent elements
What are the conceptual and technical disadvantages of this request/response structure:
A)
<xs:element name="OrderRequest">
<xs:complexType>
<xs:sequence>
...
2
votes
2
answers
2k
views
How can a unit test "test the contract" on a method that returns void?
Java 8 here but this is a general unit testing question that (is likely) language-agnostic.
The syntax of writing a JUnit test is easy, but deciding on what tests to write and how to test main/...
1
vote
1
answer
38
views
Interface of read_character and last_character in STD_FILES
According to a std_files.e that I have found, read_character requires not end_of_file, but it doesn't specify any post-condition; and last_character has no preconditions. Therefore, what happens if ...
7
votes
3
answers
26k
views
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 ...
18
votes
1
answer
2k
views
Common Lisp idioms for argument checking and other paranoia?
This question is about coding conventions, best practices, and style in production, mission-critical Common-Lisp code. I perused Google's Common-Lisp Style Guide, but didn't find anything clearly ...
0
votes
2
answers
1k
views
Checking preconditions on parameters in public methods
I'm going to ask your Point of view about a design matter.
The question is basically the following: a public method of an object should always check preconditions in its input parameters or is it ...
1
vote
1
answer
137
views
How to use offline bytecode writer with Cofoja?
I'm trying to do offline instrumentation of my code using Cofoja (contracts for Java). I cannot seem to get the contracts in the compiled class file using the offline bytecode writer (this feature is ...
20
votes
2
answers
3k
views
Design by Contract in Swift
Does Swift provide a native Design by Contract support? I understand that it can be done during runtime through assertions, but could it be done during compile time? Or, are there any external plugins/...
0
votes
0
answers
129
views
Braced list initialization of a container of abstract class in C++
I would like to do something similar to this:
#include <list>
#include <iostream>
#include <functional>
class Abstract {
public:
virtual void foo() = 0;
};
class Concrete : ...