Wrapping up the first two courses
daniel.smith at oracle.com
Fri May 10 23:39:48 UTC 2019
> On May 10, 2019, at 3:04 PM, Dan Smith <daniel.smith at oracle.com> wrote:
> Practically, the programming style I would want to use is Jim's example (h):
> String h = """+--------+
> | text |
Thinking about this a bit more, I could also be happy uniformly adopting example (a):
String a = """
| text |
Or, where needed, (e):
String e =
| text |
I think the key to this style for me is to stop thinking about this as a "string literal with newlines" and start thinking about it as a different entity. (Which is a good argument for fat delimiters.)
> As a pretty-simple definition of the 2D rectangle, I'd be happy with "all columns to the right of the opening delimiter, on all lines until the closing delimiter". Indents in between must use whitespace to align with the opening delimiter; if they don't, that's a parse error.
> I realize that some people prefer a different style, and that this story is complicated by tab characters and variable-width fonts. So maybe there's another rule (or two) for the 2D rectangle when the first line is blank, based on the placement of the closing delimiter, or based on the leftmost non-whitespace character. But my high-level point is that I'd rather not force the algorithm to be defined on a context-free String.
Reframing this to support things like (a) and (e), but still take context into account, I really think we could cut down on the degrees of freedom significantly, and just say this: the left margin of the rectangle aligns with the left side of the opening or closing delimiter, whichever is leftmost*; the top of the rectangle is the line after the opening delimiter. All indents must match the leftmost delimiter's prefix (where non-whitespace prefix text is replaced with spaces), and the line after the opening delimiter must be blank.
This is a very opinionated rule: the space to the left of the leftmost delimiter is simply off-limits. And any indentation to the right of the leftmost delimiter is preserved. That's just How It's Done. If you need a different left margin, move your delimiters (e.g., add a newline, like (e)). I think programmers would appreciate a simple, strict, easy-to-see rule, rather than a best-effort trimming algorithm.
(* I'd almost be willing to say that the opening delimiter always determines the indent, but I'm backing off for tab-lovers who won't like how prefix text gets replaced with spaces; though maybe tab-lovers will want to keep things tidy with a newline before the opening delimiter. Anyway, in most cases the opening and closing delimiter will start in the same column.)
More information about the amber-spec-observers