design-by-contract

How to show if a method may return null

可紊 提交于 2019-11-28 19:06:11
After posting this question and reading that one I realized that it is very important to know if a method is supposed to return null, or if this is considered an error condition and an exceptions should be thrown. There also is a nice discussion when to return ‘null’ or throw exception . I'm writing a method and I already know if I want to return null or throw an exception, what is the best way to express my decision, in other words, to document my contract? Some ways I can think of: Write it down in the specs / the documentation (will anyone read it?) Make it part of the method name (as I

A good Design-by-Contract library for Java? [closed]

。_饼干妹妹 提交于 2019-11-28 16:49:44
A few years ago, I did a survey of DbC packages for Java, and I wasn't wholly satisfied with any of them. Unfortunately I didn't keep good notes on my findings, and I assume things have changed. Would anybody care to compare and contrast different DbC packages for Java? There is a nice overview on WikiPedia about Design by Contract , at the end there is a section regarding languages with third party support libraries , which includes a nice serie of Java libraries. Most of these Java libraries are based on Java Assertions. In the case you only need Precondition Checking there is also a

Why is design-by-contract not so popular compared to test-driven development?

混江龙づ霸主 提交于 2019-11-28 16:31:41
You may think this question is like this question asked on StackOverflow earlier. But I am trying to look at things differently. In TDD, we write tests that include different conditions, criteria, verification code. If a class passes all these tests we are good to go. It is a way of making sure that the class actually does what it's supposed to do and nothing else. If you follow Bertrand Meyers ' book Object Oriented Software Construction word by word, the class itself has internal and external contracts, so that it only does what its supposed to do and nothing else. No external tests required

'Design By Contract' in C#

对着背影说爱祢 提交于 2019-11-28 03:12:10
I wanted to try a little design by contract in my latest C# application and wanted to have syntax akin to: public string Foo() { set { Assert.IsNotNull(value); Assert.IsTrue(value.Contains("bar")); _foo = value; } } I know I can get static methods like this from a unit test framework, but I wanted to know if something like this was already built-in to the language or if there was already some kind of framework floating around. I can write my own Assert functions, just don't want to reinvent the wheel. Luke Quinane C# 4.0 Code Contracts Microsoft has released a library for design by contract in

Design By Contract and Test-Driven Development [closed]

半城伤御伤魂 提交于 2019-11-28 03:09:27
I'm working on improving our group's development process, and I'm considering how best to implement Design By Contract with Test-Driven Development. It seems the two techniques have a lot of overlap, and I was wondering if anyone had some insight on the following (related) questions: Isn't it against the DRY principle to have TDD and DbC unless you're using some kind of code generator to generate the unit tests based on contracts? Otherwise, you have to maintain the contract in two places (the test and the contract itself), or am I missing something? To what extent does TDD make DbC redundant?

api documentation and “value limits”: do they match?

情到浓时终转凉″ 提交于 2019-11-28 01:59:46
Do you often see in API documentation (as in 'javadoc of public functions' for example) the description of "value limits" as well as the classic documentation ? Note: I am not talking about comments within the code By "value limits", I mean: does a parameter can support a null value (or an empty String, or...) ? does a 'return value' can be null or is guaranteed to never be null (or can be "empty", or...) ? Sample: What I often see (without having access to source code) is: /** * Get all readers name for this current Report. <br /> * <b>Warning</b>The Report must have been published first. *

Is Spec# stable enough to use? [closed]

自闭症网瘾萝莉.ら 提交于 2019-11-27 16:56:45
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . Does anyone here use Spec# regularly? I would like to know if it is stable and powerful enough before I start using it everywhere. It looks like the

Java: clean way to automatically throw UnsupportedOperationException when calling hashCode() and equals()?

耗尽温柔 提交于 2019-11-27 12:28:33
问题 We've got an OO codebase where in quite a lot of cases hashcode() and equals() simply don't work, mostly for the following reason: There is no way to extend an instantiable class and add a value component while preserving the equals contract, unless you are willing to forgo the benefits of object-oriented abstraction. That's a quote from "Effective Java" by Joshua Bloch and there's more on that subject in a great Artima article here: http://www.artima.com/lejava/articles/equality.html And we

ReSharper - Possible Null Assignment when using Microsoft.Contracts

笑着哭i 提交于 2019-11-27 10:19:47
Is there any way to indicate to ReSharper that a null reference won't occur because of Design-by-Contract Requires checking? For example, the following code will raise the warning ( Possible 'null' assignment to entity marked with 'NotNull' attribute ) in ReSharper on lines 7 and 8: private Dictionary<string, string> _Lookup = new Dictionary<string, string>(); public void Foo(string s) { Contract.Requires(!String.IsNullOrEmpty(s)); if (_Lookup.ContainsKey(s)) _Lookup.Remove(s); } What is really odd is that if you remove the Contract.Requires(...) line, the ReSharper message goes away. Update I

A good Design-by-Contract library for Java? [closed]

岁酱吖の 提交于 2019-11-27 09:57:52
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . A few years ago, I did a survey of DbC packages for Java, and I wasn't wholly satisfied with any of them. Unfortunately I didn't keep good notes on my findings, and I assume things have changed. Would anybody care to compare and contrast different DbC packages for Java? 回答1: There is a nice overview on WikiPedia