Slashdot Mirror


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++?"

7 of 114 comments (clear)

  1. In C++ by revlayle · · Score: 2, Funny

    I call that "using interfaces" and "strict polymorphism" (and "bunnies"!!!)

  2. I don't understand the question... by Anonymous Coward · · Score: 4, Funny

    ...but I'm sure Java + XML is the answer.

    1. Re:I don't understand the question... by WilliamSChips · · Score: 3, Funny

      Anything is a better answer than C++ for anything. Except maybe COBOL and shell script.

      --
      Please, for the good of Humanity, vote Obama.
    2. Re:I don't understand the question... by WilliamSChips · · Score: 2, Funny

      I deliberately did that. Perl isn't a programming language, it's a natural language that is somehow parsed by the compiler

      --
      Please, for the good of Humanity, vote Obama.
    3. Re:I don't understand the question... by Haeleth · · Score: 5, Funny

      Perl isn't a programming language, it's a natural language that is somehow parsed by the compiler

      I must strongly object to your use of the term "natural" in that statement.

  3. Simple Solution - Violence by Anonymous Coward · · Score: 5, Funny

    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

  4. Re:Verbal Contracts by eln · · Score: 2, Funny

    If you make the contract long and detailed enough, it provides something to beat coders with when they violate the contract.