[raw-strings] Indentation problem

Guy Steele guy.steele at oracle.com
Mon Feb 5 17:31:43 UTC 2018


> On Feb 5, 2018, at 12:37 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
> 
>> But, wait!  We don’t even have to add that to Java, because we have a string concatenation operator, `+`:
> 
> For years, this was exactly my answer regarding "Why don't we have multi-line strings."  What turned me around was Jim convincing me that the problem was not the inability to express a multi-line string (which we've been able to do since day 1, as you point out), but the higher-level issue -- the accidental friction of embedding a (small) foreign document (JSON snippet, SQL snippet, etc) in a Java program without Java's string proclivities mangling the embedded document.  Multi-line is one aspect of this, but if this were all there was, I'd still be with you on "we already have this, let's move on."  The bigger aspect is intrusion on things like regexes (lots of double-escaping, since \ is used extensively by regex), which are not even multi-line, and the introduction of errors into embedded documents while trying to turn them into something the Java lexer will accept.
> 
> So, I prefer to think of this feature not as "multi-line strings" or even as "raw strings", but "embedded strings"; things that look like strings from the outside but look like whatever you want them to on the inside.

Good, that’s a better characterization of the broad problem.

However, I also note that the broad problem may two or three distinct symptoms, and:
(1) A solution that addresses one symptom may not address the others, and
(2) On the other hand, it may (or may not) be perfectly reason to address the most painful symptoms in different ways, rather than insisting that a single solution cover them all.

In particular, I happen to think that the problem of distinguishing snippet indentation from encoding-program indentation may require a rather different kind of solution from the problem of escape characters in embedded snippets.  The reason is that in both these cases the painful symptom is visual in nature rather than logical.  That’s why I can understand what drove Tagir to pursue the pipe-character approach (even though I think it may not be the best solution to the problem).  We may want to use ```…``` to enclose regexes but also want to use some other approach to solve the multi-line / indentation problems.



More information about the amber-spec-experts mailing list