News for hackers. Stuff that matters.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by pron on Friday March 03, 2023 @04:55PM (#35015584)
Java's syntax is just as friendly and simple -- see my other comments on the subject -- it just requires the receiver to define a policy, which is essential for security. You only need to use STR when the receiver does not define a template processor and works with strings. I have no idea what Python's or JS's security experts advised, but that code injection is one of the most common vulnerabilities in memory-safe languages is a fact reported by all security advisories. String interpolation is one of the most dangerous features a language can have.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by Kwpolska on Friday March 03, 2023 @05:27PM (#35015889)
I’m not a fan of the special `log.info."x: \{x}";` syntax, it looks like a weird mix of field access and a string literal.

And even with the fancy new syntax, I’m sure there will be people passing STR."SELECT * FROM x WHERE y = \{y}" to their database. You can educate people all you want, but not all developers will read the docs telling them this is dangerous. Even if all the docs do the right thing, people might end up reading old tutorials, and will then notice the “inefficiency” of the prepared statement syntax and will just do a STR."" format. Or they might consider the database.executeQuery."SELECT \{x}"; syntax “invalid” and try to fix it.

Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by pron on Friday March 03, 2023 @06:41PM (#35016500)
Well, you know, even thirty years of experience as the custodians of one of the most successful programming languages is no guarantee of success with every feature, but that's why we have the preview process now that lets us figure out what problems people actually encounter -- which may well be different from the problems they, or we, think they would encounter -- before finalising the feature.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by avgcorrection on Saturday March 04, 2023 @08:33AM (#35020649)
If I had a cent for every time pron appealed to Java’s age and “popularity” in technical arguments, I would have at least enough cents to use a dollar-sign in string template syntax.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by pron on Saturday March 04, 2023 @08:51AM (#35020741)
That's cute, but that appeal is crucial because technical arguments that are divorced from empirical results in the field are a great way to spend a lot of time solving the wrong problems. For example, you can make technical arguments in favour of either VHS or Betamax, but while they both had superior solutions to two separate problems, one of those problems (recording time) ended up being a much more important problem for more people than the other. The purpose of engineering is not to enjoy intellectual puzzles, but to solve problems for people. If you insist that the team that does better than other teams, over and over for a few decades, is doing it all wrong, it's possible that what you consider to be right and wrong doesn't really fit with what's happening in the field.

The relatively new concept of preview features helps us do exactly that: gather information on what problems people actually encounter when working with a new feature as opposed to what problems some speculate they'll run into. The best way to influence Java's direction is not to speculate, but to report problems you've actually encountered to the relevant OpenJDK mailing list (amber-dev in this case). If the use of the \ or $ character actually turns out to be a real problem, we expect to find that out during the preview process (which will begin in JDK 21, out this September) and we'll reconsider, only we'll do it based on reports, not speculation.

Engineering is first and foremost about identifying what bigger problems more people actually need solving. Those who misunderstand that will forever be puzzled by why it is that the VHSes usually win over the Betamaxes and will continue betting on the wrong horses.

Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by avgcorrection on Saturday March 04, 2023 @11:07AM (#35021818)
Well, I’ll agree that one shouldn’t be naive about the “technically superior” arguments. One has to look at why certain things succeeded. In an honest and non-ideological way (e.g. don’t blind yourself on the “technically superior” talking points, whatever that means).

I don’t really have a problem with a backslash over a dollar-sign. I just couldn’t resist...

Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by optician_owl on Saturday March 04, 2023 @02:00AM (#35018852)
I would argue that jdbc API is far more dangerous than string interpolation :)

But I wholeheartedly support the idea of JEP. Scala got several good UX benefits based on the string interpolation (sql and logging).

Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by zelphirkalt on Saturday March 04, 2023 @04:54AM (#35019652)
When I want to write a query, I will use a prepared statement or read the docs of a library I am using to interact with a database, whether that library automatically creates a prepared statement. If I use a prepared statement and later read that code, I never again have to ask myself, whether it is safe. Quite frankly, who does not know about injection and prepared statements should not work with databases.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by Kwpolska on Saturday March 04, 2023 @06:03PM (#35025394)
Beginners tend to shoot themselves in the foot fairly often.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by yxhuvud on Saturday March 04, 2023 @08:37AM (#35020679)
Isn't that better solved by not allowing templates to be passed around and blanks filled in later but instead force them to be executed immediately? This is the case in Ruby and while there have been plenty cases of code injection, I've never seen one using the basic string interpolation to do that.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by pron on Saturday March 04, 2023 @10:26AM (#35021456)
It's not a better solution but one part of this solution (which also requires templates to originate in the program rather than as input by requiring literals). The rest is done to ensure proper, context-specific quoting/escaping for machine-interpretable constructs, such as JSON and SQL.

As to the dangers of simple string interpolation, here's a warning against using C#'s string interpolation in favour of a safer C# construct: https://bengribaudo.com/blog/2021/04/13/5596/intercepting-st...

We want to make the safe choice the easiest choice, and certainly not the trickier choice. We do that by adding a small tax to the dangerous choice -- i.e. string interpolation. When this feature previews we'll know more about how well this works and can then adjust based on people's actual experience.