4 ms·
Java: String info = STR."My name is \{name}"; Scala: val info = s"My name is $name" Why does Java ALWAYS use unnecessary verbosity? I don’t get it.
by cbeach 4y ago
Java:
String info = STR."My name is \{name}";
Scala:
val info = s"My name is $name"
Why does Java ALWAYS use unnecessary verbosity? I don’t get it. They’ve had years to learn from succinct languages.
- crummy 4y agoBackwards compatibility?
- rossjudson 4y agoI think you mean Java: var info = STR."My price is $\{price}_"; Scala: val info = s"My price is $$${price}_"
- jillesvangurp 4y agoKotlin: val info = "My name is $name" All strings are templatable in Kotlin. No need to have different types of syntax for that. What purpose does this s or STR. prefix serve serve? Seems completely redundant to me to have that.
- MrBuddyCasino 4y agoIt helps to actually read the article. There will be multiple template processors, not just one. This proposal goes beyond simple string interpolation and adds security measures against injection attacks. I'm mostly developing in Kotlin btw., but usually when Java introduces its take on a feature that has existed for a while in other languages, they improve on it. One such example: handling whitespace/indentation in multi-line strings in Kotlin vs Java. In Kotlin you usually have to call .trimIndent(), in Java the defaults are sane so you don't have to.
- jillesvangurp 4y agoThe article in this case is a longish specification. I skimmed through it. It looks over engineered to me. That's my honest first impression. A dead give away for that is that it needs a longish specification. And I indeed missed the bit about a pluggable template engine. Just one question related to that: why? I don't see the big use case for this. Maybe a bit less flexibility and a more sane syntax would be better?