[Grace-core] Indentation (After Teleconference)

Michael Homer mwh at ecs.vuw.ac.nz
Fri Feb 20 12:19:22 PST 2015


On Sat, Feb 21, 2015 at 7:22 AM, Andrew P Black
<andrew.p.black at gmail.com> wrote:
>
> On 16 Feb 2015, at 19:02 , Michael Homer <mwh at ecs.vuw.ac.nz> wrote:
>
>> On Tue, Feb 17, 2015 at 1:06 PM, Andrew P Black <black at cs.pdx.edu> wrote:
>>> We discussed this on Monday 16th February 2015
>>>
>>> On 16 Feb 2015, at 14:47 , Andrew P Black <black at cs.pdx.edu> wrote:
>>>
>>> Indentation Questions
>>>
>>> Q0  Do we care where closing braces go?
>>>
>>> Do they always have to align with the indentation of the line that opened
>>> the brace, or do we allow them anywhere?
>>>
>>>
>>> Our conclusion
>>>
>>> If a closing brace is on a line by itself, then it must be at the same
>>> indentation as the line that opened the braced-construct.
>>> However, if a brace is on a line with other stuff, then it can fall
>>> anywhere.
>> Note that this is a reversal of the previous decision which I think
>> made it into the specification somewhere (or maybe it was a paper).
>
>
> This is very Interesting.  Which part of the statement is a "reversal"?    Can you tell us where the contrary
> description is?  I don't believe that it's in the spec, because I searched there before asking these questions.
> Mor importantly, do you believe that the "previous decision" was a better decision?   If not, then I guess that
> it doesn't matter, and we can stick with what we decided on Monday.
The previous decision was that closing braces must appear at the start
of the line at the indentation level to which they return, and could
not follow each other or other code. The stated motivation was that
the language should enforce good style, and that supporting poor
structure in the language for the sake of fitting code into papers was
undesirable. They are different; I don't know if one of them is
better.
>>> Q1 Indentation of continuation lines
>>>
>>> Suppose we have a continuation line:
>>>
>>>         (X + y).
>>>                  foo {
>>>
>>> where does the next line (the body of the block) go?  It has to be indented,
>>> because of the '{', but to the right of what?   The '(' on line 1 (because
>>> it's the indentation of the logical line that the block contents has to be
>>> to the right of)?   Or the 'f' on line 2 (because thats the line where the
>>> block opened?
>>>
>>> Does the first rule make
>>>
>>>         (X + yVeryLong).
>>>                  foo {
>>>                  if (b) then {
>>>                           ...
>>>                  } else {
>>>                           ...
>>>                  }
>>>
>>> legal?  I think that the above is visually confusing.  Do we want the
>>> student to write
>>>
>>>         (X + yVeryLong).
>>>                           foo {
>>>                  if (b) then {
>>>                           ...
>>>                  } else {
>>>                           ...
>>>                  }
>>>
>>> or
>>>
>>>
>>>         (X + yVeryLong).
>>>                  foo {
>>>                           if (b) then {
>>>                                    ...
>>>                           } else {
>>>                           ...
>>>                           }
>>>
>>> ?
>>>
>>>
>>> Answer: We prefer the second form, since it distinguishes the "continuation
>>> line indent" from the "new block indent".   The proposed rule is:
>>> When a line is been continued with one or more indented continuation lines,
>>> the indentation of all of the continuations must be the same, and the
>>> indentation of the first line that is NOT part of the continuation must be
>>> less.
>> Here is a piece of real code:
>>        while {accept("op")onLineOfLastOr(statementToken).andAlso
>>                {sym.value != "="}} do {
>>            opcount := opcount + 1
>>            ...
>>        }
>> Should that be permitted or not (ignoring whether it's encouraged for
>> the moment)? It is the conventional layout for most other languages,
>> but those also don't have any semantics attached to their layout.
>> Should it result in an error?
>
> Why are you asking this?  Do  you believe that this breaks one of the rules that we are discussing here?
> It seems to me to conform to both the rule about closing braces on the same line as other stuff being allowed anywhere,
> and to the rule about the indentation of continuation lines.
I was asking because I wanted to know the answer.
-Michael


More information about the Grace-core mailing list