design-by-contract

Does Design By Contract Work For You?

Do you use Design by Contract professionally? Is it something you have to do from the beginning of a project, or can you change gears and start to incorporate it into your software development lifecycle? What have you found to be the pros/cons of the design approach? I came across the Design by Contract approach in a grad school course....

design by contract tests by assert or by exception?

When programming by contract a function or method first checks whether its preconditions are fulfilled, before starting to work on its responsibilities, right? The two most prominent ways to do these checks are by assert and by exception. assert fails only in debug mode. To make sure it is crucial to (unit) test all separate contract ...

The best way to assert pre-condition and post-condition of arguments and values in .NET?

I have been thinking about design by contract lately and I was wondering what people think is the best way to assert pre-condition and post-condition of values in .NET? i.e. validating argument values to a method. Some people recommend Debug.Assert while others talk about using an if statement plus throwing an exception. What are the pr...

Ruby and duck typing: design by contract impossible?

Method signature in Java: public List<String> getFilesIn(List<File> directories) similar one in ruby def get_files_in(directories) In the case of Java, the type system gives me information about what the method expects and delivers. In Ruby's case, I have no clue what I'm supposed to pass in, or what I'll expect to receive. In Ja...

'Design By Contract' in C#

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 kn...

How much null checking is enough?

What are some guidelines for when it is not necessary to check for a null? A lot of the inherited code I've been working on as of late has null-checks ad nauseam. Null checks on trivial functions, null checks on API calls that state non-null returns, etc. In some cases, the null-checks are reasonable, but in many places a null is not a ...

Design By Contract and Test-Driven Development

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 ...

Compile time checking in Design by Contract?

I read that compiler can enforce dbc at compile time.. How does it do it? ...

Is Spec# stable enough to use?

Hi, 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 syntax is influencing c# 4.0, which will hopefully make it easier to upgrade once 4.0 is released. Thoughts? ...

How do you do Design by Contract in Perl?

I'm investigating using DbC in our Perl projects, and I'm trying to find the best way to verify contracts in the source (e.g. checking pre/post conditions, invariants, etc.) Class::Contract was written by Damian Conway and is now maintained by C. Garret Goebel, but it looks like it hasn't been touched in over 8 years. It looks like wha...

What is the best way to write a contract for CSS usage in Web Development?

Our Dev team had been developing enterprise web page more than 2 years ago. We are curious to know what is the best way to write a contract for CSS usage. For example, if we have a COMP, how we agree on a contract so our developers and our designers agree and we don't have to go back. Is there a tool that is available for this type ...

What do you think of the Managed Contract Tools library

I recently saw this video http://channel9.msdn.com/pdc2008/TL51/ about the managed Contract tools library which certainly looks very interesting. Sadly it seems they won't include this into the language itself which would have been more elegant as in Spec#. It would be nice to have is as both options in C#4.0 in fact as the Contracts add...

Design By Contract vs Test Driven Development ?

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 its suppo...

How can I show that a method will never return null (Design by contract) in C#

I have a method which never returns a null object. I want to make it clear so that any user that is using my API don't have write code like this: if(Getxyz() != null) { // do stuff } How can I show this intent? ...

Whats wrong with non nullable objects?

I have been looking at DbC lately and Spec# which seem to have support for non nullable objects. Unfortunately Spec# seem to have been abandoned. Spec# seemed to have lots of nice language features built in so why was it abandoned? Would there be any problem with letting all objects be non-nullable by default so you would have to write...

DbC (Design by Contract) and Unit Tests

I am using contracts with C# 4.0 and before I was using lots of unit tests (not with TDD). I am wondering if DbC eliminates the need to write external unit tests? Personally I find contracts better to make robust frameworks, as the contracts are closely coupled with the code itself, and offers other benefits. What do you guys think? ...

Code Contracts, will you use them?

Microsoft just released Code Contracts, a tool that integrates with Visual Studio and allows you to define contracts for your .Net code and get runtime and compile time checking. Watch the video on Channel 9 that shows how it being used. For now it's an add-on but it will be part of the Base Class Library in .Net 4.0 Is this something...

Business entities / value objects framework with DbC support

The thing I think I spend most time on when building my business models is the validation of business entities and making sure the entity objects and their relationships maintains good integrity. My dream for a good entity/value object framework would help me create reusable entities/value objects and easily create constraints and rules ...

What is the current best validation framework for asp.net apps?

To make sure its a DRY approach all validation logic should of course go in the business logic (model). How are validation messages presented to views, should be able to localize error messages Can you generate javascript from the validation framework. Compatibility with JQuery would be perfect Is the framework compatible with a DbC ap...

Can Design-by-Contract be applied to dynamic languages as easily/well as to statically-typed ones?

The title pretty much sums up the gist. I'm interested in whether it is possible to enable/disable contract enforcement(s) when using a dynamic language without running a serious risk of poorly/un-diagnosed failure? If not, the crux seems (to me) to be that any enforcements are a required part of the component's logic, rather than opti...