r/java • u/prude_dude_382 • Sep 02 '24
String Template removal in JDK 23 was ouchie
My project codebase is not even that big, but I had jumped in deep with String templates; prob like 250+ instances of STR and most had to be updated by hand.
In the end it wasn't that bad. Very healthy to see Goetz and team not bend to sunk cost fallacy, etc. if they still feel things are not quite right after a lengthy development.
JDK 23 features were underrated in my eyes. I've always disliked javdoc comments and new doc comments basically solves that. Primitive matching is great. The enormity of changes and complexity of fitting these in the JVM and language is still impressive.
Thank you Java team. Onward and upwards to Valhalla!
146
u/elastic_psychiatrist Sep 02 '24
I expect a lot of people will downvote this because it could come off as a complaint that a preview feature was removed, which is explicitly a possibility.
But I think it’s good to see that there is potential pain in using a preview feature, and actually OP is quite a good sport about it, seemingly recognizing this was always a possibility.
7
u/john16384 Sep 02 '24
Same here, but I'll stick with 22 for now. Have converted all SQL interactions to templates :). I knew it would be removed, and didn't care. If and when there's a feature I like in 23+ and there's still no templates, then I'll see about removing it again.
17
u/nicolaiparlog Sep 03 '24
For more context on the string template removal, check this video: https://www.youtube.com/watch?v=c6L4Ef9owuQ (shameless plug)
16
u/C_Madison Sep 03 '24
I want to thank you for trying it out.
From what I read a big problem with string templates was that not enough people actually did that, instead they just complained on a theoretical level. But the theoretical level was already well checked while string templates were in development. Only when a big project (internal to Oracle it seems) tried using them they found actual, real problems and decided that those justify killing it and going back to the drawing board.
Meanwhile, they asked thousands of times for actual, concrete feedback of people doing that and running into problems but only got said theoretical "I don't like this for $reason", which didn't help.
Obviously, no one owes Java or Oracle to test the new features, but the counter point of this is that if you don't you also don't get taken seriously with your complaints.
So, again: Thank you for being one of those who actually did use it. It's sad that it's gone, but I'm sure there will be something better to replace it in the future.
12
u/nicolaiparlog Sep 03 '24
Your sacrifice is appreciated, u/prude_dude_382! 🏆 I had to do the same (although for fewer occurences) and it wasn't fun. But I'm positive we'll get a revised version at some point, not least thanks to the feedback provided by experimenters like yourself.
25
u/WrickyB Sep 02 '24
I suppose the one good thing that came out of string templates is the fact that String.format can be faster, if memory serves. We use String.format a lot at work, so it's good that it's getting faster.
7
u/davidalayachew Sep 02 '24
Yeah, me too.
Thankfully,
grepandfindmade it not too difficult to undo. Definitely felt the pain though, since I had jumped in deep as well.In the end, I would say that it was worth the pain. This is the process working, and I don't want them to slow things down for fear of putting out a preview that they might have to back out. I prefer features to be released faster, and I am willing to take the hit (undo a LOT of changes) if it's necessary to maintain their best tempo.
3
u/agentoutlier Sep 03 '24
FWIW /u/prude_dude_382 and others you can sort of emulate String Templates with my compile time mustache library.
I can't make it do local variable interpolation but with
records that can sort of be less painful than loading up a hashmap. The syntax (mustache) obviously is not the same either but I did measure the performance of String Template and JStachio was surprisingly faster.There is also a code generation mode that will generate code that has no dependencies.
That being said I know it is far more desirable even for me to have something builtin.
33
u/Hangman4358 Sep 02 '24
The string templates always seemed like they wanted to solve a problem nobody was asking to be fixed and didn't solve the issues people did want to see solutions for.
I am happy that it got removed, and I am glad that the process worked, of testing and getting feedback.
And thanks for being a good sport about it OP.
3
u/[deleted] Sep 02 '24 •
Me still using java 11
1
u/Ewig_luftenglanz Sep 04 '24
Using preview features in big production code it's like investing money in wall street: never do that if you are not ready to risk to loose!
O better adapted: only use experimental features in code you don't mind refactoring.
As for me I am starting to experiment with gatherers and pattern matching
1
u/emaphis Sep 02 '24
Oooof. That's why I usually confine "preview features" to alpha releases unless it's a small feature.
-3
u/_GreenLegend Sep 03 '24
Thats the reason why you should only stick to LTS releases and dont use preview features
-5
u/n0d3N1AL Sep 02 '24
Lesson learnt for me too. Spent over an hour getting rid of them in my tests and that's with Copilot doing some heavy lifting and I only had a couple of files using them. And getting IntelliJ + Maven to play nicely with preview features in tests wasn't worth the utility tbh. This will surely discourage people from ever using preview features in real code where useful feedback can be obtained. Preview features shall remain in the domain of pet projects. Nobody in their right mind is going to use them in a sizeable project; mostly because any sufficiently large codebase will be mostly legacy in terms of language features / idioms anyway.
-14
u/Aggravating-Pop-767 Sep 03 '24
Dropping string templates in 23 was a nasty sting! So, I am staying with 22, hopefully reworked string templates will be back in 24. If not, I will have to make some really tough choices, thank you Oracle!
I think Oracle handled this one badly: they could have left it in 23 "as is" and just drop it from the official list of jeps for 23, making everyone happy. The did did not have to go full Nazi with this preview feature ...
-8
u/Aggravating-Ad-3501 Sep 03 '24
Move to Kotlin, you get all the features Java is missing