comp.lang.ada
 help / color / mirror / Atom feed
* Clueless :)
@ 2003-03-18 12:55 Karel Miklav
  2003-03-18 16:37 ` Martin Krischik
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Karel Miklav @ 2003-03-18 12:55 UTC (permalink / raw)


Learning Ada I'm playing with container libraries and there are some 
things puzzling me. If I initialize a generic container with an abstract 
data type, this container will copy the whole ADT through and forth on 
every assignment and alike. Isn't this an overkill?

Then John English in his book "Ada 95: The Craft of Object-Oriented 
Programming" is doing this:

function Succ (Iterator : Diary_Iterator) return
Diary_Iterator is
begin
     if Iterator.List = null or else Iterator.Current = null then
         raise Iterator_Error;
     else
         return (List => Iterator.List,
                 Current => Iterator.Current.Next);
     end if;
end Succ;

As I understand he gets in an iterator to increase, but he throws it 
away and creates another one. Is it so cheap or am I missunderstanding 
something about Ada compilers or something?

And one more question about the concept supported by keywords bounded, 
unbounded, dynamic, fixed-length etc. Like first I must admit I don't 
get it; why is there a need for this in Ada, when in tens of other 
languages I've seen there is not? And why there are bounded, unbounded 
and dynamic versions of Booch components but no polymorphic? Are people 
really making collections of 30 (the number is not important but the 
last time I made a fixed structure it was on C64 long time ago) elements 
like Simon Wright in his Case study?

Sory folks, I'm desperate and nobody speaks Ada here :) Please tell me 
what am I missing.

Regards,
Karel Miklav




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Clueless :)
  2003-03-18 12:55 Clueless :) Karel Miklav
@ 2003-03-18 16:37 ` Martin Krischik
  2003-03-20 21:00   ` Simon Wright
  2003-03-18 20:42 ` Matthew Heaney
  2003-03-19  2:21 ` Jeffrey Carter
  2 siblings, 1 reply; 10+ messages in thread
From: Martin Krischik @ 2003-03-18 16:37 UTC (permalink / raw)


On Tue, 18 Mar 2003 13:55:34 +0100, Karel Miklav wrote:

> Learning Ada I'm playing with container libraries and there are some 
> things puzzling me. If I initialize a generic container with an abstract 
> data type, this container will copy the whole ADT through and forth on 
> every assignment and alike. Isn't this an overkill?
> 
 
> As I understand he gets in an iterator to increase, but he throws it 
> away and creates another one. Is it so cheap or am I missunderstanding 
> something about Ada compilers or something?
 
Some Classes are indeed so lightweight that it is indeed aceptable to
create a new instance. BTW: The old instance is not thown away. The caller
of the function can still use that copy.

> And one more question about the concept supported by keywords bounded, 

These are not keywords just identifier.

> unbounded, dynamic, fixed-length etc. Like first I must admit I don't 
> get it; why is there a need for this in Ada, when in tens of other 
> languages I've seen there is not? And why there are bounded, unbounded 
> and dynamic versions of Booch components but no polymorphic? Are people 
> really making collections of 30 (the number is not important but the 
> last time I made a fixed structure it was on C64 long time ago) elements 
> like Simon Wright in his Case study?

Large collection class librarys usualy have theese options (i.E. IBM Open Class
Library - that C++). They somtetimes have different namens. The Idea is
flexibility against speed. In Booch bounded are the fastest but as the
name suggest not very flexible. Unbouded is the most flexible.

30 elements? Well, I use collections (with IBMs OCL) with up to 15.000 elements.
Important is to use the right collection for you data and then performace
is even with > 10.000 elements quite aceptable.

With Regards

Martin

-- 
Martin Krischik
mailto://Martin@krischik.com
http://ada.krischik.com




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Clueless :)
  2003-03-18 12:55 Clueless :) Karel Miklav
  2003-03-18 16:37 ` Martin Krischik
@ 2003-03-18 20:42 ` Matthew Heaney
  2003-03-19  6:43   ` Karel Miklav
  2003-03-19  2:21 ` Jeffrey Carter
  2 siblings, 1 reply; 10+ messages in thread
From: Matthew Heaney @ 2003-03-18 20:42 UTC (permalink / raw)


Karel Miklav <karel@inetis.spppambait.com> wrote in message news:<qHEda.2435$wK6.104835@news.siol.net>...
> Learning Ada I'm playing with container libraries and there are some 
> things puzzling me. If I initialize a generic container with an abstract 
> data type, this container will copy the whole ADT through and forth on 
> every assignment and alike. Isn't this an overkill?

What do you mean by "copy the whole ADT" during assignment.  Types
don't get copied --only objects do-- so your question doesn't make any
sense as written.


> As I understand he gets in an iterator to increase, but he throws it 
> away and creates another one. Is it so cheap or am I missunderstanding 
> something about Ada compilers or something?

You're constructing a new iterator object from an existing iterator
object. Sort of like the function:

   class iterator {
   public:
      iterator succ() const;
   //..
   };

For example:

   iterator i;
   //...
   i = i.succ();

The reason it's written this way in Ada is because scalar types have a
built-in function that already does that:

   I : Integer;
   --...
   I := Integer'Succ (I);

John was just being consistent with the rest of the language.  The
Charles container library (modelled on the C++ STL) is implemented
similarly:

http://home.earthlink.net/~matthewjheaney/charles/


> And one more question about the concept supported by keywords bounded, 
> unbounded, dynamic, fixed-length etc. Like first I must admit I don't 
> get it; why is there a need for this in Ada, when in tens of other 
> languages I've seen there is not? 

Because you don't have "bounded" forms in C++; that is, an array
declared on the stack whose size is dynamic, i.e.

   void op(int n)
   {
      char str[n];  //not std c++
      //...

You can do this in Ada, in C99, and in g++.  For example:

   procedure Op (N : Natural) is
      S : String (1 .. N);
   begin
      --...

You typically need a "bounded" form in order to declare a stack-based
container, whose maximum number of items ("size") isn't know until
run-time:

   procedure Op (Size : Natural) is
      V : List_Subtype (Size);  --no dynamic allocation
   begin



> And why there are bounded, unbounded 
> and dynamic versions of Booch components but no polymorphic? 

Can't you just instantiate the container using an access type that
designates T'Class?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Clueless :)
  2003-03-18 12:55 Clueless :) Karel Miklav
  2003-03-18 16:37 ` Martin Krischik
  2003-03-18 20:42 ` Matthew Heaney
@ 2003-03-19  2:21 ` Jeffrey Carter
  2 siblings, 0 replies; 10+ messages in thread
From: Jeffrey Carter @ 2003-03-19  2:21 UTC (permalink / raw)


Karel Miklav wrote:
> And one more question about the concept supported by keywords bounded, 
> unbounded, dynamic, fixed-length etc. Like first I must admit I don't 
> get it; why is there a need for this in Ada, when in tens of other 
> languages I've seen there is not? And why there are bounded, unbounded 
> and dynamic versions of Booch components but no polymorphic? Are people 
> really making collections of 30 (the number is not important but the 
> last time I made a fixed structure it was on C64 long time ago) elements 
> like Simon Wright in his Case study?

Lots of Ada programs are in safety critical embedded real-time systems, 
like flying commercial airliners, controlling passenger trains, and the 
like. It's often unacceptable in such systems to use dynamic allocation 
("unbounded" structures) so bounded structures are used, with a maximum 
size based on worse case analysis. So, yes, there really are people 
creating fixed maximum size structures even today.

Other languages may have more limited application areas, or may be used 
by less knowledgeable people, and so may only provide unbounded structures.

-- 
Jeff Carter
"Don't knock masturbation. It's sex with someone I love."
Annie Hall




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Clueless :)
  2003-03-18 20:42 ` Matthew Heaney
@ 2003-03-19  6:43   ` Karel Miklav
  0 siblings, 0 replies; 10+ messages in thread
From: Karel Miklav @ 2003-03-19  6:43 UTC (permalink / raw)


Matthew and Jeffrey,

thank you, I feel much better now :)

Regards,
Karel Miklav




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Clueless :)
  2003-03-18 16:37 ` Martin Krischik
@ 2003-03-20 21:00   ` Simon Wright
  2003-03-21  7:39     ` Karel Miklav
                       ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Simon Wright @ 2003-03-20 21:00 UTC (permalink / raw)


"Martin Krischik" <Martin.Krischik@T-Online.de> writes:

> On Tue, 18 Mar 2003 13:55:34 +0100, Karel Miklav wrote:

> > languages I've seen there is not? And why there are bounded,
> > unbounded and dynamic versions of Booch components but no
> > polymorphic? Are people really making collections of 30 (the
> > number is not important but the last time I made a fixed structure
> > it was on C64 long time ago) elements like Simon Wright in his
> > Case study?

The impetus behind the bounded forms is to avoid memory allocation. Of
course, one of the reasons for doing this is because of a need for
high dependability (safety-related software, for instance) and I doubt
that anyone in such an enviromnent will be using off-the-shelf
component libraries. But if you just want to avoid heap fragmentation
they can help.

> Large collection class librarys usualy have theese options (i.E. IBM
> Open Class Library - that C++). They somtetimes have different
> namens. The Idea is flexibility against speed. In Booch bounded are
> the fastest but as the name suggest not very flexible. Unbouded is
> the most flexible.
> 
> 30 elements? Well, I use collections (with IBMs OCL) with up to
> 15.000 elements.  Important is to use the right collection for you
> data and then performace is even with > 10.000 elements quite
> aceptable.

I suppose I could have used 42 as the example. It's not at all
uncommon in embedded systems to know exactly how many of a thing there
are going to be.

In a recent release of the BCs, the Maximum_Size parameter for the
bounded forms is merely the default maximum; you can say
Collections.Unconstrained_Collection (Maximum_Size => nnn) to override
at runtime.

I do take the point that the first thing I show people in the case
study ought to be the simplest thing for them to do; that is now done
using the (new) Unmanaged form, which doesn't require you to specify a
storage manager (and which should work with GNAT 3.12 for those fixed
in the past).

You might say, wouldn't this new Unmanaged better be called Unbounded,
and rename the present Unbounded to Managed? ... well, yes, but the
people out there using the BCs wouldn't thank me!



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Clueless :)
  2003-03-20 21:00   ` Simon Wright
@ 2003-03-21  7:39     ` Karel Miklav
  2003-03-21  8:34     ` Karel Miklav
  2003-03-21  9:26     ` Karel Miklav
  2 siblings, 0 replies; 10+ messages in thread
From: Karel Miklav @ 2003-03-21  7:39 UTC (permalink / raw)


Simon Wright wrote:
> You might say, wouldn't this new Unmanaged better be called Unbounded,
> and rename the present Unbounded to Managed? ... well, yes, but the
> people out there using the BCs wouldn't thank me!

If these component are not some kind of joke I would consider doing a 
fork. You owe it to the kids :)

Regards,
Karel Miklav




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Clueless :)
  2003-03-20 21:00   ` Simon Wright
  2003-03-21  7:39     ` Karel Miklav
@ 2003-03-21  8:34     ` Karel Miklav
  2003-03-21  9:26     ` Karel Miklav
  2 siblings, 0 replies; 10+ messages in thread
From: Karel Miklav @ 2003-03-21  8:34 UTC (permalink / raw)


Simon Wright wrote:
> You might say, wouldn't this new Unmanaged better be called Unbounded,
> and rename the present Unbounded to Managed? ... well, yes, but the
> people out there using the BCs wouldn't thank me!

If these component are not some kind of joke I would consider doing a 
fork in cases like this. You owe it to the kids too :) And thank you for 
your work.

Regards,
Karel Miklav




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Clueless :)
  2003-03-20 21:00   ` Simon Wright
  2003-03-21  7:39     ` Karel Miklav
  2003-03-21  8:34     ` Karel Miklav
@ 2003-03-21  9:26     ` Karel Miklav
  2003-03-21 18:01       ` Simon Wright
  2 siblings, 1 reply; 10+ messages in thread
From: Karel Miklav @ 2003-03-21  9:26 UTC (permalink / raw)


Simon Wright wrote:
 > The impetus behind the bounded forms is to avoid memory allocation. Of
 > course, one of the reasons for doing this is because of a need for
 > high dependability (safety-related software, for instance) and I doubt
 > that anyone in such an enviromnent will be using off-the-shelf
 > component libraries. But if you just want to avoid heap fragmentation
 > they can help.

Sorry, I completely forgot about that. In my business I usually don't 
know the number of types in advance, and can only speculate about orders 
of magnitude of items.

 > I do take the point that the first thing I show people in the case
 > study ought to be the simplest thing for them to do; that is now done
 > using the (new) Unmanaged form, which doesn't require you to specify a
 > storage manager (and which should work with GNAT 3.12 for those fixed
 > in the past).

The tutorial should also show how to fill the container. I was not able 
to find a simple and complete example nowhere, then I've figured it out 
from tests. The next step of learning is probably looking into the 
sources. I would send my examples, but some people may die laughing :) 
Maybe Ada community needs a Wiki?

And yes: do I always have to make separate initialization packages, 
because GNAT chokes on this:


with bc.containers.collections.bounded;

procedure club is

    type person is
       record
          name : string (1 .. 4);
          age  : integer range 0 .. 150;
       end record;

    package container is new bc.containers (person);
    package collection is new container.collections;
    package people is new collection.bounded(maximum_size => 100);

    club : people.collection;

begin

    people.append(club,(name => "nivi", age => 22));

end club;


 > You might say, wouldn't this new Unmanaged better be called Unbounded,
 > and rename the present Unbounded to Managed? ... well, yes, but the
 > people out there using the BCs wouldn't thank me!

If these component are not some kind of joke I would consider doing a 
fork in cases like this. You owe it to the kids too :)

Regards, and thank you for the good work.
Karel Miklav




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Clueless :)
  2003-03-21  9:26     ` Karel Miklav
@ 2003-03-21 18:01       ` Simon Wright
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Wright @ 2003-03-21 18:01 UTC (permalink / raw)


Karel Miklav <karel@inetis.spppambait.com> writes:

> The tutorial should also show how to fill the container. I was not
> able to find a simple and complete example nowhere, then I've figured
> it out from tests.

Good point.

> And yes: do I always have to make separate initialization packages,
> because GNAT chokes on this:

The trouble is, that in order to get initialization and finalization
BC.Containers.Container is derived from Ada.Finalization.Controlled,
and if you do that you have to derive in a library-level package.

This feature of the language is unlikely to go away.

>  > You might say, wouldn't this new Unmanaged better be called Unbounded,
>  > and rename the present Unbounded to Managed? ... well, yes, but the
>  > people out there using the BCs wouldn't thank me!
> 
> If these component are not some kind of joke I would consider doing
> a fork in cases like this. You owe it to the kids too :)

The problem is that I don't have the energy to maintain both
branches. However, enhancement requests aren't that frequent, perhaps
you're right ..



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-03-21 18:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-18 12:55 Clueless :) Karel Miklav
2003-03-18 16:37 ` Martin Krischik
2003-03-20 21:00   ` Simon Wright
2003-03-21  7:39     ` Karel Miklav
2003-03-21  8:34     ` Karel Miklav
2003-03-21  9:26     ` Karel Miklav
2003-03-21 18:01       ` Simon Wright
2003-03-18 20:42 ` Matthew Heaney
2003-03-19  6:43   ` Karel Miklav
2003-03-19  2:21 ` Jeffrey Carter

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