----- Original Message -----
> From: "Guy Steele" <[email protected]>
> To: "Brian Goetz" <[email protected]>
> Cc: "Remi Forax" <[email protected]>, "amber-spec-experts" 
> <[email protected]>
> Sent: Wednesday, April 12, 2023 6:38:13 PM
> Subject: Re: Revisit the String template syntax

>> On Apr 12, 2023, at 12:21 PM, Brian Goetz <[email protected]> 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).

JavaScript is a user of the ${} syntax but it's a fairly recent addition.

In Java, Maven, Gradle through their lineage to Apache Ant, in fact, all 
projects using the apache common-text StringSubstitutor (or the much older 
StrSubstitutor) are using the ${} syntax since a very long time. All Java 
developers are familiar with this syntax for string interpolation.

So for a lot of Java developers, the syntax \{} feels alien to Java in 
comparison. So yes, you have to escape the $ sign, you have to tweak the lexer 
but, in my opinion, it's a case where familiarity in the whole ecosystem trumps 
local rationalization.

> 
> —Guy

Rémi

Reply via email to