comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: MI ammunition : linked lists
Date: Sat, 08 Nov 2003 11:27:28 +0100
Date: 2003-11-08T11:27:28+01:00	[thread overview]
Message-ID: <boig4f$1elvjg$1@ID-77047.news.uni-berlin.de> (raw)
In-Reply-To: wkvqb.67$y95.60@nwrdny01.gnilink.net

Frank J. Lhota wrote:

> Even where MI is available, I would not implement linked lists this way.
> Do we really want the type of a node vary depending on its position on the
> list? Do we want to convert the type of end nodes when a new node is
> added, or when an end node is removed?

YES!

There are two opposite variants of list design. One of them, most people
seems keeping in mind, is to have a list element and then to add object
specific things:

type List_Element is ...;
type My_Object_In_A_List is new List_Element with private;

This sort of design faces many problems. What if My_Object_... has to be in
many lists simultaneously? No way. Then to the problem you and others
mention. It exists because an inheritance by extension from List_Element
fixes the representation of My_Object_... This is inherently bad. You can
argue that to have different representations for root, middle and end nodes
is wrong, and flatten them to be of same type, as all here propose. Let
accept it for a minute. How about another challenge. What if we have
different list representation? What if there is Double_Linked_List_Element,
Array_List_Element, Persistent_List_Element, Remote_List_Element and
My_Object could be put in either of them? By inheriting form a specific
element type, we produce different object types, depending on the element
representation. And if you move an object from one list to another it still
has to mutate! - This has nothing to do with MI! -

An alternative design could be objects independent from list elements. A
"list element" could act as a smart pointer to My_Object_...'Class. If you
do this, then mutating a list element would cause no problem, because it
would not affect the object itself. It is just like to get another pointer
to it. Because List_Elements are small (up to two fields), it would be very
efficient [assuming that List_Elements could be by-value]. In this case MI
would offer a type-safe representation for list elements. It is a clear
advantage. The problem with this approach is that:

1. user-defined access types are presently not supported, which makes
implementation of smart pointers (by controlled types) very difficult and
inefficient;

2. access types and user-defined by-value types cannot be tagged;

3. initialization / finalization is allowed for controlled types only;

4. there is no MI, after all.

I think that to fix 1-3 [and arguably 4] would drastically improve Ada, at
least much more than introdicing += or saturated arithmetics.

-- 
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-11-08 10:27 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-06 16:32 MI ammunition : linked lists amado.alves
2003-11-06 16:46 ` Stephen Leake
2003-11-06 17:15 ` Frank J. Lhota
2003-11-08 10:27   ` Dmitry A. Kazakov [this message]
2003-11-06 17:16 ` Jean-Pierre Rosen
2003-11-06 18:15   ` Wes Groleau
2003-11-06 21:03   ` Simon Wright
2003-11-07 10:39     ` Dmitry A. Kazakov
2003-11-07 10:29 ` Dmitry A. Kazakov
2003-11-10 14:51 ` Lutz Donnerhacke
2003-11-10 17:52   ` Marius Amado Alves
2003-11-11  9:32     ` Lutz Donnerhacke
2003-11-11 12:24       ` Marius Amado Alves
2003-11-11 12:58         ` Lutz Donnerhacke
2003-11-11 16:09           ` Robert I. Eachus
2003-11-11 17:11             ` Marius Amado Alves
2003-11-12  9:21               ` Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2003-11-06 17:26 amado.alves
2003-11-06 17:33 amado.alves
2003-11-06 19:01 amado.alves
2003-11-11 18:38 ` Georg Bauhaus
2003-11-11 21:27   ` Marius Amado Alves
2003-11-12  0:23     ` Georg Bauhaus
2003-11-12 11:29 amado.alves
replies disabled

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