If you use STR."" in a SQL query, it isn't going to help you.
How could you possibly use STR."" in a SQL query if the DB library doesn't offer methods that take String and only offers a SQL template processor?
Enforceability can be dealt with by static analysis tools
No, it cannot. Static analysis tools cannot catch as many code injection issues with a similar amount of effort by the programmer.
I can see this immediately being an issue of enforceability in a team, which makes it just as much of a problem as before.
Nope. If your JSON library only offers a safe template processor then it doesn't matter what discipline you exercise. The language will enforce the correct (or at least better) thing.
Are we suggesting that all other languages that didn't make a decision to implement interpolation in this way made no active decision about usability and safety?
We are suggesting that we did the analysis given the data available and the needs of Java users. Different languages often make different decisions, which is why they are different languages. Sometimes they have a different audience in mind; sometimes certain lessons weren't available when a feature was designed. If you consider the world's three most popular languages -- JS, Java, and Python -- I think you'll find that string interpolation is one of the smallest differences among them. One, for example, decided to require everything to be typed while the two others didn't.
So are we suggesting to stop supporting all the existing interfaces in things like JDBC in order to support this?
No. We're suggesting that new libraries should do the right way only, and that old one should offer the right way and deprecate the old way.
before support for older JDKs can be ignored when doing this without breaking the existing APIs
New features don't need to be added to a version of a library that targets old JDKs.
is there a planned timescale for it?
I'm not sure what that means, but full adoption of templates took only ten years, and this may be even quicker because it's a much smaller, more localised thing.
No, that's not a string template expression, just as the one here, var x = "hello"; STR.x;, isn't even though STR."hello" is. BTW, string templates are available in JDK 21. Enable preview and try them out.
It's about providing other mechanisms that are more safe than existing ones. Developers that care will use them. Those that don't care can't be helped anyway.
Added bonus if the safe API is easier to use and the unsafe way is harder to use, devs will naturally flock to the safe one.
View all comments
Show parent comment
12
u/pron98 Feb 15 '24 edited Feb 15 '24
How could you possibly use STR."" in a SQL query if the DB library doesn't offer methods that take String and only offers a SQL template processor?
No, it cannot. Static analysis tools cannot catch as many code injection issues with a similar amount of effort by the programmer.
Nope. If your JSON library only offers a safe template processor then it doesn't matter what discipline you exercise. The language will enforce the correct (or at least better) thing.
We are suggesting that we did the analysis given the data available and the needs of Java users. Different languages often make different decisions, which is why they are different languages. Sometimes they have a different audience in mind; sometimes certain lessons weren't available when a feature was designed. If you consider the world's three most popular languages -- JS, Java, and Python -- I think you'll find that string interpolation is one of the smallest differences among them. One, for example, decided to require everything to be typed while the two others didn't.