* Indentation
@ 2014-08-08 16:12 Victor Porton
2014-08-08 16:32 ` Indentation Adam Beneschan
2014-08-08 16:38 ` Indentation Pascal Obry
0 siblings, 2 replies; 7+ messages in thread
From: Victor Porton @ 2014-08-08 16:12 UTC (permalink / raw)
What should be the indentation in the following Ada code fragment
(especially its last line)?
type T is
record
X: Integer;
end record
with Convention => C;
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indentation
2014-08-08 16:12 Indentation Victor Porton
@ 2014-08-08 16:32 ` Adam Beneschan
2014-08-08 17:16 ` Indentation Jeffrey Carter
2014-08-08 16:38 ` Indentation Pascal Obry
1 sibling, 1 reply; 7+ messages in thread
From: Adam Beneschan @ 2014-08-08 16:32 UTC (permalink / raw)
On Friday, August 8, 2014 9:12:55 AM UTC-7, Victor Porton wrote:
> What should be the indentation in the following Ada code fragment
>
> (especially its last line)?
>
>
>
> type T is
> record
> X: Integer;
> end record
> with Convention => C;
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.
-- Adam
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indentation
2014-08-08 16:12 Indentation Victor Porton
2014-08-08 16:32 ` Indentation Adam Beneschan
@ 2014-08-08 16:38 ` Pascal Obry
1 sibling, 0 replies; 7+ messages in thread
From: Pascal Obry @ 2014-08-08 16:38 UTC (permalink / raw)
Le vendredi 08 août 2014 à 19:12 +0300, Victor Porton a écrit :
> What should be the indentation in the following Ada code fragment
> (especially its last line)?
>
> type T is
> record
> X: Integer;
> end record
> with Convention => C;
For me:
type T is record
X: Integer;
end record with Convention => C;
3 lines. If there is multiple aspects, probably:
type T is record
X: Integer;
end record with
Pass_By_Copy => True,
Convention => C;
or
type T is record
X: Integer;
end record
with
Pass_By_Copy => True,
Convention => C;
Not sure yet as this is quite recent and I did not use such aspects.
--
Pascal Obry / Magny Les Hameaux (78)
The best way to travel is by means of imagination
http://v2p.fr.eu.org
http://www.obry.net
gpg --keyserver keys.gnupg.net --recv-key F949BD3B
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indentation
2014-08-08 16:32 ` Indentation Adam Beneschan
@ 2014-08-08 17:16 ` Jeffrey Carter
2014-08-08 17:45 ` Indentation Peter Chapin
2014-08-08 22:51 ` Indentation Randy Brukardt
0 siblings, 2 replies; 7+ messages in thread
From: Jeffrey Carter @ 2014-08-08 17:16 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indentation
2014-08-08 17:16 ` Indentation Jeffrey Carter
@ 2014-08-08 17:45 ` Peter Chapin
2014-08-08 17:50 ` Indentation Peter Chapin
2014-08-08 22:51 ` Indentation Randy Brukardt
1 sibling, 1 reply; 7+ messages in thread
From: Peter Chapin @ 2014-08-08 17:45 UTC (permalink / raw)
On 2014-08-08 13:16, Jeffrey Carter wrote:
> 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;
To my mind the aspects should be introduced on a separate line so they
aren't lost. I had to review the declaration above a couple of times
before I realized the aspect was even there.
I favor indenting the aspect. Consider the common case where there are
multiple declarations at the same level
type X_Type is ...;
type Y_Type is ...;
procedure A(...);
function B(...) return ...;
If you slip an aspect in at the same level of indentation as the
declaration to which it is attached it clutters things considerably.
type X_Type is ...
with ...;
type Y_Type is ...
with ...;
procedure A(...)
with ...;
function B(...) return ...
with ...;
Of course adding some blank likes would help but I still like to see the
aspect set off so its association with the previous declaration is obvious
type X_Type is...
with ...;
type Y_Type is ...
with ...;
procedure A(...)
with ...;
function B(...) return ...
with ...;
Peter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indentation
2014-08-08 17:45 ` Indentation Peter Chapin
@ 2014-08-08 17:50 ` Peter Chapin
0 siblings, 0 replies; 7+ messages in thread
From: Peter Chapin @ 2014-08-08 17:50 UTC (permalink / raw)
On 2014-08-08 13:45, Peter Chapin wrote:
> I favor indenting the aspect. Consider the common case where there are
> multiple declarations at the same level...
I forgot to mention (sorry) that if the aspect's value is complex, such
as often the case for Pre, Post, and other assertions, it is normal for
the aspect itself to span multiple lines. Trying to put it on the same
line as the declaration is crazy in that case and not indenting it
doesn't work well either. Then, for consistency it seems natural to
treat all aspects the same way.
-- Division returns quotient and remainder.
procedure Divide (Dividend : in Very_Long;
Divisor : in Very_Long;
Quotient : out Very_Long;
Remainder : out Very_Long)
with
Depends => (Quotient => (Dividend, Divisor, Quotient),
Remainder => (Dividend, Divisor, Remainder)),
Pre => (not Is_Zero(Divisor)) and
(Divisor.Digit_Length = Remainder.Digit_Length) and
(Dividend.Digit_Length = Quotient.Digit_Length ) and
(Dividend.Digit_Length = 2*Divisor.Digit_Length);
Peter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indentation
2014-08-08 17:16 ` Indentation Jeffrey Carter
2014-08-08 17:45 ` Indentation Peter Chapin
@ 2014-08-08 22:51 ` Randy Brukardt
1 sibling, 0 replies; 7+ messages in thread
From: Randy Brukardt @ 2014-08-08 22:51 UTC (permalink / raw)
"Jeffrey Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message
news:ls30lf$cj2$2@dont-email.me...
...
> 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".
My understanding is that the Ada 9x team went through the entire standard
and regularized the indentation. (It's not really from Ada 80 anymore.)
Remember, they also switched to Title case identifiers (Ada 83 had them all
in UPPER CASE - yuck!). Since, we pretty much take it as given.
For aspects, we had a long and rather inconclusive discussion about how they
ought to be indented. The style shown in the RM is what we settled on, but
it wasn't close to unanimous.
The only indentation that I know I do differently than the RM is record
types (I think the RM inserts an extra level there for no reason).
Otherwise, I follow the RM style pretty closely (more closely as the years
go by).
Randy.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-08-08 22:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-08 16:12 Indentation Victor Porton
2014-08-08 16:32 ` Indentation Adam Beneschan
2014-08-08 17:16 ` Indentation Jeffrey Carter
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox