comp.lang.ada
 help / color / mirror / Atom feed
From: Mace Ayres <mace.ayres@gmail.com>
Subject: Re: Why *.adb and *.ads?
Date: Sat, 27 Jan 2018 08:40:46 -0800 (PST)
Date: 2018-01-27T08:40:46-08:00	[thread overview]
Message-ID: <9dd4fa3e-4c0d-438d-9d6f-664a91347bfe@googlegroups.com> (raw)
In-Reply-To: <sr-dnX5CE7MbA_HHnZ2dnUU7-YPNnZ2d@giganews.com>

Ada, like Pascal,  on which Ada is substantially based, requires declaration of functions, procedures, and other elements (types I think)  before they are used, a pre-declaration. This is unlike other languages that allows you declare and use and variable like Basic, or Python or the like where you can invent things about anywhere on the fly. The Pascal/Ada “definition” or pre declaration defines the type name, parameters in and return types, and supports the Strong Typing and safety characteristics of Ada.  The compiler can then enforce proper use of the functions, procedures, an types later in the program, because it has a reference standard, the predeclaration/definition to validate proper use and compilation.  In Pascal, the declarations simply had to be put before the full body of the procedure/function, all in one file.

With GNAT you can put the specification/predeclaration and body (full source code not just the high level definition) in a single file.

But, by using the *.ads to contain the specification and the *.adb to contain the full elaboration, the pre-declaration/specification and subsequent body distinction are enforced, both logically for the developer, and compiler.

Also, if you have a large body file *.adb, you can look at the *.ads and quickly see all the functions and procedures that are in the body, though Ada best practices says not to put loo many procedures and functions in a *.adb file (package). In the past, I have seen, and have myself, put a large comment section at the start of a body of code that listed all the following procedures/functions, with parameters, and their intended use, in languages that did not specifically require prior declarations.This useful in large long lived programs where many developers may work on the code over time. It provides a quick way to see at a high level, what’s in a large body of code.

Also, pre declaration/specification is a solid step forward in CS languages when it emerged some decades past.


      parent reply	other threads:[~2018-01-27 16:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-01 20:15 Why *.adb and *.ads? Andrew Shvets
2018-01-01 21:00 ` Jeffrey R. Carter
2018-01-02  1:50   ` Mace Ayres
2018-01-02  1:27 ` Mace Ayres
2018-01-27 15:45 ` Norman Worth
2018-01-27 16:37   ` Dennis Lee Bieber
2018-01-27 22:18     ` [OT] VMS editors and PC keyboards, was: " Simon Clubley
2018-01-27 16:40   ` Mace Ayres [this message]
replies disabled

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