comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Indentation
Date: Fri, 08 Aug 2014 10:16:31 -0700
Date: 2014-08-08T10:16:31-07:00	[thread overview]
Message-ID: <ls30lf$cj2$2@dont-email.me> (raw)
In-Reply-To: <0c2b1cf8-125b-44d6-9f46-2dc1c546e5c6@googlegroups.com>

On 08/08/2014 09:32 AM, Adam Beneschan wrote:
>
> An RM example in B.3.3 looks like:
>
> type T (Flag : Boolean := False) is
>      record
>          case Flag is
>              when False =>
>                  F1 : Float := 0.0;
>              when True =>
>                  F2 : Integer := 0;
>          end case;
>      end record
>      with Unchecked_Union;
>
> That's as good an answer as you're going to get.  Other people may have other preferences, but you really can't make an objective case for one or another style as long as it's reasonable.

That depends on whether people can agree on a precise specification of why 
indentation is used. The compiler doesn't care, so it must be for humans, and as 
it increases writing complexity, it must be for readers. So if we have a precise 
statement of what indentation is supposed to convey to readers we can speak more 
objectively about it than just "this is what I like" or "this is what the ARM uses".

For me, indentation exists to reflect nesting. If A is indented 1 indentation 
level from B, then A is nested directly within B; if A is indented 2 levels, 
then it is nested directly in something else (C) that is nested directly within B.

With this definition, the indentation in the ARM example is clearly incorrect. 
The case statement is nested directly within the type declaration, but is 
indented 2 levels; F1 and F2 are nested directly within the case statement but 
are indented another 2 levels.

What is new in Ada 12 that I haven't worked with yet is the aspect clause. This 
is clearly part of the type declaration, not nested within it, and so should be 
part of the type framing text. So I would probably indent this as

type T (Flag : Boolean := False) is record
    case Flag is
    when False =>
       F1 : Float := 0.0;
    when True =>
       F2 : Integer := 0;
    end case;
end record with Unchecked_Union;

For a lengthy aspect clause, I like something that indicates clearly that the 
declaration is not finished yet, so I'd probably use

end record with
    <aspect 1>,
    <aspect 2>,
    ...,
    <aspect N>;

I've never heard a reason for indentation that resulted in the indentation used 
by the ARM, or a satisfactory explanation of why the ARM indents record type 
declarations and case statements the way it does. If one should write

type T is
    record

then surely one should also write

type T is
    range

type T is
    array

and the like.

At the Ada launch (1980 Dec 10), Ichbiah talked about "comb structures" driving 
the layout of code, and the ARM indentation of records and cases seems to 
violate that rule.

Of course, the ARM indentation goes back to Ada 80, and one can argue that the 
ARM is never wrong, in which case indentation is arbitrary and the only rule can 
be "use what the ARM uses".

-- 
Jeff Carter
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail
17


  reply	other threads:[~2014-08-08 17:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-08 16:12 Indentation Victor Porton
2014-08-08 16:32 ` Indentation Adam Beneschan
2014-08-08 17:16   ` Jeffrey Carter [this message]
2014-08-08 17:45     ` Indentation Peter Chapin
2014-08-08 17:50       ` Indentation Peter Chapin
2014-08-08 22:51     ` Indentation Randy Brukardt
2014-08-08 16:38 ` Indentation Pascal Obry
replies disabled

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