comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: List Container Straw Man
Date: 07 Nov 2001 14:49:49 -0500
Date: 2001-11-07T19:50:24+00:00	[thread overview]
Message-ID: <u1yjacqea.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 9s9s8p$11vt7l$1@ID-25716.news.dfncis.de

"Nick Roberts" <nickroberts@adaos.worldonline.co.uk> writes:

> Please make the type List derived from an abstract 'iterator' type. List
> would then inherit the iteration operations of this type. An alternative is
> for List to provide a function that generates or gives access to an object
> derived from this iterator type.
> 
> For example:
> 
> 
> generic
>    type Element_Type is private;
> 
> package Containers is
> 
>    ...
> 
>    type Terminating_Producer is abstract tagged limited private;
> 
>    procedure Read (Producer: in out Terminating_Producer; Item: out
> Element_Type) is abstract;
> 
>    function End_of_Data (Producer: in Terminating_Producer) return Boolean
> is abstract;
> 
>    ...
> 
>    type Sequence_Reproducer is abstract new Terminating_Producer with
> private;
> 
>    procedure Restart (Reproducer: in out Sequence_Reproducer) is abstract;
> 
>    type Sequence_Recorder is abstract new Sequence_Reproducer with private;
> 
>    procedure Rewrite (Reproducer: in out Sequence_Reproducer) is abstract;
> 
>    procedure Write (Recorder: in out Sequence_Recorder; Item: in
> Element_Type) is abstract;
> 
>    function Count (Recorder: in Sequence_Recorder) return Natural is
> abstract;
> 
>    function Is_Recording (Recorder: in Sequence_Recorder) return Boolean is
> abstract;
> 
>    ...
> 
> end Containers;
> 
> 
> The Restart procedure tells a sequence reproducer to start producing its
> data over again. The Rewrite procedure tells a sequence recorder to start
> recording data (at which point Write can be used and Read cannot;
> Is_Recording returns True). Restart than tells it to start reading again (at
> which point Write cannot be used; Is_Recording returns False). Count returns
> the number of items currently recorded.

Well, I find this very confusing; there is not enough documentation
for me.

First, you switched from "Sequence_Reproducer" to "Sequence_Recorder".
Or maybe you left out a type?

Why are there three (or four) independent types? How do I write to a
producer object in the first place, so there is something to read?
Conversely, how do I read from a recorder?

> package Containers.Lists.Unbounded is
> 
>    type Linked_List is new Sequence_Recorder with private;
> 
>    -- Representing a singly-linked (forward) list type, with typical
> operations.
> 
>    function "&" (Left, Right: in Linked_List) return Linked_List is
> abstract;

Why is this abstract? How many implementations of a singly-linked list
are there? Hmm, I guess we have discussed several here, including
various options for making Iterators safe. So maybe this makes sense.

>    ...
> <snip> 
> end Containers.Utility.Lists;
> 
> 
> In this way, a piece of software which only needs to iterate over a
> container can be passed any of the list types, or other container types.

This is true. But it leads to the "complex instantiation" problem that
is one requirement for the list package under discussion.

It also introduces tagged types, which some users might want to avoid
(they can have run-time overhead, or be hard to test).

Personally, I've never run across a situation where this abstract
container design really made sense; it was always more important to
optimize the implentation for real-time issues (I'm a rocket
scientist, after all :).

In a truly complete library, I think both options should be available;
abstract containers and concrete, simple lists. Perhaps the "Dennison
List" package could be used to implement the doubly-linked list
variant of the abstract container package; would that work for you?

> Please don't get this elementary aspect of the design wrong!

"Wrong" is too strong. Just because some people give different design
options different importance does not make them wrong!

-- 
-- Stephe



  reply	other threads:[~2001-11-07 19:49 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-06 16:45 List Container Straw Man Nick Roberts
2001-11-06 17:29 ` Stephen Leake
2001-11-06 18:25   ` Marin David Condic
2001-11-06 23:02     ` Nick Roberts
2001-11-07 19:49       ` Stephen Leake [this message]
2001-11-07 20:30         ` Marin David Condic
2001-11-07 23:58           ` Nick Roberts
2001-11-08  4:34             ` Jeffrey Carter
2001-11-08 10:45             ` Ehud Lamm
2001-11-08 19:09               ` Nick Roberts
2001-11-09 16:32                 ` Ted Dennison
2001-11-10  2:20                   ` Nick Roberts
2001-11-10 19:50                     ` Ehud Lamm
2001-11-11  3:48                       ` Nick Roberts
2001-11-08 10:41           ` Ehud Lamm
2001-11-08 19:20             ` Marin David Condic
2001-11-08 20:35               ` Ehud Lamm
2001-11-09 16:39             ` Ted Dennison
2001-11-08  0:06         ` Nick Roberts
2001-11-09 16:16           ` Stephen Leake
2001-11-09 16:24             ` Ehud Lamm
2001-11-09 16:52               ` Brian Rogoff
2001-11-09 18:04             ` Darren New
2001-11-09 20:05               ` Stephen Leake
2001-11-10  3:24             ` Nick Roberts
2001-11-06 23:52   ` Nick Roberts
2001-11-07  4:44     ` A question and a request Eric Merritt
2001-11-07 11:00       ` Preben Randhol
2001-11-07 12:54         ` David C. Hoos, Sr.
2001-11-08  2:35           ` dale
2001-11-07 13:24         ` Eric Merritt
2001-11-07 13:58       ` James Rogers
2001-11-07 16:32       ` Jeffrey Carter
2001-11-09 23:32       ` Matthew Heaney
replies disabled

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