title: Why is design-by-contract not so popular compared to test-driven development?
body: <p>You may think this question is like <a href="https://stackoverflow.com/questions/394591/design-by-contract-and-test-driven-development">this</a> question asked on StackOverflow earlier. But I am trying to look at things differently.</p>
  
  <p>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.</p>
  
  <p>If you follow <em>Bertrand Meyers</em>' book <em>Object Oriented Software Construction</em> 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 because the to code to ensure contract is followed is the part of the class.</p>
  
  <p>Quick example to make things clear</p>
  
  <blockquote>
    <p><strong>TDD</strong></p>
    
    <ol>
    <li><p>Create test to ensure that in all cases a value ranges from (0-100)</p></li>
    <li><p>Create a class containing a method that passes the test.</p></li>
    </ol>
    
    <p><strong>DBC</strong></p>
    
    <ol>
    <li>Create a class, create a contract for that member <code>var</code> to range from (0-100), set contract for contract breach, define a method.</li>
    </ol>
  </blockquote>
  
  <p>I personally like the DBC approach.</p>
  
  <hr>
  
  <p>Is there a reason why pure DBC is not so popular? Is it the languages or tools or being Agile or is it just me who likes to have code responsible for itself?</p>
  
  <p>If you think I am not thinking right, I would be more than willing to learn.</p>