comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: on the need to duplicate code for procedure signature in both body and interface files
Date: Mon, 9 Jul 2012 08:11:24 -0700 (PDT)
Date: 2012-07-09T08:11:24-07:00	[thread overview]
Message-ID: <97181340-e20e-4127-a1e8-f8c16088f4a5@googlegroups.com> (raw)
In-Reply-To: <jtafi8$pvg$1@speranza.aioe.org>

On Saturday, July 7, 2012 4:08:53 PM UTC-7, 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).
> 
> 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).
> 
> 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?

Overloading makes this an issue.  But I think that having procedure and function declarations duplicated in the body is a big help for readability.  If I'm looking at a procedure in the body, I can see what the declaration is.  In fact, one of the things I *don't* like about Ada is that when you write a generic procedure or function, you can't duplicate the generic part in the body.  I really like having that information available when I read the body, so that when I see a generic formal I know what it is without having to flip back to the specification.  Usually I just copy the generic formal part into the body and comment it out.

Anyway, I wrote a program a long time ago that takes text input with procedure and function declarations and provides empty bodies for them.  So I just copy and paste the spec part into the body and run it through the program.

                          -- Adam



  parent reply	other threads:[~2012-07-09 15:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-07 23:08 on the need to duplicate code for procedure signature in both body and interface files Nasser M. Abbasi
2012-07-08  4:01 ` Shark8
2012-07-08 17:13   ` Brian Drummond
2012-07-08  4:21 ` Niklas Holsti
2012-07-08  6:09 ` Jeffrey Carter
2012-07-13 15:51   ` Robert A Duff
2012-07-08  7:38 ` Stephen Leake
2012-07-08 10:52 ` Manuel Collado
2012-07-09  1:48 ` Britt
2012-07-09 10:49   ` AdaMagica
2012-07-09 15:11 ` Adam Beneschan [this message]
2012-07-13 17:12 ` björn lundin
replies disabled

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