From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Ada2012 : In praise of 'for ... of ... loop'...
Date: Wed, 30 May 2012 12:30:21 -0700
Date: 2012-05-30T12:30:21-07:00 [thread overview]
Message-ID: <jq5sgd$2tu5$1@adenine.netfront.net> (raw)
In-Reply-To: <371a4b67-1969-4cd5-90f4-d58a9b276f29@googlegroups.com>
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 news@netfront.net ---
next prev parent reply other threads:[~2012-05-30 19:30 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 [this message]
2012-05-30 20:54 ` Pascal Obry
2012-05-31 14:09 ` Martin
2012-05-31 20:58 ` tonyg
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