comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Multiple procedures in the same adb file?
Date: Sun, 11 Jan 2015 19:53:17 -0500
Date: 2015-01-11T19:53:17-05:00	[thread overview]
Message-ID: <wcc1tn0x1j6.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: chg8qqFe9apU1@mid.individual.net

Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

> On 15-01-11 21:51 , Robert A Duff wrote:
>> It is unwise to have procedures outside of packages
>
> Why "unwise"?

Because sometimes you need to add new stuff (another related procedure,
for example), and then there's no good place to put it.  If the existing
procedure is in a package, then that's where you put it.

This happened to me:  Existing code:

    function Some_Root_Package.Some_Function(...) return String;

Now I happen to know that it always returns String(1..20).
And returning known-length strings is more efficient,
and this one is a bottleneck, so it's worth changing to
something like:

    subtype String_20 is String(1..20);
    function Some_Function(...) return String_20;

But that doesn't work without adding a new package, which breaks
compatibility.  And this was a widely-used library, so I couldn't do
that.  And String_20 really doesn't belong in Some_Root_Package,
nor anywhere else than the package that Some_Function is (directly) in
(which didn't exist!).

If the original programmer had put Some_Function in a child package
Some_Root_Package.Some_Package in the first place, then I wouldn't have
had these problems.

I admit: these concerns are only significant for widely-used libraries.
If I had been working on a program instead of a library, I would have
just moved Some_Function into a package, and modified all the call
sites.  But it's probably a good idea to get in the habit of using
"library-programming" style even when doing "program-programming",
if it's not too much trouble.

Besides, it complicates the language quite a bit to have misc stuff
allowed as compilation units (e.g. task body subunits).  I would prefer
that the only unit of separate compilation be the package (and maybe
generic package).

>... I agree it is unusual, but I find it is sometimes useful,
> in particular to have subprograms which are children of packages but are
> their own compilation units. In a layered architecture, such subprograms
> are sort of in a layer between the higher layer that contains the
> declaration of the parent package, and the lower layer that contains the
> body of that package.

Sure, but you can do that with another package just as well as
with a procedure.

> In language-lawyer terms, perhaps such subprograms are not really
> "outside of packages", because child units are in some sense "inside"
> their parents, but the child subprograms are not "inside" any package in
> terms of source-code files.

Yes, you're right.  In fact, everything is logically nested within
package Standard, so everything is in a package.  But I meant that
everything should be physically/textually nested within a package,
and packages (and generic packages) should be the only
separately-compiled things.  And main procedures should be
(textually) in packages, instead of as standalone procedures
(and that part is not Ada -- just my preference for how it ought
to be!).

- Bob


  reply	other threads:[~2015-01-12  0:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-11 18:37 Multiple procedures in the same adb file? John Smith
2015-01-11 19:05 ` John Smith
2015-01-11 19:51 ` Robert A Duff
2015-01-11 20:38   ` John Smith
2015-01-11 21:02     ` Robert A Duff
2015-01-11 21:51       ` John Smith
2015-01-12  0:53         ` Robert A Duff
2015-01-12  0:55         ` Robert A Duff
2015-01-13  0:11       ` Randy Brukardt
2015-01-11 21:38   ` Niklas Holsti
2015-01-12  0:53     ` Robert A Duff [this message]
2015-01-12  9:01       ` J-P. Rosen
2015-01-12 14:57         ` Robert A Duff
2015-01-13  0:09           ` Randy Brukardt
2015-01-12  0:55     ` Robert A Duff
2015-01-11 20:04 ` Jeffrey 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