comp.lang.ada
 help / color / mirror / Atom feed
* Re: Proposed change to BC iterator parameters
@ 2003-12-11 15:05 ada_wizard
  2003-12-11 16:45 ` Robert A Duff
  0 siblings, 1 reply; 50+ messages in thread
From: ada_wizard @ 2003-12-11 15:05 UTC (permalink / raw)
  To: comp.lang.ada

MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
User-Agent: Internet Messaging Program (IMP) 3.2.1

"Steve" <nospam_steved94@comcast.net> writes:

> "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message
> news:wccekvc2rol.fsf@shell01.TheWorld.com...
> [snip]
> >
> > I don't understand the point of Param_Type and Param above.  If you want
> > to pass extra information to Apply, nest the instantiation in a place
> > where it can see that data.
> 
> The reason for Param_Type and Param is to avoid using data outside of the
> scope of the Apply routine except for the arguments to the Apply machine.
> It comes from that old school of thought:
>   Avoid global data
>   All inputs and outputs of a procedure should appear in their parameter
> lists

Just for the record, I agree with Robert Duff here :).

While the rules you state are in general reasonable, no rule should be
treated as an absolute. A local instantiation of a generic iterator
that accesses data in the local scope that is not in the parameter
list is _not_ using global data. SAL takes this approach.

In addition, it is useful to have a version of the iterator that does
_not_ take Param_Type. I haven't looked at the booch components (yes,
that is a failing on my part :); perhaps it offers both flavors of
iterators. For me, that is an unnecessary complication, requiring
extra testing and maintenance.


On a slightly related topic:

There was an interesting paper at the SigAda conference yesterday (I'm
posting from my hotel) on "shortcuts" as an efficient way to implement
"safe" containers (no dangling links, even when iterators are used to
delete items). Looked like a good idea; I recommend checking it out. I
think the proceedings will be in a future issue of Ada Letters.

-- 
-- Stephe

___________________________________________________________
This mail sent using ToadMail -- Web based e-mail @ ToadNet



^ permalink raw reply	[flat|nested] 50+ messages in thread
* RE: Proposed change to BC iterator parameters
@ 2003-12-23 10:40 amado.alves
  0 siblings, 0 replies; 50+ messages in thread
From: amado.alves @ 2003-12-23 10:40 UTC (permalink / raw)
  To: comp.lang.ada

"The current building blocks violate at least one important "ility":
readability.  You have to instantiate separately, and you have to split
the loop body out into a separate procedure, and you have to pass extra
paraameters around, all of which means that the pieces of the loop get
scattered about.  And you have to clutter the namespace with a name for
the loop body, which is not (usually) a natural abstraction on its own,
and doesn't deserve a separate name.  Or you have to use the "cursor"
style, which has problems I pointed out elsewhere." (Bob)

Ok, maybe we're entering a subjective area here. Personally I don't find these things more problematic than any proposal I've seen so far, "Java style interfaces" included. Usually I tackle the above problems using good old top-down development, encapsulating the implementation complexity inside meaninfully named subprograms. I'm happier with this solution than with any proposal I've seen so far. Except generic parameters ;-)



^ permalink raw reply	[flat|nested] 50+ messages in thread
* RE: Proposed change to BC iterator parameters
@ 2003-12-19 15:53 amado.alves
  2003-12-19 23:05 ` Robert A Duff
  0 siblings, 1 reply; 50+ messages in thread
From: amado.alves @ 2003-12-19 15:53 UTC (permalink / raw)
  To: comp.lang.ada

"...Ada has such weak support for iterators."
 
Will you stop saying that? An iterator is an abstraction. No general purpose language is suppose to have "support for iterators". Ada provides many building blocks appropriate for constructing iterators. The only thing lacking is perhaps anonymous subprograms (e.g. like blocks in Smalltalk). But I fear adding that would go against a number of the "-ilities".



^ permalink raw reply	[flat|nested] 50+ messages in thread
* RE: Proposed change to BC iterator parameters
@ 2003-12-11 16:02 amado.alves
  0 siblings, 0 replies; 50+ messages in thread
From: amado.alves @ 2003-12-11 16:02 UTC (permalink / raw)
  To: comp.lang.ada

<<There was an interesting paper at the SigAda conference yesterday (I'm
posting from my hotel) on "shortcuts" as an efficient way to implement
"safe" containers (no dangling links, even when iterators are used to
delete items). Looked like a good idea; I recommend checking it out. I
think the proceedings will be in a future issue of Ada Letters.>>

This must be the same theory that was presented at the containers workshop in Ada-Europe 2001. Those of the participants who were able to understand it concluded it was unnecessary. I was a participant, I did NOT understand it, but I trust one who did, and so I will not look into it.




^ permalink raw reply	[flat|nested] 50+ messages in thread
* RE: Proposed change to BC iterator parameters
@ 2003-12-11 12:56 amado.alves
  2003-12-17 20:25 ` Robert A Duff
  0 siblings, 1 reply; 50+ messages in thread
From: amado.alves @ 2003-12-11 12:56 UTC (permalink / raw)
  To: comp.lang.ada

<<...
  Avoid global data
  All inputs and outputs of a procedure should appear in their parameter
lists

Following these simple guidelines usually makes code a lot easier to follow.>>

In the big, yes, but not in the small, namely in loops, ifs, and... visits.




^ permalink raw reply	[flat|nested] 50+ messages in thread
* RE: Proposed change to BC iterator parameters
@ 2003-12-11 12:43 amado.alves
  0 siblings, 0 replies; 50+ messages in thread
From: amado.alves @ 2003-12-11 12:43 UTC (permalink / raw)
  To: comp.lang.ada

<<...
> with premature termination of the iteration done by raising inside
> Apply an exception which Visit_With_In_Param propagates by
> definition. 

Yeah, that works.  It's not very efficient...>>

In GNAT it is no less efficient than the boolean parameter approach. I've checked experimentally. Is it a *real* problem in other implementations?

<<...Ada really doesn't have very good support for iterators.>>

I see some weaknesses in Ada, but not this one.

<<...
(Goto haters should consider that exceptions are just like gotos, except
you don't know statically where they're going to -- i.e., exceptions are
*worse* than gotos, from a structured programming point of view.)>>

There are two opposing schools of though regarding the use of exceptions for control flow. Obviously I belong to the one that says it's OK.

<<I don't understand the point of Param_Type and Param above.  If you want
to pass extra information to Apply, nest the instantiation in a place
where it can see that data.>>

Exactly, cf. example in my previous message.




^ permalink raw reply	[flat|nested] 50+ messages in thread
* RE: Proposed change to BC iterator parameters
@ 2003-12-11 12:33 amado.alves
  0 siblings, 0 replies; 50+ messages in thread
From: amado.alves @ 2003-12-11 12:33 UTC (permalink / raw)
  To: comp.lang.ada

<<
> indefinite formals, but I pass well without limited ones. Most limited
> formals I've seen in libraries are accompanied by a formal assignment
> operation or some such, which prety much defeats the purpose of their
> (formal) limitedness, i.e. their logic is in clash with their definition.

Well there is one exception here. It's File_Type. I can see the need to
write a container to a file with the help of an iterator. Here limited
might help.

Remember: we talk about an extra parameter to the iterator and not about the
data stored inside the container.>>

That's two *separate* issues. Passing a file parameter to an iterator:

procedure Iterate_With_File (F : File_Type) is
  procedure Apply (Item : Iterator) is
  begin
    Op (F, Item);
  end;
  procedure A_Visit is new Visit (Apply);
begin
  A_Visit;
end;

Now, a container of files. With a container library that does not accept limited element types. You know, every problem can be solved with yet another level of indirection:

  type File_Ptr is access all File_Type;
  package My_Container is new Container (File_Ptr);





^ permalink raw reply	[flat|nested] 50+ messages in thread
* RE: Proposed change to BC iterator parameters
@ 2003-12-10 14:39 amado.alves
  0 siblings, 0 replies; 50+ messages in thread
From: amado.alves @ 2003-12-10 14:39 UTC (permalink / raw)
  To: comp.lang.ada

<<...
   generic
      with procedure Apply (Elem : in Item);
   procedure Visit_With_In_Param (Using : in out Iterator'Class);

with premature termination of the iteration done by raising inside Apply an exception which Visit_With_In_Param propagates by definition.>>

Oops... obviously I should have deleted the "_With_In_Param" part in the names.





^ permalink raw reply	[flat|nested] 50+ messages in thread
* RE: Proposed change to BC iterator parameters
@ 2003-12-10 13:36 amado.alves
  2003-12-10 17:39 ` Martin Krischik
                   ` (3 more replies)
  0 siblings, 4 replies; 50+ messages in thread
From: amado.alves @ 2003-12-10 13:36 UTC (permalink / raw)
  To: Simon Wright, comp.lang.ada

<<...
   generic
      type Param_Type is private;
      with procedure Apply (Elem : in Item;
                            Param : in Param_Type;
                            OK : out Boolean);
   procedure Visit_With_In_Param (Using : in out Iterator'Class;
                                  Param : in Param_Type);
>>

I've never found a situation where the following much simpler signature wouldn't suffice:

   generic
      with procedure Apply (Elem : in Item);
   procedure Visit_With_In_Param (Using : in out Iterator'Class);

with premature termination of the iteration done by raising inside Apply an exception which Visit_With_In_Param propagates by definition.

<<...      type Param_Type (<>) is limited private;

As I understand it, this allows users much more freedom (you can even
use a tagged type provided you instantiate with Tagged_Type'Class)...>>

Strictly you don't need the limited formal for (unlimited) tagged or class actuals. You need the limited formal for limited actuals, whatever their class. Limitedness is completely orthogonal to definiteness. I do like indefinite formals, but I pass well without limited ones. Most limited formals I've seen in libraries are accompanied by a formal assignment operation or some such, which prety much defeats the purpose of their (formal) limitedness, i.e. their logic is in clash with their definition.




^ permalink raw reply	[flat|nested] 50+ messages in thread
* Proposed change to BC iterator parameters
@ 2003-12-10  5:46 Simon Wright
  2003-12-10 18:12 ` Jeffrey Carter
  2003-12-10 20:59 ` Simon Wright
  0 siblings, 2 replies; 50+ messages in thread
From: Simon Wright @ 2003-12-10  5:46 UTC (permalink / raw)


Martin Krischik <krischik@users.sourceforge.net>'s AdaCL
(http://adacl.sourceforge.net) includes changes to some of the Booch
Component iterators. For example,

   generic
      type Param_Type is private;
      with procedure Apply (Elem : in Item;
                            Param : in Param_Type;
                            OK : out Boolean);
   procedure Visit_With_In_Param (Using : in out Iterator'Class;
                                  Param : in Param_Type);
   --  Call Apply with a Parameter for each Item in the Container to
   --  which the iterator Using is bound. The iteration will terminate
   --  early if Apply sets OK to False.

Martin proposes

      type Param_Type (<>) is private;

but it occurs to me that the code ought to be

      type Param_Type (<>) is limited private;

As I understand it, this allows users much more freedom (you can even
use a tagged type provided you instantiate with Tagged_Type'Class).

But are there any downsides? (backward incompatibility being something
to for me to avoid!)

-- 
Simon Wright                               100% Ada, no bugs.



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

end of thread, other threads:[~2003-12-23 10:40 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-11 15:05 Proposed change to BC iterator parameters ada_wizard
2003-12-11 16:45 ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
2003-12-23 10:40 amado.alves
2003-12-19 15:53 amado.alves
2003-12-19 23:05 ` Robert A Duff
2003-12-11 16:02 amado.alves
2003-12-11 12:56 amado.alves
2003-12-17 20:25 ` Robert A Duff
2003-12-11 12:43 amado.alves
2003-12-11 12:33 amado.alves
2003-12-10 14:39 amado.alves
2003-12-10 13:36 amado.alves
2003-12-10 17:39 ` Martin Krischik
2003-12-10 18:22 ` Jeffrey Carter
2003-12-10 23:00   ` Robert A Duff
2003-12-11  1:00     ` Jeffrey Carter
2003-12-11 15:09       ` Robert A Duff
2003-12-11  8:33     ` Dmitry A. Kazakov
2003-12-10 20:50 ` Simon Wright
2003-12-10 23:12 ` Robert A Duff
2003-12-11  5:07   ` Steve
2003-12-11 15:24     ` Robert A Duff
2003-12-11 17:39       ` Jeffrey Carter
2003-12-12 22:22         ` Robert A Duff
2003-12-13  0:57           ` Jeffrey Carter
2003-12-17 20:59             ` Robert A Duff
2003-12-18 10:05               ` Dmitry A. Kazakov
2003-12-18 18:14                 ` Robert A Duff
2003-12-19 10:53                   ` Dmitry A. Kazakov
2003-12-19 16:17                     ` Georg Bauhaus
2003-12-19 17:19                       ` Dmitry A. Kazakov
2003-12-19 22:51                         ` Robert A Duff
2003-12-20 12:20                           ` Dmitry A. Kazakov
2003-12-19 22:47                       ` Robert A Duff
2003-12-20  2:11                         ` Stephen Leake
2003-12-20 19:08                         ` Robert I. Eachus
2003-12-21 11:39                           ` Simon Wright
2003-12-21 18:13                             ` Robert I. Eachus
2003-12-21 13:58                           ` Dmitry A. Kazakov
2003-12-22  1:25                             ` Robert I. Eachus
     [not found]         ` <916oa1-c93.ln1@beastie.ix.netcom.com>
2003-12-13 16:57           ` Simon Wright
2003-12-12  5:29     ` Simon Wright
2003-12-12 22:26       ` Robert A Duff
2003-12-13 16:55         ` Simon Wright
2003-12-13 17:27           ` Dmitry A. Kazakov
2003-12-13  2:44       ` Steve
2003-12-10  5:46 Simon Wright
2003-12-10 18:12 ` Jeffrey Carter
2003-12-11 16:10   ` Martin Krischik
2003-12-10 20:59 ` Simon Wright

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