comp.lang.ada
 help / color / mirror / Atom feed
From: Brad Moore <bmoore.ada@gmail.com>
Subject: Re: Is the Documentation In a spec File Usually Enough For You ?
Date: Thu, 18 Oct 2018 08:24:37 -0700 (PDT)
Date: 2018-10-18T08:24:37-07:00	[thread overview]
Message-ID: <d3cce76a-d0c7-4086-8929-e585ef219a67@googlegroups.com> (raw)
In-Reply-To: <eec140a3-cab7-43d2-a6a1-dc7ebce86a5b@googlegroups.com>

It should also be mentioned that with Ada 2012, the addition of contracts helps also aid to reader of a spec understand what a subprogram does, and how it was intended to be used by the author. 

A problem with documentation is that it can become stale if not maintained, whereas the contracts are assertions in the code and thus tend to be more accurate. 

A designer of a package should consider, for example, what pre and post conditions should be applied to the subprograms of that package. The addition of contracts tends to simplify the documentation that is needed.

As an example, in the standard package
Ada.Locales, there is;

   type Country_Code is new String (1 .. 2)
      with Dynamic_Predicate =>
         (for all E of Country_Code => E in 'A' .. 'Z');

 function Country return Country_Code;

If we didn't have the contract for Dynamic_Predicate on the Country_Code type, 
we would need to document that the function Country returns a 2 character string where all the characters of the string consist of capital letters from A to Z inclusive.  

With the contract, this doesn't need to be documented, and the contract is more concise for the reader than having to read a full paragraph of text. Further, anywhere the Country_Code result is used in the user's program, it is clear that the contract holds, since it is a property of the type.

If the implementation changes in a way that breaks the contracts, then this tends to get caught, and either the implementation is adjusted to meet the contracts, or the contracts are adjusted to meet the implementation. Generally one tries to avoid making changes to contracts, particularly if there are existing users of those contracts.

Brad


  reply	other threads:[~2018-10-18 15:24 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-15  0:42 Is the Documentation In a spec File Usually Enough For You ? patrick
2018-10-15  5:44 ` Henrik Härkönen
2018-10-15  7:22 ` Dmitry A. Kazakov
2018-10-15  7:42 ` Niklas Holsti
2018-10-15 10:05 ` AdaMagica
2018-10-15 11:25   ` patrick
2018-10-15 11:57     ` Markus Schöpflin
2018-10-15 13:02       ` patrick
2018-10-15 16:50 ` Jeffrey R. Carter
2018-10-16  9:57   ` AdaMagica
2018-10-16 16:57     ` Jeffrey R. Carter
2018-10-18  9:06       ` AdaMagica
2018-10-18 15:24         ` Brad Moore [this message]
2018-10-18 17:29         ` Jeffrey R. Carter
2018-10-18 17:54           ` AdaMagica
2018-10-18 18:50             ` Dennis Lee Bieber
2018-10-18 20:07             ` Jeffrey R. Carter
2018-10-21 15:20               ` AdaMagica
2018-10-21 18:56                 ` Jeffrey R. Carter
2018-10-22 16:04                   ` AdaMagica
2018-10-22 19:13                     ` Jeffrey R. Carter
2018-10-23 10:00                       ` AdaMagica
2018-10-18 21:24             ` Randy Brukardt
2018-10-19  7:39               ` J-P. Rosen
2018-10-20  1:27                 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox