Design By Contract (DbC)
Tags: programming, beginners, tutorial, productivity
Published: 2022-03-15 17:07:01

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">This time I don’t want to write about a brilliant feature of IRIS</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(of</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> which it has many), but instead about a feature that is sorely missing.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">Today, talking about OOP is not sexy. Although almost all modern programming languages implement some kind of OOP,  discussions about fundamental issues of software development are not very common between real-world implementors of such technologies as developers are. In fact, Computer Science as a whole isn’t a mainstream topic between developers, which I think it should be.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">In this InterSystems Developers Community,  most posts are about questions</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(How</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> do I … ?) of how to use the technology or practical solutions to a problem</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(How</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> can I … ?).</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">But not many are about fundamental computer science concepts and how they are implemented</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(or</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> not) in our favorite Data Platform.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">How can one be using a fundamental concept such as OOP, but not discussing it how it is being implemented in your favorite platform?</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">It is the same with everybody using</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(and</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> having opinions about) REST API’s without even knowing what REST means or have read Roy Fielding’s dissertation.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">Or using the concept of an ESB and know nothing about Dave Chappel’s book where he first introduced the term Enterprise Service Bus.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">(Mis)Using the term</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘agile’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> without ever having read the Agile Manifesto.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">One of my all-time favorite books about computer science and OOP is Bertrand Meyer’s book Object-Oriented Software Construction</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(2nd</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> Ed)</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(OOSC),</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> a classic about software quality, robustness, extensibility, and reusaibility, and why OOP is a solution for many of these issues.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">Every developer who is using classes, objects, methods, and inheritance should read this book.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">Based on the work of DataTree, InterSystems has made an excellent OOP implementation with Cache and the Cache Object Script extensions to Mumps. Great multiple inheritance</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(of</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> which I will probably write a different article) and polymorphism, not only in the programming language but also in the database. In my opinion, the only</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(but</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> unique) combination that truly implements OOP: code and data in one place.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> </span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">But what IRIS lacks and which is described in detail in OOSC,  is a feature that lays a concise robustness layer upon OOP which is called Design by Contract.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">What we often see in code</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(methods)</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> is:</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">method getMail(id) → Mail</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">  If not id return</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-ldquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-ldquo">“Id</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> is required”</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">This is what we call</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘defensive</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> programming’, the method being called is arming itself against</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘illegal’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> invocations.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">But the</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘contract’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> of the method is obvious: if you give me an</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(valid)</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> id I will return the associated email message, this code, executed at every invocation, shouldn’t be necessary. This way the responsibility is being shifted from the caller to the method being called.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">DbC is all about that, the</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘contract’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> of a class or a method or an object instance of that class states precisely what is expected as input and what is promised as output as long as the caller adheres to the contract of the method</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(or</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> the class as a whole).</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">DbC is defensive programming on steroids, without the runtime penalty of checking everything: you describe all constraints at design time.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">DbC has two runtime modes: development and production.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">In development mode, all constraints and checks are executed and reported.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">In production mode, they will only be executed in case of an exception.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">How does DbC do that?</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">At a class level, you define</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘invariants’:</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> conditions that need to be met at all times</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(entering</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> constructor methods excluded).</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">At a method level, you define pre-conditions and post-conditions.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">Before even executing a single line of code, the pre-conditions must be met.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">After having executed the method’s code the post-conditions must be met, for that for every property there is an</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘old’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> value, the value the property had before the method was executed.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">And for both entering as well as exiting the method, the invariants must still be valid.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">In development mode, these conditions will all be executed. At that level you can choose how to handle unfulfilled conditions: throw an error or just report the event.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">In production mode, the conditions will not be executed, but in the advent of an exception within the method, both invariants and pre-conditions will be checked and are part of the exception info, after that an error is being raised at all times.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">You can also define a</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘rescue’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> method, code that is being executed when an exception occurs, from setting database values, closing files and connections, executing repair code, etc. You can even set a</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘try-again’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> flag.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">Of course, the latter you can also achieve with IRIS standard $ZTrap or Try-Catch mechanisms.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">Why should we want DbC in IRIS Objectscript?</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">I think the code will be much more robust and, having not to worry about performance penalties at runtime, the conditions can</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lparen"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lparen">(should)</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> be quite elaborate.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">Having constructed the right set of conditions, unit-tests would hardly be needed, the</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘tests’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> will be run at every invocation of a method. And, in contrary to separate unit-test frameworks, the conditions are right in the code, it’s documentation too.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">If DbC is so great why isn't it widely applied?</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">Coming back to my introduction: ignorance.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">As developers, in general, don’t</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘do’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> Computer Science, they will never be able to grasp the essence of fundamental computer engineering concepts. But, even worse, educators, professional training programs, and</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘experts’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> are hardly aware of the DbC concept.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">(Unit) Testing is a far more easy concept to understand than writing a</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z s-lsquo"> </span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z h-lsquo">‘contract’</span><span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z"> for classes or code.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">I also expect it to be quite difficult to build into an existing language or compiler.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">There are a few languages that have DbC built-in, most prominent is Eiffel, a language, not entirely surprising, designed by Bertrand Meyer.</span>
</div>

<div>
   
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">At InterSystems the trend seems to be slowly moving away from ObjectScript, especially with the upcoming Embedded Python feature, which is a brilliant move.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">But when ObjectScript could have DbC built-in, the language would get a tremendous boost for designing robust applications.</span>
</div>

<div>
  <span class="author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90z95iylplm6z82zz76zpn6ddz78z7z68zz78zz81zqz88zz77zgiz83zz76zz84zz66zz87z">It would be interesting to learn what the ObjectScript core developers have to say about this matter.</span>
</div>

<div>
   
</div>