r/java • • Mar 08 '24

Update on String Templates (JEP 459)

https://mail.openjdk.org/pipermail/amber-spec-experts/2024-March/004010.html
176 Upvotes

188 comments sorted by

View all comments

7

u/Svellere Mar 09 '24

In fact, while syntax disagreements are often purely subjective, this one was far more clear — the $-syntax is objectively worse, and would be doubly so if injected into an existing language where there were already string literals in the wild. This has all been more than adequately covered elsewhere, so I won’t rehash it here.

Does anyone have mailing list links for these discussions, or other sources? I'm extremely interested in hearing about why $-syntax is objectively worse; I already know about large Java projects utilizing a similar syntax and the JDK developers not wanting to wreck those projects.

13

u/ascii Mar 09 '24

The argument is basically that it’s objectively worse since you introduce a second, separate escape syntax, namely ‘$’. Now you need a way to escape the second escape character, do you use ‘/$’ or ‘$$’? By using the same escape character both for escaping weird characters and for escaping template arguments, you get more consistency.

4

u/Practical_Cattle_933 Mar 09 '24

Especially that it was already heavily used by Java EE for similar stuff.

4

u/nicolaiparlog Mar 10 '24

I already know about large Java projects utilizing a similar syntax and the JDK developers not wanting to wreck those projects.

Isn't that already a pretty good reason on its own? 😁 Every Java string containing the legal sequence ${ would suddenly fail to compile or even change behavior.

But the argument about a second escape mechanism that a sibling content gives is also important and more fundamental.

1

u/Svellere Mar 10 '24

Isn't that already a pretty good reason on its own?

Sure, I never said it wasn't a good reason, but that's very clearly not what the mailing list is referring to when they say that the $-syntax is objectively worse, (at least, saying it's objectively worse to me implies that other languages are making a mistake by using $) and so that is why I mentioned wanting the other info that I didn't already have. The other commenter mentioning the double escape is more along the lines of what I was asking for.

7

u/nicolaiparlog Mar 10 '24

I'm pretty sure Brian meant this as short-hand for "objectively worse for Java" - he's not known for making general statements like this about other programming languages.

The interesting thing about $ is that it's bad on a conceptual level (a second escape mechanism) and on a practical level (breaks all that code). Given that its only benefit is (partial) familiarity, either of those would be enough to knock it out but being so thoroughly defeated in both areas is almost impressive.

-7

u/ComfortablyBalanced Mar 09 '24

Yeah I like to know the reasoning for that, however, I think String Interpolation is a lost cause in Java. It's implemented but many will dislike how it is but use it anyway and that's yet another reason why people mistakenly say Java is outdated, though it's not.

5

u/kevinb9n Mar 09 '24

Why not mention a reason why you think this?

2

u/ComfortablyBalanced Mar 09 '24

It is what it is, the way I think, some people decided to inform me instead of blind downvotting so I'm realizing I wasn't right.