Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)
From: Dmitry A. Kazakov (mailbox_at_dmitry-kazakov.de)
Date: 10/04/04
- Next message: David Botton: "Re: GWindows and David Botton"
- Previous message: Marius Amado Alves: "Re: GWindows and a future home for it"
- In reply to: Matthew Heaney: "Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)"
- Next in thread: Robert Kawulak: "Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 4 Oct 2004 15:21:53 +0200
On Mon, 04 Oct 2004 12:16:58 GMT, Matthew Heaney wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> It is because they are not arrays. But why an ordered list should not
>> implement an array interface? In my view it should, making the above
>> legal for lists.
>
> Stop obsessing about syntax.
Aha, but semantically that all is just a Turing machine. So yes, I am
obsessed with syntax. (:-))
> If you want a consistent interface for
> containers, you have that in AI-302 (but of course it's not an "array"
> interface):
>
> procedure Op (Container : <container's type>) is
> C : Cursor := First (Container);
> begin
> while Has_Element (C) loop
> Process (C); --or Process (Element (C))
> Next (C);
> end loop;
> end Op;
>
> Actually, if you intend on iterating over all the elements in a
> container, the passive iterator is preferred:
>
> procedure Op (Container : <containers's type> is
> begin
> Container.Iterate (Process'Access);
> end;
>
> If you have an array type, then you can give it a container-like
> interface for the purpose of binding an array object to a generic
> algorithm. I showed how to do this in an earlier post.
This is what I think the wrong way is - to use Ada's arrays like STL
containers, instead of the reverse. You will probably agree that iteration
is a fundamental programming pattern. As such, it IMO deserves a separate
language construct rather than being hidden in a subroutine call.
>> I do! I hate implicit iterators, I prefer loops where
>> possible. Especially, because exit conditions, nested iterations,
>> exception handling become visible.
>
> If you intend on traversing every element in the container, then use a
> passive iterator. It's more efficient, and less error-prone.
>
> If you have exit conditions, then go ahead and use an active-iterator
> style loop.
Just compare:
declare
C : Cursor := First (Container);
begin
while Has_Element (C) loop
Process (Element (C));
Next (C);
end loop;
end;
with
for C in Container'Range loop
Process (Container (C));
end loop;
You have to know about Cursor, First, Has_Element, Element and Next only to
call Process on each element of a container!
[ Don't even try to tell me that First is like 'First etc. Because, being
obsessed with syntax, I will reply that then it should be named 'First!
(:-)) ]
>> [ Ranting: 40 years spent in developing readable, safe, well-structured
>> language constructs, only to replace them with nested function calls a la
>> Lisp? ]
>
> This is a specious comparison.
I tried hard... (:-))
-- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
- Next message: David Botton: "Re: GWindows and David Botton"
- Previous message: Marius Amado Alves: "Re: GWindows and a future home for it"
- In reply to: Matthew Heaney: "Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)"
- Next in thread: Robert Kawulak: "Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|