Design by Contract in C++?
An anonymous reader asks: "I have read some of the stuff on Eiffel, watched their tutorial videos about design by contract, and the entire thing sounds like a pretty good idea. However, the problem is that we don't use Eiffel at work, and I highly doubt I could get people to come around to the idea of switching to it. Although we use a lot of C++, I can imagine that a lot of the ideas from Eiffel can be applied there. I have looked around on the net and found a few articles talking about different ways of applying design by contract using assert statements and the like. I also found the dlib C++ library on SourceForge which, among other things, puts a design by contract face on a lot of API calls. So, there are obviously people doing it. What is everyone's experience with Design by Contract in C++? What tools are there that help make it a workable system? Lastly, are there any pitfalls to taking this approach in C++?"
I call that "using interfaces" and "strict polymorphism" (and "bunnies"!!!)
...but I'm sure Java + XML is the answer.
I place a one line comment above each of my C++ functions that I want to have Eiffel like design by contract features:
// Note: If you don't pass reasonable values to this function I will fucking kill you
-
-
- void
- DoSomething(...)
- {
- }
PS F Ghandi
If you make the contract long and detailed enough, it provides something to beat coders with when they violate the contract.