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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,35782846f963b1e5 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.220.230 with SMTP id pz6mr17761503pbc.3.1341721269584; Sat, 07 Jul 2012 21:21:09 -0700 (PDT) Path: l9ni11132pbj.0!nntp.google.com!news1.google.com!goblin2!goblin.stu.neva.ru!news.internetdienste.de!news.tu-darmstadt.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: on the need to duplicate code for procedure signature in both body and interface files Date: Sun, 08 Jul 2012 07:21:07 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 X-Trace: individual.net LnUXQcRM6JwxsA1cGIh7HQWJtj3CGmXmWq2EiuYYC/5KnLSHZJGbvVjaO+YYMfJpt3 Cancel-Lock: sha1:fpFGMtAMVtbDLXIN0PvoiHevZ/8= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-07-08T07:21:07+03:00 List-Id: On 12-07-08 02:08 , Nasser M. Abbasi wrote: > Basic question from an Ada newbie. > > One thing that always bothered me in Ada is the need > to physically duplicate the code that represents the API > of the package procedures and functions in both the interface > and the body files (.ads and .adb). That is a language property that applies to the source-code files. If you use some kind of CASE tool or IDE, it can hide the duplication by synchronizing the text in the spec and body. For exampe, I think GPS/gnat has the ability to generate a dummy body (.adb) from a given spec (.ads) (but not to maintain the connection if the spec changes). Possibly the Ada mode of emacs can do that too. Several years ago I used an Ada CASE tool called HoodNICE, based on the HOOD design method. In this tool, one wrote the Ada code once, and the tool generated the spec and body files. However, the design method was based on packages as "objects", and dependencies were basically managed on the object level *without* separation of spec and body, so one had to take some special ugly action to show that "object" A depended on "object" B only because the *body* of package A needed a "with" clause for package B, while the *spec* of A did *not* need such a clause. (To be fair, the HOOD design method tried to enforce a strict layering with no mutual dependencies through bodies. But this is a very limiting rule, and we violated it in most projects.) > I do not like duplicating code at all. Even if it is only > for the signature of the API, and even though the Ada > compiler will catch any difference (assuming one changes > the .ads and forget to update the .adb for example). The important reason for "duplicating" the code (signature) is that one needs some way to show which body belongs to which declaration when the subprogram names are overloaded (same name, different signature). Duplicating the text that defines the signature is IMO the simplest and most readable way to show this connection, when the declaration and body are in different files. in a sense, there is no more "duplication" here than when we "duplicate" the subprogram name and parameter names in the calls to the subprograms. Keeping the spec and body in the same file would mess up "make" logic based on file time-stamps. Changing the body code should normally not force recompilation of clients of the spec. > Was there no other alternatives to avoid this situation > when Ada was originally designed in order to keep the same > good concept of separating the interface from the body, but > somehow at the same time, eliminate the need to duplicate by > hand the API definition code in 2 separate places? Given the copy/paste abilities of good text editors, I don't see this as a problem at all. In my spec files, most of the text is comments (ooh how I hate that misleading word!) that describe what the stuff means and how it works; the actual Ada code is a small fraction, and of this code, only the subprogram signatures are duplicated in the body. (Of course there are comments in the body, too, but on different issues.) No doubt one could devise an Ada compilation system, similar to the HoodNICE method, in which only body files exist, with some mark-up to show which parts of these files are "public" (belong in the spec). A dedicated tool could then generate the spec files, and also avoid updating the time-stamp of the spec when the contents of the file do not change. But as I said, I don't feel that this (apparent) duplication is a problem. > I am using GNAT. I Assume this is the same in other Ada > implementations. I wonder how the Rational Ada enviroment worked, on this issue. I'm sure someone on this group remembers. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .