Alignment algorithm (was: Wrapping up the first two courses)
Brian Goetz
brian.goetz at oracle.com
Tue Apr 23 14:57:24 UTC 2019
>> I think we should reconsider whether a non-blank first line means
>> that we should consider any indentation on the first line too. This
>> has the likely-beneficial side-effect that having a non-blank
>> character immediately following the """ effectively means "no
>> stripping."
>
> I would go the other way and say that any non-blank first line should
> mean no stripping at all. A non-blank first line will always have at
> least an extra three characters of indentation, so won't line up with
> the rest of the string. (Ignoring some questionable (ab)use of 4+ width
> tabs.)
This is worth considering — but as I’ve said before, this can’t be the only opt-out. One way to unify these is some sort of auto-stripped escape that does not count as whitespace.
> Non-empty first lines would still be useful as an opt-out. And I'd
> suggest a convention of using this opt-out by escaping the leading
> newline, thus making the first line effectively non-empty without
> messing up alignment in the source:
> `
> String s = """\
> line 1
> line 2
> """;
> `
I would prefer to treat \<newline> as an escape that means “eat the newline”, as it is in other languages, as in the example John posted last week. But in that interpretation, you get the same effect, because the above is equavlient to
> String s = """line 1
> line 2
> """;
Or maybe that’s what you were suggesting?
More information about the amber-spec-experts
mailing list