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=ham 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.196.232 with SMTP id ip8mr1804729pbc.6.1342194667759; Fri, 13 Jul 2012 08:51:07 -0700 (PDT) Path: l9ni11632pbj.0!nntp.google.com!news1.google.com!news.glorb.com!solaris.cc.vt.edu!news.vt.edu!newsfeed-00.mathworks.com!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: on the need to duplicate code for procedure signature in both body and interface files Date: Fri, 13 Jul 2012 11:51:07 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 X-Trace: pcls6.std.com 1342194667 2727 192.74.137.71 (13 Jul 2012 15:51:07 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 13 Jul 2012 15:51:07 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:v/6n3b3mihzWEoTDQC8DFkpOb6A= Content-Type: text/plain; charset=us-ascii Date: 2012-07-13T11:51:07-04:00 List-Id: Jeffrey Carter writes: > Consider the following: > > package P is > function F (I : Integer) return Integer; > > type Integer_List is array (Integer range <>) of Integer; > > function F return Integer_List; > end P; > > How are you going to write the body of P so the compiler knows which > body implements which function F without repeating the parameter list > and return type profile, which is what distinguishes these 2 overloaded > functions? Well, that wouldn't be too hard of a problem to solve. I think the real reason for duplicating the information is readability. For example, you could require that two functions in the same scope have different names. You could still use overloading via renames: function F_Integer (I : Integer) return Integer; function F (I : Integer) return Integer renames F_Integer; ... function F_Integer_List return Integer_List; function F return Integer_List renames F_Integer_List; I tend to use this style anyway, because then the debugger tells me which function I'm in. Also, if this were the rule, the compiler could more easily give good error messages. Consider: procedure P (X : Integer); ... procedure P (X : Long_Integer) is -- Wrong. begin ... end P; where the mistake is that I changed Integer to Long_Integer in one place but forgot the other. A typical compiler will complain incorrectly that P doesn't have a body. One could facilitate the above renamings with a shorthand: function F_Integer, F (I : Integer) return Integer; function F_Integer_List, F return Integer_List; - Bob