comp.lang.ada
 help / color / mirror / Atom feed
From: tonyg <tonythegair@gmail.com>
Subject: Re: Ada2012 : In praise of 'for ... of ... loop'...
Date: Thu, 31 May 2012 13:58:24 -0700 (PDT)
Date: 2012-05-31T13:58:24-07:00	[thread overview]
Message-ID: <53841cff-1dc1-47ec-8778-4a3f1c3ba55e@j9g2000vbk.googlegroups.com> (raw)
In-Reply-To: 8e00262b-8ff5-4862-b4a4-d19465a389b1@googlegroups.com

On May 31, 2:09 pm, Martin <mar...@thedowies.com> wrote:
> On Wednesday, May 30, 2012 8:30:21 PM UTC+1, Jeffrey Carter wrote:
> > On 05/30/2012 01:10 AM, Martin wrote:
>
> > >        for Comment of Header_Comments loop
> > >           Put_Line (File, Comment_Str&  Comment);
> > >        end loop;
> > >        if Include_Last_Saved_Time then
> > >           Put_Line (File, Comment_Str&  "Last saved: "&  Image (Date =>  Clock));
> > >        end if;
> > >        for Section of This.Sections loop
> > >           Put_Line (File, "["&  To_String (Section.Name)&  "]");
> > >           for Pair of Section.Pairs loop
> > >              Put_Line (File, To_String (Pair.Key)&  "="&  To_String (Pair.Value));
> > >           end loop;
> > >        end loop;
>
> > This uses 2 inline "for" loops, one containing a nested "for loop".
>
> > >        Close (File);
> > >     exception
> > >        -- implementation detail
> > >     end Save;
>
> > > what we used to have (mocked up!):
>
> > This uses vector iterators.
>
> > While this is a nice feature, I don't think it's worth the added language
> > complexity.
>
> > In general, using "for" loops will be clearer than using iterators. In the case
> > of vectors (or unbounded arrays, to use their correct name), one can iterate
> > over them using "for" loops, and the use of iterators for an array abstraction
> > is a questionable practice:
>
> > for I in Header_Comments.First_Index .. Header_Comments.Last_Index loop
> >     Put_Line (File, Comment_Str & Header_Comments.Element (I) );
> > end loop;
>
> > if ... then
> >     ...
> > end if;
>
> > for I in This.Sections.First_Index .. This.Sections.Last_Index loop
> >     Section := This.Sections.Element (I);
> >     Put_Line ...
>
> >     for J in Section.Pairs.First_Index .. Section.Pairs.Last_Index loop
> >        Pair := Section.Pairs.Element (J);
> >        Put_Line ...
> >     end loop;
> > end loop;
>
> > I think this is equally clear and requires no additional language complexity.
>
> > Had your example used sets or maps it would have been a stronger argument.
>
> > --
> > Jeff Carter
> > "He didn't get that nose from playing ping-pong."
> > Never Give a Sucker an Even Break
> > 110
>
> > --- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net ---
>
> Sorry, I just find that full of "noise" these days...to many characters that are just repeated. and 'Section' and 'Pairs' need to be declared somewhere too. I know you can get rid of the repetition with some 'renames' or a nested subprogram but that's just "noise" and makes more work for the reader.
>
> Aside from the benefits Pascal mentions, the new syntax offers both readability *and writability* which is a bit of a departure for the language ;-)
>
> -- Martin


very interesting. Thanks for the example and explaining it well
Martin. I really appreciate this because it does not come easily to
me, but once its there it sticks and is very useful. Is this going to
go into a wiki, maybe the danish ada mafia would host a gems like
section in there.



  reply	other threads:[~2012-05-31 20:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-29 14:29 Ada2012 : In praise of 'for ... of ... loop' Martin
2012-05-29 15:02 ` Georg Bauhaus
2012-05-30  8:10   ` Martin
2012-05-30  8:15     ` Thomas Løcke
2012-05-30 16:21       ` Pascal Obry
2012-05-30 19:30     ` Jeffrey Carter
2012-05-30 20:54       ` Pascal Obry
2012-05-31 14:09       ` Martin
2012-05-31 20:58         ` tonyg [this message]
2012-05-30 22:26     ` Georg Bauhaus
2012-05-30 22:45       ` Georg Bauhaus
2012-06-07  0:19       ` Randy Brukardt
2012-06-07 12:42         ` Georg Bauhaus
2012-06-07 12:54           ` Georg Bauhaus
replies disabled

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