comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Why .ads as well as .adb?
Date: Wed, 5 Jun 2019 17:28:09 +0300
Date: 2019-06-05T17:28:09+03:00	[thread overview]
Message-ID: <glq1rpF1v52U1@mid.individual.net> (raw)
In-Reply-To: <f611bdb8-5a40-48bd-afe5-17de72bbe193@googlegroups.com>

On 19-06-05 15:58 , Maciej Sobczak wrote:
>> On the other hand, I like it that I can get a first impression of
>> an Ada program by reading just the .ads files.
>
> This. This is important. I have seen the suggestion to treat spec
> files as a low-level requirements document, to be completed by the
> body.

I imagine that is how most Ada programmers design programs -- divide the 
thing into packages, write the specs for each package to document the 
division of responsibilities and functions, and then implement the 
bodies according to the specs. (Of course this means that the .ads files 
should contain lots of requirements written as comments or contracts.)

In the SW processes used in ESA projects, these steps are often 
separated into successive phases: architectural design first, detailed 
design+coding second, with the two phases separated by a formal review 
meeting.

> In particular, it is very difficult to explain this concept to
> beginners, because in simple examples the redundancy of syntax is
> just shocking - the package spec looks like copy-paste of signatures;

The "redundancy" applies only to subprograms, and is in fact not 
redundant once overloading is used.

Most of my specs contain mostly type declarations, with a smattering of 
subprogram declarations -- no, in fact most of my specs contain mostly 
comments to explain the types and to specify and explain what the 
subprograms (should) do. Most subprograms in the bodies are private and 
are not declared in the spec.

 > and arguably this is how some of the specs are born in practice.

Usually the body is initialized as a copy of the relevant parts of the 
spec. GPS even has a menu command for this, which generates an .adb 
file, with null subprogram bodies, from an .ads file.

I copy declarations from body to spec only if I find, while implementing 
the program, that I must publish something that I originally did not 
intend to make visible to clients.

> The language that forces me to copy-paste stuff between files is not
> inviting me to study it more deeply.

Hmm. The same copy-paste applies to C (header files vs .c files).

>> Apart from all the other reasons already given, keeping spec and
>> body in the same file can cause compilation-order problems.
>
> Only if you assume that the compiler reads the file only once and
> therefore must validate everything in a single pass.

No, the compiler does not *have* to validate everything at once, but 
mixing .ads and .adb in the same file means (as I said) that the 
compiler must have the ability to avoid validating the .adb part if it 
is only "withing" the file. This makes the compiler more complex, 
although the fact that Ada (unlike some other languages) does not allow 
application-defined syntax extensions (such as macros) would keep it 
tractable.

> Which is not the case anyway, not even in Ada

Explain why an Ada compiler should have to read a source file multiple 
times, please. GNAT does it (for .ads files and in some other cases) but 
some compilers do not, AFAIK.

If your point is only that most present-day compilers are (internally) 
multi-pass, that is true, but I don't see the relevance.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


  reply	other threads:[~2019-06-05 14:28 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-02  0:48 Why .ads as well as .adb? John Perry
2019-06-02  5:42 ` J-P. Rosen
2019-06-02  6:39 ` Dmitry A. Kazakov
2019-06-03  7:35   ` Maciej Sobczak
2019-06-03  7:57     ` J-P. Rosen
2019-06-03 19:49       ` Keith Thompson
2019-06-04  8:03       ` Maciej Sobczak
2019-06-03  8:13     ` Dmitry A. Kazakov
2019-06-03 19:51       ` Keith Thompson
2019-06-03 20:18         ` Dmitry A. Kazakov
2019-06-04  8:24       ` Maciej Sobczak
2019-06-04  9:33         ` Dmitry A. Kazakov
2019-06-05  9:04           ` Maciej Sobczak
2019-06-05 12:48             ` Dmitry A. Kazakov
2019-06-05 17:12               ` G. B.
2019-06-05 18:50                 ` Optikos
2019-06-05 22:57                   ` Randy Brukardt
2019-06-04 22:28         ` Randy Brukardt
2019-06-05  8:28           ` Maciej Sobczak
2019-06-05  9:20             ` J-P. Rosen
2019-06-05  9:28               ` Paul Rubin
2019-06-05 10:11                 ` Niklas Holsti
2019-06-05 12:58                   ` Maciej Sobczak
2019-06-05 14:28                     ` Niklas Holsti [this message]
2019-06-06  7:34                       ` Maciej Sobczak
2019-06-06 19:51                         ` Keith Thompson
2019-06-06 20:27                           ` J-P. Rosen
2019-06-06 21:12                         ` Randy Brukardt
2019-06-06 21:17                         ` Randy Brukardt
2019-06-06 22:08                           ` Dennis Lee Bieber
2019-06-07  7:59                           ` Maciej Sobczak
2019-06-07 10:42                             ` alby.gamper
2019-06-07 16:59                               ` Dennis Lee Bieber
2019-06-07 14:10                             ` Brad Moore
2019-06-07 23:37                               ` Paul Rubin
2019-06-08  1:16                                 ` Brad Moore
2019-06-08  7:34                                   ` Simon Wright
2019-06-08 17:44                                 ` G.B.
2019-06-08 21:41                                 ` Keith Thompson
2019-06-09  0:40                                   ` Paul Rubin
2019-06-09 18:56                                     ` Keith Thompson
2019-06-09 20:35                                       ` John Perry
2019-06-09 21:15                                         ` Niklas Holsti
2019-06-09 22:37                                           ` John Perry
2019-06-10  9:01                                             ` Simon Wright
2019-06-10 13:15                                               ` Simon Wright
2019-06-10  9:22                                             ` Niklas Holsti
2019-06-09 21:37                                         ` Simon Wright
2019-06-09 22:40                                           ` John Perry
2019-06-10  9:07                                             ` Simon Wright
2019-06-09 21:46                                         ` Niklas Holsti
2019-06-10 17:11                                         ` Dennis Lee Bieber
2019-06-08  4:57                             ` Randy Brukardt
2019-06-08 23:57                               ` Optikos
2019-06-09  0:43                                 ` Paul Rubin
2019-06-10  8:17                               ` Maciej Sobczak
2019-06-10 19:10                                 ` G.B.
2019-06-10 22:07                                 ` Randy Brukardt
2019-06-11  0:32                                   ` Optikos
2019-06-11 15:39                                     ` Brad Moore
2019-06-11 16:14                                       ` John Perry
2019-06-11 16:46                                         ` Shark8
2019-06-11 19:29                                           ` John Perry
2019-06-14  6:12                                             ` Brad Moore
2019-06-14 21:51                                               ` John Perry
2019-06-14 16:29                                             ` djakoogler
2019-06-11 18:19                                         ` joakimds
2019-06-11 15:49                                   ` Jeffrey R. Carter
2019-06-07  7:36                       ` Niklas Holsti
2019-06-05 22:41                     ` Randy Brukardt
2019-06-06  3:34             ` Keith Thompson
2019-06-06  7:29               ` Maciej Sobczak
2019-06-06 15:30                 ` John Perry
2019-06-06 15:41                 ` Brad Moore
2019-06-06 19:42                 ` Keith Thompson
2019-06-06 16:37               ` Dennis Lee Bieber
2019-06-02  9:59 ` joakimds
2019-06-02 20:14 ` G.B.
2019-06-03 13:37 ` John Perry
2019-06-03 14:50   ` Niklas Holsti
2019-06-03 19:23     ` John Perry
2019-06-03 21:04       ` Niklas Holsti
2019-06-03 18:51   ` Lucretia
2019-06-03 19:32     ` John Perry
2019-06-03 17:00 ` Jeffrey R. Carter
2019-06-03 18:59   ` Lucretia
2019-06-03 19:29   ` John Perry
2019-06-03 20:00     ` Jeffrey R. Carter
replies disabled

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