Revisit the String template syntax
Guy Steele
guy.steele at oracle.com
Wed Apr 12 16:38:13 UTC 2023
> On Apr 12, 2023, at 12:21 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>
> The backslash syntax is objectively better than the dollar-sign syntax, which is why we selected it in the first place. Reasons included:
>
> - Today, “${name}” is a valid string literal, whereas “\{name}” is not.
This point is worth expanding on:. It is important to consider not only the effort of writing new code, but also the effort of maintaining and extending old code.
With the introduction of string templates, we can expect a fairly common activity to be the modification of an existing string literal to become a string template.
Under the current design, this requires doing two things:
(1) Add “STR.” to the front of the string literal.
(2) Add “\{expression}” in various places.
Using the dollar-sign syntax would require three steps:
(1) Add “STR.” to the front of the string literal.
(2) Add “\{expression}” in various places.
(3) Check the_entire string literal_ for occurrences of “$” and perhaps replace with "\$”.
I don’t think it’s worth it just to make Java look a little bit more like JavaScript (and a little bit less like Java).
—Guy
More information about the amber-spec-experts
mailing list