From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Idiom for a class and an object in Ada
Date: Wed, 20 Oct 2004 10:39:42 +0200
Date: 2004-10-20T10:39:42+02:00 [thread overview]
Message-ID: <g5xenepow3t3$.1obbbyroo690h.dlg@40tude.net> (raw)
In-Reply-To: uoeixvols.fsf@earthlink.net
On Wed, 20 Oct 2004 07:24:31 GMT, Matthew Heaney wrote:
> For reasons I can't fathom, many Ada95 developers still have a very
> Ada83 mindset.
Probably because Ada 83 was good! (:-))
> package P is
>
> type T (<>) is limited private;
>
> procedure Op (O : in T);
>
> function Object1 return T;
> function Object2 return T;
>
> private
>
> type T is limited record ...;
>
> end P;
This approach is difficult to follow with read-write objects, because it
then forces to use indirection.
> This is exactly how Text_IO works. The objects returned by functions
> Standard_Input, Standard_Output, etc, correspond to the functions
> Object1 and Object2 above.
Yes and the price is heavy:
procedure Put(File : in File_Type; Item : in Character);
writes into *in* File! Even if File_Type is considered to be an "iterator",
"access window" etc, rather than the file, then definitely Put and Get
should *change* it. So what is File_Type? It is a language construct to
provide a work-around for the pattern above, i.e. a hack. A bit watery for
an IDIOM.
> This is the canonical Ada95 idiom for controlling instance creation, and
> for declaring well-known objects.
Yes, but it lacks an ability to create non-constant objects on the stack,
and it requires an extra indirection level. There should be a way for
forward object declarations.
type X (<>) is limited private;
A : X renames private; -- Forward rename
or so
A : X := private; -- Forward initialization
or
A : private X;
private
type X is record
Field : Integer;
end record;
A : X := (Field => 123);
Then of course there should be a way for in-place modification of the
result for by-reference types and copy-out/copy-in for all others.
Anonymous access results are good, but I'd prefer a more elaborated
solution without access types.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2004-10-20 8:39 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-18 11:47 Idiom for a class and an object in Ada Marin David Condic
2004-10-18 12:14 ` Martin Krischik
2004-10-18 19:40 ` Matthew Heaney
2004-10-19 12:59 ` Marin David Condic
2004-10-19 14:46 ` Martin Dowie
2004-10-19 15:55 ` Matthew Heaney
2004-10-19 18:31 ` Martin Dowie
2004-10-19 15:52 ` Matthew Heaney
2004-10-18 12:26 ` Marius Amado Alves
2004-10-19 2:09 ` Jeffrey Carter
2004-10-19 3:28 ` Matthew Heaney
2004-10-19 12:53 ` Marin David Condic
2004-10-19 14:44 ` Matthew Heaney
2004-10-19 15:01 ` Dmitry A. Kazakov
2004-10-19 15:40 ` Matthew Heaney
2004-10-20 7:58 ` Dmitry A. Kazakov
2004-10-20 12:31 ` Marin David Condic
2004-10-20 13:53 ` Dmitry A. Kazakov
2004-10-20 15:23 ` Matthew Heaney
2004-10-21 12:24 ` Marin David Condic
2004-10-21 17:15 ` Matthew Heaney
2004-10-20 5:39 ` Simon Wright
2004-10-20 7:24 ` Matthew Heaney
2004-10-20 8:39 ` Dmitry A. Kazakov [this message]
2004-10-21 1:36 ` Jeffrey Carter
2004-10-21 1:46 ` Matthew Heaney
2004-10-21 7:51 ` Dmitry A. Kazakov
2004-10-21 12:45 ` Matthew Heaney
2004-10-21 14:11 ` Dmitry A. Kazakov
2004-10-22 1:04 ` Jeffrey Carter
2004-10-22 1:36 ` Matthew Heaney
2004-10-21 19:31 ` Kevin Cline
2004-10-21 22:02 ` Matthew Heaney
2004-10-22 0:10 ` Matthew Heaney
2004-10-21 8:25 ` Martin Dowie
2004-10-20 17:04 ` Matthew Heaney
2004-10-20 19:37 ` Simon Wright
2004-10-20 20:04 ` Matthew Heaney
2004-10-22 5:37 ` Simon Wright
2004-10-20 1:10 ` Jeffrey Carter
2004-10-20 7:04 ` Matthew Heaney
2004-10-20 12:42 ` Marin David Condic
2004-10-20 12:55 ` Matthew Heaney
2004-10-20 15:27 ` Matthew Heaney
2004-10-21 1:36 ` Matthew Heaney
2004-10-19 12:38 ` Marin David Condic
2004-10-18 16:59 ` Matthew Heaney
2004-10-18 18:02 ` Martin Dowie
2004-10-19 13:06 ` Marin David Condic
2004-10-19 14:51 ` Martin Dowie
2004-10-20 16:20 ` Michael Paus
2004-10-20 17:15 ` Matthew Heaney
2004-10-20 17:55 ` Michael Paus
2004-10-21 12:33 ` Marin David Condic
-- strict thread matches above, loose matches on Subject: below --
2004-10-21 13:59 Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox