From: Jared <nowhere@nowhere.nowhere>
Subject: Re: advice on package design
Date: Fri, 18 Mar 2005 03:06:47 GMT
Date: 2005-03-18T03:06:47+00:00 [thread overview]
Message-ID: <bBr_d.72$5d2.1813@news.uswest.net> (raw)
In-Reply-To: wccsm2u6k1t.fsf@shell01.TheWorld.com
Robert A Duff <bobduff@shell01.TheWorld.com> wrote in
news:wccsm2u6k1t.fsf@shell01.TheWorld.com:
> But that seems less readable (to me) than just writing
> "Initialize_Database;" where I want it to happen.
> So a rule (requiring "declare") that is intended to increase
> readability actually decreases it.
>
> And if you want a statement in a package *spec* (say, to initialize
> something), it's far worse. There's no direct workaround; you have to
> totally rearrange the structure of your design in order to get around
> a silly syntax rule.
Is this terribly common, though? I'm just a hobbyist, so when I run
across something like that, I just assume I have a bad design.
> It seems to me that:
>
> Mumble: T := Blah(...);
>
> should be precisely equivalent to:
>
> Mumble: T;
> Mumble := Blah(...);
>
> which should be precisely equivalent to:
>
> Mumble: T;
> Blah(Mumble);
>
> (where in the last example we replace function Blah with a procedure
> with an 'out' parameter). The programmer should be able to switch
> from one of these forms to another, without changing the semantics of
> the program. But the syntax rules require stirring the code around
> when you make these changes.
>
> (Another reason Ada does not have the above desirable property is that
> function results of subtype String behave differently from 'out'
> parameters of subtype String. I don't like that.)
This is the case for all unconstrained array types. In order to use
unconstrained variables, we three distasteful choices. Invoke the
entire object mechanism for a single controlled type, fiddle with
access types and hope not to drop any references, or create code that
looks like:
> function F(...) return String is
> A: String := ...;
> begin
> Do_Something(A);
> declare
> B: constant String := G(A);
> begin
> ... and so on ..................................
> declare
> Z:
> String ...
> begin
> return
> Z;
>
> Yuck.
There's always Ada.Strings.Unbounded.Unbounded_String, but that's
only good for character arrays.
Incidentally, I'm just a hobbyist, so I don't know about this; how
common is it in production code to declare a controlled type just
to guarantee uniqueness of reference? Of those, how many are used
for arrays?
next prev parent reply other threads:[~2005-03-18 3:06 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-07 16:23 advice on package design spambox
2005-03-07 21:08 ` Dmitry A. Kazakov
2005-03-08 12:48 ` spambox
2005-03-08 17:18 ` Dmitry A. Kazakov
2005-03-12 19:57 ` Robert A Duff
2005-03-12 20:45 ` Dmitry A. Kazakov
2005-03-12 21:59 ` Robert A Duff
2005-03-13 9:23 ` Dmitry A. Kazakov
2005-03-16 20:41 ` Robert A Duff
2005-03-17 10:22 ` Dmitry A. Kazakov
2005-03-17 14:04 ` Robert A Duff
2005-03-17 15:59 ` Dmitry A. Kazakov
2005-03-17 19:10 ` Robert A Duff
2005-03-17 19:47 ` Martin Dowie
2005-03-17 20:55 ` Robert A Duff
2005-03-17 21:14 ` Marius Amado Alves
2005-03-18 9:31 ` Martin Dowie
2005-03-18 9:38 ` Martin Dowie
2005-03-21 16:19 ` Robert A Duff
2005-03-17 20:48 ` Dmitry A. Kazakov
2005-03-17 21:26 ` Robert A Duff
2005-03-18 3:06 ` Jared [this message]
2005-03-18 10:00 ` Dmitry A. Kazakov
2005-03-21 16:17 ` Robert A Duff
2005-03-21 18:16 ` Dmitry A. Kazakov
2005-03-21 20:35 ` Robert A Duff
2005-03-22 10:55 ` Dmitry A. Kazakov
2005-03-17 23:23 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox