From: Britt Snodgrass on
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.

- Britt
From: Adam Beneschan on
On Sep 4, 4:06 pm, Britt Snodgrass <britt.snodgr...(a)gmail.com> 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?

Probably because for loops and blocks, the names are useful for
something else. For loops, you can specify the loop name in an EXIT
statement (useful if you nest loops and want to exit the outer one).
For blocks, the block name can be used as part of an expanded name
(i.e. if you declare a variable V in the declaration portion of the
declare block, you can refer to Block_Name.V). My guess is that since
the names were needed for those purposes for loops and blocks, but not
for anything else, the original language designers didn't bother to
allow them for other compound statements.


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:

I'd just use comments.

-- Decide_This:
case Some_Variable is
...
end case; -- Decide_This

-- Adam
From: Robert A Duff on
Britt Snodgrass <britt.snodgrass(a)gmail.com> writes:

> 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...

I think loop names are for doing exits from nested loops.
If you're using them to "clearly indicate...", then I think
you are unintentionally obfuscating. Reader thinks, "Uh, oh,
there's nested exits in here..." But it's a false alarm.

If you want to clearly indicate the purpose of a block of
code, I think a comment is what you want, plus surrounding that
block with blank lines. As in:

... -- previous code

-- Decide this:
case Some_Variable is
...
end case;

... -- following code

>... and have wished I
> could do the same for case statements, e.g.,
>
> Decide_This:
> case Some_Variable is
> ...
> end case Decide_This;

I suppose you could do this:

Decide_This: begin
case Some_Variable is
...
end case Decide_This;
end Decide_This;

Actually, in GNAT there are some places that look something like this:

case Some_Variable is
when This =>
Do_This: begin
..
end Do_This;
when That =>
Do_That: begin
..
end Do_That;
... -- and so on for hundreds of cases
end case;

> 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.

Loop names were invented so you could exit from nested ones.
Block names were invented so you could refer to nested
objects using dot notation, as in Block_Name.Local.
I suppose nobody thought of naming particular statements
as you would a procedure name. That's my guess, as to rationale.

- Bob
From: Adam Beneschan on
On Sep 4, 5:29 pm, Robert A Duff <bobd...(a)shell01.TheWorld.com> wrote:

> Decide_This: begin
>   case Some_Variable is
>   ...
>   end case Decide_This;
> end Decide_This;

Well, you can't say "end case Decide_This;", but I assume that was
just a typo.

But anyway, I like this solution. It should accomplish its purpose
nicely.

-- Adam
From: Robert A Duff on
Adam Beneschan <adam(a)irvine.com> writes:

> On Sep 4, 5:29�pm, Robert A Duff <bobd...(a)shell01.TheWorld.com> wrote:
>
>> Decide_This: begin
>> � case Some_Variable is
>> � ...
>> � end case Decide_This;
>> end Decide_This;
>
> Well, you can't say "end case Decide_This;", but I assume that was
> just a typo.

Yeah, just a cut&paste error. Thanks for the correction.

> But anyway, I like this solution. It should accomplish its purpose
> nicely.

Yeah, but I like the "when" example even better.

- Bob