comp.lang.ada
 help / color / mirror / Atom feed
From: Richard Riehle <richard@adaworks.com>
Subject: ;Re: Style: always declare subrountines?
Date: Sun, 17 Nov 2002 17:52:13 -0800
Date: 2002-11-18T01:44:49+00:00	[thread overview]
Message-ID: <3DD847CD.A3D78EE9@adaworks.com> (raw)
In-Reply-To: 3dccc023$0$304$bed64819@news.gradwell.net

Victor Porton wrote:

> How do you consider this:
>
> If one would always declare every subrountine of a package body in the
> specification (in the public or in the private part) this excludes the
> possibility that one may mistakedly create an internal subrountine with
> the same specification as a not yet implemented public procedure and
> forget to implement this public procedure and so get wrong program
> behavior.

My own own preference for internal subprograms that have no
entry in the specification  to promote them to a private package
specification.   This promotes reuse, enhances maintenance, and
allows extensibility.   For example, consider:

            package P1 is
                procedure Q ...
                procedure R ...
                function    S   return ...
           end P1;

           package body P1 is
               function T ... return  ... is ... end T;
               function Z ... return  ... is ... end Z;
               function W ... return  ... is ... end W;
               procedure Q ... is ...   end Q;
               procedure R ... is ...   end R;
               function    S ... return ... is ...   end S;
          end P1;

The three functions, T, Z, and W can be promoted to a private package
specification,

            private package P1.Utilities is
               function T ... return  ... ;
               function Z ... return  ... ;
               function W ... return  ... ;
          end P1.Utilities;

Now package body for P1 is as before but,

          with P1.Utilities;
          package body P1 is  ... end P1;

For some reason, we continue to see some designers
miss out on the potential for decomposing their systems
so they can make the best use of private child library units.
The fundamental design policy can be stated as: only include
in package body the code corresponding directly to entries
in the specification.  Everything else should have its
own specification and implementation.

Richard Riehle





  parent reply	other threads:[~2002-11-18  1:52 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-09  6:39 Style: always declare subrountines? Victor Porton
2002-11-09 11:09 ` sk
2002-11-09 12:34 ` Victor Porton
2002-11-09 14:34   ` Jim Rogers
2002-11-09 14:53   ` sk
2002-11-09 15:36 ` Robert A Duff
2002-11-09 16:16 ` Frank J. Lhota
2002-11-09 16:28 ` chris.danx
2002-11-09 18:36 ` Simon Wright
2002-11-12 17:31 ` Stephen Leake
2002-11-18  1:52 ` Richard Riehle [this message]
2002-11-28 10:32   ` John English
2002-11-28 12:52     ` Lutz Donnerhacke
2002-12-03 11:15       ` John English
2002-12-03 12:22         ` Lutz Donnerhacke
2002-12-03 13:11           ` John English
2002-12-03 14:31             ` Robert A Duff
2002-12-03 14:41               ` Lutz Donnerhacke
2002-11-28 17:49     ` Vincent Marciante
2002-12-03 11:09       ` John English
2002-11-28 18:45     ` "private with" proposal Vincent Marciante
2002-11-28 20:12       ` David C. Hoos, Sr.
2002-11-29  4:28         ` Vincent Marciante
2002-12-01  1:00           ` Dale Stanbrough
2002-12-02 18:20       ` Stephen Leake
2002-12-03  5:37         ` Vincent Marciante
2002-12-03 19:24           ` Randy Brukardt
2002-12-04  3:52             ` Vincent Marciante
replies disabled

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