From: Dmitry A. Kazakov on 5 Sep 2009 04:18 On Fri, 4 Sep 2009 16:06:12 -0700 (PDT), Britt Snodgrass wrote: > Ada allows optional names for loops and declare blocks but not for > case or if statetements. Why not, since these are also multi-line > statements that terminate with an 'end" keyword? I sometimes use loop > names to clearly indicate the purpose of the loop and have wished I > could do the same for case statements, e.g., > > Decide_This: > case Some_Variable is > ... > end case Decide_This; > > or similarly for long if statements: > > Decide_That: > if Whatever then > ... > end if Decide_That: > > Such names could also be used in the outline view of an IDE like > Eclipse to support quick location of the named entity. > > I suppose there was some rationale so I'm curious what it was. Ada has labels: <<Decide_This>> case Some_Variable is ... end case; <<Decide_That>> if Whatever then ... end if: -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Robert A Duff on 6 Sep 2009 08:44 "Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> writes: > Ada has labels: > > <<Decide_This>> > case Some_Variable is > ... > end case; > > <<Decide_That>> > if Whatever then > ... > end if: I prefer comments: -- Decide this. case Some_Variable is ... end case; -- Decide that. if Whatever then ... end if: To me, a label is a warning that gotos are lurking around the place. - Bob
From: Britt on 6 Sep 2009 13:46 On Sep 6, 7:44 am, Robert A Duff <bobd...(a)shell01.TheWorld.com> wrote: > "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> writes: > > > Ada has labels: > > > <<Decide_This>> > > case Some_Variable is > > ... > > end case; > > > <<Decide_That>> > > if Whatever then > > ... > > end if: > > I prefer comments: > > -- Decide this. > case Some_Variable is > ... > end case; > > -- Decide that. > if Whatever then > ... > end if: > > To me, a label is a warning that gotos are lurking around the place. Labels are also useful as breakpoint targets if the compiler produces associated symbolic information that can then be used by the debugger. Using labels for this purpose is much better (more maintainable) than breaking on line numbers. Such permanent breakpoints are sometimes useful in formal white-box test procedures. SPARK was recently changed to allow use of Ada labels for this purpose (breakpoints, not gotos), and the GNATPP pretty-printer now has a new switch to format Ada labels on separate lines (as shown in Dmitry's example). The responses to my original question have been informative. I think I would still like for the next revision of Ada to allow a name on any multi-line construct that closes with an end keyword. This would make the language more symmetric, I think. It would also be useful if Ada IDEs included both names and labels in their outline view to facilitate source code navigation. - Britt
From: Ole-Hjalmar Kristensen on 7 Sep 2009 03:27 That could be useful, but I have seen compilers produce worse code by having labels around (like not putting variables in registers), presumably because the analysis showed it was a potential target for a goto. >>>>> "B" == Britt <britt.snodgrass(a)gmail.com> writes: <snip> B> Labels are also useful as breakpoint targets if the compiler produces B> associated symbolic information that can then be used by the B> debugger. Using labels for this purpose is much better (more B> maintainable) than breaking on line numbers. Such permanent B> breakpoints are sometimes useful in formal white-box test procedures. B> SPARK was recently changed to allow use of Ada labels for this B> purpose (breakpoints, not gotos), and the GNATPP pretty-printer now B> has a new switch to format Ada labels on separate lines (as shown in B> Dmitry's example). <snip> B> - Britt -- C++: The power, elegance and simplicity of a hand grenade.
First
|
Prev
|
Pages: 1 2 Prev: AIDE by Stéphane Rivière Next: gnatbind error with gtk after upgrade to GNAT GPL 2009 |