Fwd: Raw string literals -- restarting the discussion

Brian Goetz brian.goetz at oracle.com
Mon Jan 7 16:09:53 UTC 2019


This was received on amber-spec-comments.  

> From: elias vasylenko <eliasvasylenko at gmail.com>
> Subject: Re: Raw string literals -- restarting the discussion
> Date: January 7, 2019 at 8:10:57 AM EST
> To: amber-spec-comments at openjdk.java.net
> 
>> At first blush, the simplicity of the Rust approach is attractive; just
> let strings span multiple lines, with no new syntax.  The obvious
> counter-arguments are pretty weak in the current age; if you code in IDE,
> as most developers do, it is not easy to accidentally leave off a closing
> quote, and the syntax highlighting will make this obvious in the event we
> do so anyway.  But, if we look through the lens of our use cases -- such as
> JSON snippets -- we see that this approach fails almost completely, because
> you _still_ have to escape the quotes, and almost all multi-line snippets
> will have quotes.  So, let's cross this off too.  The same applies to using
> a letter prefix for multi-line strings; it doesn't address the primary use
> case.
> 
> I'm a little confused about the argument to cross this off. Is this not
> dismissing a solution to the multi-line string problem on the basis that it
> doesn't also solve the raw string problem? Within the exploration of raw
> strings and multi-line strings as separate features I think this reasoning
> bears a little extra scrutiny.
> 
> Contrast, for example, using triple quote for multi-line and `r` prefix for
> raw:
> 
>    var s1 = """
>      <xml>
>        <example />
>      </xml>
>    """;
> 
>    var s2 = """
>      {
>        "json" : "example"
>      }
>    """;
> 
>    var s3 = r"""
>      {
>        "quote" : "\"",
>        "backslash" : "\\"
>      }
>    """;
> 
> I don't see what the triple quotes buy us over single quotes other than
> that they also serve the secondary purpose of a sort of poor-man's raw
> string. Is that really worth the extra inconsistency given that we also
> wish to have *actual* raw strings? I'd argue that the requirement for
> unescaped quotes falls more naturally within the scope of the raw string
> feature than the multi-line string feature:
> 
>    var s1 = "
>      <xml>
>        <example />
>      </xml>
>    ";
> 
>    var s2 = \"
>      {
>        "json" : "example"
>      }
>    "\;
> 
>    // or with a variable-length component to the delimiter...
>    var s3 = \\\"
>      {
>        "quote" : "\"",
>        "backslash" : "\\"
>      }
>    "\\\;
> 
> The \""\ syntax is just an example, the above arguments can equally be
> applied to e.g. the \+ \- proposal.
> 
> That said I think there's also a minor danger of implying some sort of
> distinction between nonce-based delimiters and variable-length delimiters
> which doesn't necessarily exist. Isn't the latter just an example of the
> former but with a restricted format? Surely the reason the nonce-based
> approaches and e.g. the Rust approach avoid most of the edge cases suffered
> by the original backtick proposal is that the delimiters have both a
> variable portion *and* a single inner character.
> 
> On Wed, 2 Jan 2019 at 18:22, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
>> As many of you saw, we pulled back the Raw String Literals feature from
>> JDK 12.  The public statement is here:



More information about the amber-dev mailing list