From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,51bff7cd4c35a15d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.223.40 with SMTP id qr8mr182958pbc.0.1338473498392; Thu, 31 May 2012 07:11:38 -0700 (PDT) Path: l9ni3913pbj.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Ada2012 : In praise of 'for ... of ... loop'... Date: Thu, 31 May 2012 07:09:38 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8e00262b-8ff5-4862-b4a4-d19465a389b1@googlegroups.com> References: <74e4e6b5-20bd-4388-b4a0-dfbecc8070be@googlegroups.com> <4fc4e51d$0$6566$9b4e6d93@newsspool4.arcor-online.net> <371a4b67-1969-4cd5-90f4-d58a9b276f29@googlegroups.com> NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 X-Trace: posting.google.com 1338473498 6747 127.0.0.1 (31 May 2012 14:11:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 31 May 2012 14:11:38 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-05-31T07:09:38-07:00 List-Id: 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 = =3D> 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)& "=3D"& To_String (= Pair.Value)); > > end loop; > > end loop; >=20 > This uses 2 inline "for" loops, one containing a nested "for loop". >=20 > > Close (File); > > exception > > -- implementation detail > > end Save; > > > > what we used to have (mocked up!): >=20 > This uses vector iterators. >=20 > While this is a nice feature, I don't think it's worth the added language= =20 > complexity. >=20 > In general, using "for" loops will be clearer than using iterators. In th= e case=20 > of vectors (or unbounded arrays, to use their correct name), one can iter= ate=20 > over them using "for" loops, and the use of iterators for an array abstra= ction=20 > is a questionable practice: >=20 > for I in Header_Comments.First_Index .. Header_Comments.Last_Index loop > Put_Line (File, Comment_Str & Header_Comments.Element (I) ); > end loop; >=20 > if ... then > ... > end if; >=20 > for I in This.Sections.First_Index .. This.Sections.Last_Index loop > Section :=3D This.Sections.Element (I); > Put_Line ... >=20 > for J in Section.Pairs.First_Index .. Section.Pairs.Last_Index loop > Pair :=3D Section.Pairs.Element (J); > Put_Line ... > end loop; > end loop; >=20 > I think this is equally clear and requires no additional language complex= ity. >=20 > Had your example used sets or maps it would have been a stronger argument= . >=20 > --=20 > Jeff Carter > "He didn't get that nose from playing ping-pong." > Never Give a Sucker an Even Break > 110 >=20 > --- Posted via news://freenews.netfront.net/ - Complaints to news@netfron= t.net --- Sorry, I just find that full of "noise" these days...to many characters tha= t are just repeated. and 'Section' and 'Pairs' need to be declared somewher= e too. I know you can get rid of the repetition with some 'renames' or a ne= sted subprogram but that's just "noise" and makes more work for the reader. Aside from the benefits Pascal mentions, the new syntax offers both readabi= lity *and writability* which is a bit of a departure for the language ;-) -- Martin