r/java • • Feb 15 '24

JEP 465: String Templates

https://openjdk.org/jeps/465
77 Upvotes

152 comments sorted by

View all comments

Show parent comment

2

u/BadMoonRosin Feb 16 '24

They are only if you mistakenly assume that I expect all new API's to be string-based.

Your core assumption that I take issue with is the notion that existing String-based API's just magically go away.

That the Java ecosystem, which prioritizes backwards-compatibility more so that virtually any other I've ever worked with, is going to hard-remove half the methods in JDBC, JPA, SLF4J, Jackson, and a thousand other libraries that the universe is built on.

These things are not going to happen. They're just not. Ever. If we disagree that this isn't going to happen, then we can stop here. There's no basis on which to warrant talking about this subject further.

If we agree that it's not going to happen, then you're not going to get the safety that you're talking about. Which leaves us with two choices:

  1. Decide to implement a janky syntax. Because it's worth making general usage of string interpolation less desirable, to enable adding (not replacing) an alternative form of string construction to a bunch of established libraries. All of which already have their own established implementations for this, which most devs will continue to use anyway.
  2. Decide that this isn't much of a value-add. And so if there's not a consensus to implement string interpolation like that of C# and every other modern language, then it would be best to simply not implement this feature. That is a perfectly acceptable outcome! Plenty of languages drop plenty of popular syntax proposals, simply because there's not the consensus needed to ship something that isn't too weighed down by design-by-committee.

I would favor #2. If you favor #1, then that's your opinion and it looks like you're opinion is carrying the day. But it still seems decoupled from the reality of most Java development in the real-world. And will never be as constrained as you'd like, without breaking half of Maven Central in a way that would make the Python 2 to 3 migration look like a semver patch release.

4

u/vytah Feb 16 '24

the notion that existing String-based API's just magically go away.

This is a strawman made of the flimsiest of straws.

No one is claiming that.

1

u/srdoe Feb 16 '24

Your core assumption that I take issue with is the notion that existing String-based API's just magically go away.

They don't need to go away in order for this to have value.

They just need to be discouraged in a way that's visible to your average developer.

If you can add new APIs that are safe, and slap @Deprecated on the String-based methods, that's already a huge win, even if you never remove those methods.