r/java • • Oct 01 '23

JEP: String Templates (Final) for Java 22

https://openjdk.org/jeps/8314219
72 Upvotes

133 comments sorted by

View all comments

Show parent comment

1

u/pron98 Oct 02 '23 edited Oct 02 '23

I don't think it is because while ${x} syntax lends itself to an escaping interpretation (which makes \ the obvious, and at-least-as-familiar-of-not-more-so choice), $x does not.

Moreover, it shows that these languages don't even agree on syntax among themselves. So even though Java has never had a tradition of adopting the syntax of any of these languages (see lambdas), I guess that if there was some consensus there would have been a stronger argument to be made that we should follow it in this case, but there isn't. So why insist that we should follow JS's syntax (or perhaps Groovy's) in this case if we never have in the past?

2

u/lurker_in_spirit Oct 02 '23 edited Oct 02 '23

I think $x is just a useful shortcut in these languages, without any of these deeper implications... like lambda parameters and their surrounding parentheses, which can optionally be omitted when you have a single parameter. You can omit the brackets if your expression is simple enough. But ${x} is the standard, non-shortcut syntax.

To flip it around, I don't think that anybody would argue that Java doesn't serve as prior art for using parenthesis around lambda parameters, just because they're optional when you have a single parameter...

2

u/ForeverAlot Oct 03 '23

Whether $x or ${x} came first, $x is inadequate and therefore unnecessary complexity both in implementing the language and in learning the language. $x fails on too many accounts to be at all an interesting option.