Revisit the String template syntax

Tagir Valeev amaembo at
Sat Apr 15 07:48:14 UTC 2023

Hello,  Rémi!

> 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.

To me, this is actually an argument against ${}. With \{}, the users
will have a clear difference between language-supported interpolation
and external library interpolation. I can imagine that in some cases,
you may need to use both. For example, imagine that you are generating
build.xml or pom.xml and want to store strings containing ${...} as is
without interpolating right now, because they refer to the properties
defined in that file. However, you want to interpolate eagerly some
other parts of these strings using Java string interpolation.
Something like STR."${project.basedir}/build/\{generateTempDirName()}/".
You can easily combine two approaches with \{} escapes. It would be
much harder and much more error prone to create such templates if the
same syntax was used for both Java and external interpolation. I think
that distinguished interpolation syntax, which is rarely used in other
contexts, is actually an advantage. People will get used to it.

With best regards,
Tagir Valeev

More information about the amber-spec-experts mailing list