News for hackers. Stuff that matters.

mhosain

Re:Java String Interpolation final in Java 23 on Saturday January 13, 2024 @12:18PM (#38982073)
> Also, I think you may have misunderstood what this feature...

No, I am aware of the differences between StringBuilder and string templating. One of the most common usage is concatenation (e.g. toString() methods). Sometimes it's cleaner to use StringBuilder instead of + operator to do that. And templating will be mostly used for concatenation.

All I am saying is, it could be simpler. I read the full JEP before my first comment. I frequently do Python and did little bit of Kotlin before. I guess that's where all this is coming from.

Re:Java String Interpolation final in Java 23 on Saturday January 13, 2024 @10:04AM (#38980568)
Yeah, but than what was the point? We could've continue to use existing methods.

The goal was getting something clean and friendly. Look at Python for example. Any similar solution would have made it both non-breaking (codes won't compile with unsupported version) and clean.

Re:Java String Interpolation final in Java 23 on Saturday January 13, 2024 @09:56AM (#38980486)
> STR is not a prefix but simply the name of the variable referencing the receiver

That is THE problem. You can use StringBuilder more easily than this ugly thing. When you write code in IDE (I hope so), writing `.append()` is actually easier than this `\{}` dreadful thing.

> It is being escaped, and so reading it as being escaped is the correct and intended understanding. Just like `\n` or `\t`, `\{` means that the next character has a special meaning, as it always does in Java. There was no need to introduce yet another escape sequence; the old one works just fine.

But what about the `}` after the expression? Who/what is escaping that? It should make it clear that this is a special syntax that does some special things. `\` is sort of universal escape character. Putting it in here feels wrong. Again, that's me (along with some other), and you definitely can disagree.

Re:Java String Interpolation final in Java 23 on Saturday January 13, 2024 @09:03AM (#38979978)
No, absolutely not! This will be the most hated Java feature to me.
Re:Java String Interpolation final in Java 23 on Saturday January 13, 2024 @09:02AM (#38979964)
Sadly, true. Why is the template processor named `STR`, why not `f"String"`, like Python? On top of the ugly `STR.` prefix, this dreaded `\` character infuriates me more. Kotlin and Groovy have the nicest implementation by far because it doesn't require any prefixes. I understand Java can't suddenly do that because it needs to be backward-compatible.

I can't get over the ugly `\{someVar}`. It will be easily confused as the `{` character is being escaped, rather than a template. `${someVar}` was a much better option.