comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Why no named case statements?
Date: Fri, 04 Sep 2009 20:29:28 -0400
Date: 2009-09-04T20:29:28-04:00	[thread overview]
Message-ID: <wccy6oumdxz.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 5233a224-07c1-4a7b-906e-b4cb8e193c85@y42g2000yqb.googlegroups.com

Britt Snodgrass <britt.snodgrass@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



  parent reply	other threads:[~2009-09-05  0:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-04 23:06 Why no named case statements? Britt Snodgrass
2009-09-04 23:47 ` Adam Beneschan
2009-09-05  0:29 ` Robert A Duff [this message]
2009-09-05  0:49   ` Adam Beneschan
2009-09-05  1:04     ` Robert A Duff
2009-09-05  8:18 ` Dmitry A. Kazakov
2009-09-06 12:44   ` Robert A Duff
2009-09-06 17:46     ` Britt
2009-09-07  7:27       ` Ole-Hjalmar Kristensen
replies disabled

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