From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.fn3LatRFkm9/xzEj7F2/NQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Why .ads as well as .adb? Date: Mon, 3 Jun 2019 10:13:40 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <28facad3-c55f-4ef2-8ef8-004925b7d1f1@googlegroups.com> NNTP-Posting-Host: fn3LatRFkm9/xzEj7F2/NQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:56439 Date: 2019-06-03T10:13:40+02:00 List-Id: On 2019-06-03 09:35, Maciej Sobczak wrote: >> That is not possible. You cannot generate specification from >> implementation and conversely. > > Yes, you can. You can generate specs from implementations. No. Specification describes a class of implementations. You cannot deduce class from its single member. >> In both cases there is additional >> information missing. > > Why is it missing? What if we put all information in implementation? Then there is nothing missing and we can generate specs from it. It is not possible as well. The language of specifications (to be useful) must have statements non-existing in the language of implementations. > Your argument is not convincing. It can be expanded into: > - I have separate spec and implementation files, so I can write my contracts in the spec and then I don't have to repeat them in bodies. No. The right statement would be: I cannot write contract in the body. Contract and an implementation of are in two different languages with two different domains. They cannot be spelt in a single language. BTW, this is why Ada's dynamic constraints is not a contract. They are implementations of a contract to raise an exception when some Boolean expression yields False. > - Well, I did not write my contracts in bodies, so they are not there and therefore something is missing, so I cannot generate specs from it. > > ? Right. >> Compare also Ada's declarative regions with C++'s >> ad-hoc declarations: >> >> declare >> X : Integer; >> begin >> ... -- Some code >> X := 1; >> end; >> >> { >> ... // Some code >> int X; >> X = 1; >> } > > When I compare these two examples, I see that C++ is more readable, because it allows me to minimize the scope of names that are not needed until in later parts of code, without messing with useless constructs like this: > > begin > -- some code > declare > X : Integer; > begin > X := 1; > end; > end; > > There is *nothing* gained in this construct and it is equivalent to the C++ example above. The gain is definition of the scope. C++ equivalent, which I would force in each C++ programming guideline, would be: { ... // Some code { int X; X = 1; .. } .. // Some code } >> BTW when writing OS-dependent code it is very convenient >> to have one *.ads file and several *.adb files. > > I do that in C++, too. > >> And, in the >> tool-chain you just switch to another *.adb when changing the target. > > And, in the tool-chain you just switch to another *.cpp when changing the target. > >> Compare that with C++'s #ifdef infestations. > > What? Why would anybody do that, apart from those few cases where this approach genuinely improves the readability of the code and where having separate compilation units would actually be more difficult to maintain? Yes, why? There must be something contagious in #ifdef's, or maybe, it just what C/C++ inherently is? My guess and my point is that this is what you inevitably get without proper contracts (=> separated specifications). > In other words: for multiplatform development, C++ gives me 2 solutions and I can choose the one which is more beneficial in the given context. Ada offers only one. How is this better? Choice is a burden. Would you can have a water tap with a third choice: hot, cold, sulfuric acid? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de