6 ms·
It looks so bad in the context they give themselves: C# $"{x} plus {y} equals {x + y}" Visual Basic $"{x} plus {y} equals {x + y}" Python
by ryangs 3y ago
It looks so bad in the context they give themselves:
C# $"{x} plus {y} equals {x + y}"
Visual Basic $"{x} plus {y} equals {x + y}"
Python f"{x} plus {y} equals {x + y}"
Scala s"$x plus $y equals ${x + y}"
Groovy "$x plus $y equals ${x + y}"
Kotlin "$x plus $y equals ${x + y}"
JavaScript `${x} plus ${y} equals ${x + y}`
Ruby "#{x} plus #{y} equals #{x + y}"
Swift "\(x) plus \(y) equals \(x + y)"
And finally:
Java STR."\{x} plus \{y} equals \{x + y}"
- hibikir 3y agoIt's explained if you look at the proposals: They wanted to avoid any and all risks of backwards compatibility with any existing templating tool in the Java ecosystem. Every sensible syntax was covered by one of those, so the core language is stuck with the least bad one available.
- paulddraper 3y ago...at what cost tho
- capableweb 3y agoThe JEP makes it kind of clear: > trading off a small amount of convenience to gain a large amount of safety
- paulddraper 3y ago*large *small
- bcrosby95 3y agoYou can create json and sql string template processors that suffer from no injection problems. I'd call that a large improvement over, for example, Javascript. But I'm not familiar enough with the string template feature in the other languages to comment on their relative security.
- 5e92cb50239222b 3y agoThis is a solved problem in .NET, and C# only has one kind of string templating: FormattableString foo = $"select * from {table} where {column} = 42"; https://learn.microsoft.com/en-us/ef/core/querying/sql-queries#passing-parameters https://learn.microsoft.com/en-us/ef/core/querying/sql-queri...
- kaba0 3y agoNot sure if C# can do that, but java’s implementation can return an arbitrary object based on the templates/parameters.
- paulddraper 3y ago> You can create json and sql string template processors that suffer from no injection problems. I'd call that a large improvement over, for example, Javascript. Bad example. JavaScript literally has that (ever since ES6). [1] function sql(strings, ...args) { // ... } sql`SELECT * FROM user WHERE email = $1` [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- _old_dude_ 3y agoIt's prefixed by "STR." so the syntax is different from any existing tools ? It remember me the first proposed syntax for lambdas. Let's hope the next preview will fix that.
- deleted 3y ago[deleted]