What Happened to Java's String Templates? Inside Java Newscast #71

  Рет қаралды 20,795

Java

Java

Күн бұрын

Пікірлер: 201
@rodjenihm
@rodjenihm 3 ай бұрын
"Damn. " + "I was very excited about string templates. "
@shadeblackwolf1508
@shadeblackwolf1508 3 ай бұрын
var pronoun = me; println(pronoun + " too");
@edmaphis9805
@edmaphis9805 3 ай бұрын
@@shadeblackwolf1508 var timeline = "soon"; str("Hopefully, we get them /{timeline}");
@djgredler
@djgredler 3 ай бұрын
"String s = String.interpolate(`text \{variable}`)" is not enterprisey enough. We need a few more levels of abstraction, like a StringFactory and a StringFactoryLocator.
@nipafx
@nipafx 3 ай бұрын
Good point, will forward to Project AmberFactoryLocator!
@diegoshevek5927
@diegoshevek5927 3 ай бұрын
Look out for the DevelopersResponsibility class, it has a lot of functionality concerning our own responsibility as developers to stand our ground on what we consider to be good practices for our work, despite the gibberish and bureaucratic old ways of doing things in big companies.
@guai9632
@guai9632 3 ай бұрын
StringTemplateFactoryLocatorDelegateSupplier
@lapissea1190
@lapissea1190 3 ай бұрын
I'm just gonna say it, if it's long and unwieldy to use (aka worse than str.) then people will tend not to use it, regardless if it's secure or not
@scarletdice
@scarletdice 3 ай бұрын
*sneeze* module *sneeze*
@nipafx
@nipafx 3 ай бұрын
I agree and that's the challenge here: Finding a way to structure the feature, so it ends up being safer _and_ more usable than concatenation.
@lapissea1190
@lapissea1190 3 ай бұрын
Yeeah. I personally liked "STR." when it comes to actually typing/reading it but maybe there is some other solution. Maybe there is something worth in consistency with number type notation? (so 10L)
@prdoyle
@prdoyle 3 ай бұрын
He covers that point in the video.
@tranceyy
@tranceyy 3 ай бұрын
Just take ideas from the almighty C#, it's so elegant.
@flatmapper
@flatmapper 3 ай бұрын
I will die faster than Java will be like a convinient language
@StrangerNoises
@StrangerNoises 3 ай бұрын
if another reason for string templates was because String::format was so inefficient, but the reason they thought they needed string templates to be that way was for the efficiency, but that was later shown to be wrong... has anyone thought about just making String::format more efficient using that learned lesson while we're about it? 🙂
@nipafx
@nipafx 3 ай бұрын
I wondered about that, too. Will try to find out.
@mortillan2196
@mortillan2196 3 ай бұрын
+1 to this. This way string template can take all the time it needs but the community using latest java will benefit on optimization of String::format
@nipafx
@nipafx 3 ай бұрын
I looked into this. It turns out, the FMT implementation borrowed much of its code from the explorations for JEP 348 (openjdk.org/jeps/348), which explicitly mentions `String::format`. So there is a JEP tracking this. I don't know what that means for the near future, though. Will JEP 348 move forward to prove that processors really aren't necessary before string templates progress? Or is this already established to the point where both JEPs can move on independently? Will `String::format` have to wait for its optimization through JEP 348 or can/will it be special-cased before that? Your guesses are as good as mine...
@briangoetz7591
@briangoetz7591 3 ай бұрын
As a general rule, you should assume the answer to any question of the form "has anyone thought of..." is "yes". In fact, the StringTemplate feature _grew out of_ experiments to optimize String::format.
@onebeartoe
@onebeartoe 3 ай бұрын
I am glad to see Java feature experimentation in the open for developers to see. It is also good to see that the JEP process allows for change, while the enhancement is still being developed.
@prdoyle
@prdoyle 3 ай бұрын
Yep, exactly. I'm disappointed to see templates disappear, but this process has brought us a lot of goodies over the last few years, so they've earned the benefit of the doubt. :)
@RajaRaviVarman
@RajaRaviVarman 3 ай бұрын
Aside Javascript, most DSLs today use ${}. So it is a familiar notation in devops today and introducing another notation for string template is just bad.
@HarisOsmanagic
@HarisOsmanagic 2 ай бұрын
Agreed, but at times we also need to re-think those decision and not stick to conventions that prove to be bad.
@khmarbaise
@khmarbaise 3 ай бұрын
Really good video spiced with some humor. Very good summarization about the preview feature idea and very detailed information about the why etc. about String Templates. Great.
@zombi1034
@zombi1034 3 ай бұрын
public static String f(StringTemplate t) { return String.interpolate(t); } var muchBetter = f(`Hello \{world}`);
@fabianmerki4222
@fabianmerki4222 3 ай бұрын
and add a replace all ${ to \{
@TheBigLou13
@TheBigLou13 3 ай бұрын
Thank you for the care of making it thought-through, well and consistent with all of Java!
@prdoyle
@prdoyle 3 ай бұрын
I, for one, liked the old proposal as it was. Backslash-curly was an elegant solution (preference for $ seems irrational to me) and the STR."" syntax was concise and clear. But this JEP process has brought a lot of amazing improvements to Java so I trust the process and I'm excited to see where it lands.
@nipafx
@nipafx 3 ай бұрын
I agree with your entire statement. 💯
@samfromuk796
@samfromuk796 3 ай бұрын
Why is ${} irrational? It's used in Bash scripts a lot and it's in Groovy.
@nipafx
@nipafx 3 ай бұрын
@@samfromuk796 See 7:35. First: That a feature and particularly a specific syntax works well in one language doesn't mean that it works well in another one. Second: More than that, it may not even be optimal in that language - designers do make mistakes, after all. 😉
@nO_d3N1AL
@nO_d3N1AL 2 ай бұрын
@@samfromuk796Backwards compatibility
@prdoyle
@prdoyle Ай бұрын
@@samfromuk796 ${} has backward compatibility problems that \{} does not. It is objectively worse for this application.
@brandpcalderon5343
@brandpcalderon5343 3 ай бұрын
I don't use String Templates that much, but why don't copy the C# string interpolation, $"{my_var}" it looks kinda elegant ($ it's more elegant than \ ), so when applying the $ symbol before the quotes, it scapes the bracket caracter { , that'd be my solution.
@nipafx
@nipafx 3 ай бұрын
The mailing list discussion indeed considers marking string templates with a sigil like `$`, e.g. `StringTemplate t = $"text \{variable}"`. But if any `{...}` section would then be interpreted as an expression, you'd still have to escape any curly brace you want to show up as is. And when you turn a `StringTemplate` back into a `String` while refactoring, you have to undo all those escape. This conceptual load seems unnecessary - just use `\{...}` for expressions and there's never any unnecessary (un)escaping.
@neonmidnight6264
@neonmidnight6264 3 ай бұрын
What's more, Roslyn can lower interpolated string expressions to special calls to a "handler" builder type, which lets you write `dbSet.FromSql($"SELECT * FROM users WHERE id = {id}")` without ever risking SQL injection - the handler handles this behind the scenes to parametrize the query and escape the parameter.
@nipafx
@nipafx 3 ай бұрын
@@neonmidnight6264 In the example you gave, how's the '"handler" builder type' selected?
@vytah
@vytah 3 ай бұрын
@@nipafx It's target typing, the same thing it does in LINQ with expression trees. If the target of a string template is of type FormattedString, it's passed in uninterpolated. I think the original goal was to avoid making temporary strings when logging or printing, but it can have other uses as well. FormattedString is almost like StringTemplate in Java, except it does not have a list of text chunks, it has a string that matches what you would pass to String.Format, so your processor has to parse it itself.
@nipafx
@nipafx 3 ай бұрын
@@vytah So, in Java terms, I could call a method that takes a java,sql.Statement but pass a StringTemplate and then the runtime goes looking for a StringTemplate~>Statement converter?
@eloy4
@eloy4 3 ай бұрын
I'm hearing a lot of "forget about it". The Java community will not be happy. I personally enjoy JS String interpolation with backticks, it feels so easy. Such a pitty. I hope it works out in the end.
@DmitryPolovka
@DmitryPolovka 8 күн бұрын
My guy used every single place inside his apartment to film 😅
@nipafx
@nipafx 7 күн бұрын
Technically, the hallway was left unrecorded, but it has terrible lighting. :D
@mrkostya008
@mrkostya008 3 ай бұрын
I don't understand what's the issue of just copying it from JS. `Look, ${name}, doesn't this look just better`? And if you ever need to sanitize the input as with SQL queries you can just make the `` strings be a different class that inherits from String and has some additional functionality attached to it where you can access the interpolated strings, it would be both OOP-like and clean for developers.
@nipafx
@nipafx 3 ай бұрын
String is final and for a million reasons (not least of which is performance), it absolutely needs to remain that.
@yuriblanc8446
@yuriblanc8446 3 ай бұрын
StringInterpolatorFactory(new StringTemplate(new Thread()).interpolate(new StringExpression("/{value}"), new StringTemplateParams()).build().toString(). That's how to make it entetprisely.
@nipafx
@nipafx 3 ай бұрын
😂
@srki22
@srki22 3 ай бұрын
You sound like you are a bit under the weather, take a sick day and take care of yourself.
@nipafx
@nipafx 3 ай бұрын
I will, thank you. :)
@DavidRosario69
@DavidRosario69 3 ай бұрын
JavaScript may be the only CURRENT top ten Tiobe language to use ${}, but there are plenty of us who write bash scripts, some who use Groovy directly or indirectly (e.g. Gradle), and some poor, unfortunate folks who use PHP. For better or worse, PHP was a top 10 language.
@VonCarlsson
@VonCarlsson 3 ай бұрын
Not to mention the second and third most used JVM languages: Kotlin and Scala. They sure go out of their way to avoid recognizing their existence...
@dmitriimoldavanov4701
@dmitriimoldavanov4701 3 ай бұрын
Two toothbrushes! Girls! This one taken 🎉
@sergios6794
@sergios6794 3 ай бұрын
If at the end String Templates couldn't be added at all, I think at least the interpolation can stay. Since, as mentioned, the \ is a escape char, it woudn't break anything if you just add interpolations to normal strings like String str = "\{myVar}";
@nipafx
@nipafx 3 ай бұрын
I think that's a terrible idea. It makes an easy-but-dangerous practice (carelessly embedding variables in strings) even easier without adressing the danger (injection attacks) at all. See 5:20 for a longer explanation.
@vytah
@vytah 3 ай бұрын
It's more likely we get generic string templates without string interpolation than string interpolation without generic string templates.
@USONOFAV
@USONOFAV 3 ай бұрын
I'm glad they ditched that ugly implementation of string template
@masrizalw
@masrizalw 3 ай бұрын
That's why i love Java, the goal is not just for work
@elias_toivanen
@elias_toivanen Ай бұрын
It was the right call
@KevinSheppard
@KevinSheppard 2 ай бұрын
Why not treat templates similarly to regex patterns? Something like Template t = String.compile(`Hello, @{name}!`) Then you can run t.process("world") to get the result.
@jtau8042
@jtau8042 Ай бұрын
I don't like the `\{` syntax because `\` escaping the next char, so the string `text \{var} test` looks to me unbalanced.
@guai9632
@guai9632 3 ай бұрын
java keeps pretending it's the only language on jvm both kotlin and groovy use dollar sign, so we won't
@nipafx
@nipafx 3 ай бұрын
Or Kotlin and Groovy language designers made mistakes (just like Java designers did, btw) and we can do better. 😉 I think that possibility is at least worth exploring.
@guai9632
@guai9632 3 ай бұрын
kotlin and groovy designers know well what a principle of least surprise is
@nipafx
@nipafx 3 ай бұрын
@@guai9632 And Swift, Python, C#, ... designers don't? Also, do you think this should be the only consideration or is there a trade-off?
@guai9632
@guai9632 3 ай бұрын
c#'s do
@nipafx
@nipafx 3 ай бұрын
@@guai9632 Leaving aside that you left ~1.67 of my questions unanswered 😉, why doesn't C# use ${var} or $var for embedded variables, then?
@sadiulhakim7814
@sadiulhakim7814 3 ай бұрын
I liked String Template
@nipafx
@nipafx 3 ай бұрын
Same.
@softcoda
@softcoda 3 ай бұрын
This is really not cool. I now have to go and update all code bases where I already introduced this.
@nO_d3N1AL
@nO_d3N1AL 2 ай бұрын
I'm sure I'm not alone in that this was the first Preview feature I actually bothered using in real-world code. Specifically, it makes writing tests so much more elegant, for example, formatting JSON. To have it be removed with no migration path to a non-preview alternative is unfortunate. I suppose I can just stay on Java 21 as it is widely LTS supported and migrate once an alternative is available.
@holothuroid9111
@holothuroid9111 3 ай бұрын
Now, StringTemplate could have a method to turn itself into an interpolated string.
@nipafx
@nipafx 3 ай бұрын
Yeah, in fact they already did have that in JDKs 21 and 22. I didn't use it at 10:33 because it favors one out of all possible "StringTempalte -> ..." transformations. E.g. `Statement.create("text \{variable}")` would then be harder to discover and longer than `"text \{variable}".interpolate()`, which I don't find ideal.
@maethorechannen
@maethorechannen 3 ай бұрын
The reason why ${} is familiar has little to with other languages. It's familiar because it's used in things like Spring's "Spring Expression Language" .
@shadeblackwolf1508
@shadeblackwolf1508 3 ай бұрын
And that is exactly why it cannot be used. Java does not want to break all your existing code using existing library placeholders. If they used ${, then spring would never be able to see that character combination. And every codebase running on old versions of spring where that processor expects a String, not a StringTemplate, would break.
@nipafx
@nipafx 3 ай бұрын
Are you sure more Java devs use SpEL et al. than, say, JS, Kotlin, Scala, and bash put together? Either way, the reason people cite when arguing for $ is more often one of these languages than SpEL. And that's not a bad idea because Java-string-based languages using $ is a really good reason for Java's string templates _not_ to use them, so bringing up SpEL et. al as an argument _for_ $ is an own goal.
@maethorechannen
@maethorechannen 3 ай бұрын
@@nipafx It's not just SPeL though. Thymeleaf uses it. Apache Velocity and Freemarker use it. I really think the familiarity comes from within the Java community itself, not from what other languages are doing.
@maethorechannen
@maethorechannen 3 ай бұрын
@@shadeblackwolf1508 I'm not arguing that String Template should or shouldn't use ${}, I'm arguing that the familiarity for it from Java developers comes from it currently being used by them with Java already, not that it's coming from other languages which the video implies.
@maethorechannen
@maethorechannen 3 ай бұрын
@@shadeblackwolf1508 Also, if String Templates could break existing code, then they shouldn't be added full stop. (And the more I think about it, the more I question the need for String Templates to be baked into the JDK, when we already have several template libraries other than "other languages do it and it would be kind of cool")
@jediikk
@jediikk 3 ай бұрын
I don't really get the security point. Why it should be goal of string templates? If injection is a concern, the sanitization should be left to the function/processor of whoever consumes the string template. My experience is mainly with JS version of string templating, and I don't feel insecure at all since many SQL libraries solve it just like I described - by processing/sanitizing the string template values with their own functions that take string template as parameter.
@nipafx
@nipafx 3 ай бұрын
String templates aren't needed to make security possible as there are already perfectly safe ways to create, e.g., SQL statements based on user input. Alas, they aren't always used (or injection attackes wouldn't be in the OWASP Top Ten). And a big reason why they aren't always used is because string concatenation is so much easier. So if you can find a way to make templating/interpolation just a bit easier than concatenation but as safe as the proper approaches, that would be a huge win. And that's a goal worth working towards; much more than just removing the inconveience of ` + `. JS's template strings aren't a good example and shouldn't be adopted by Java. It makes the wrong choice (injecting unchecked variable values into strings) the easiest one and leaves you to go the extra mile (wondering which tag function to tack on). But at least the tag function has access to the string portions and the variables, so that's good. I agree when you say "sanitization should be left to the function/processor". But for that to happen reliably, it must be a goal of the design process. And that's why security is a goal for string templates.
@shadeblackwolf1508
@shadeblackwolf1508 3 ай бұрын
Short version, StringTemplates make it possible for a library to force the safe AND convenient way, instead of choosing to support one or both. They don't wanna break things all over the place but if they had string templates from the start, jdbc would have been implemented to take a StringTemplate as query and values, and do the mapping into a PreparedStatement internally, never exposing a string interface that lets users create unsafe queries.
@mchiareli
@mchiareli 3 ай бұрын
​@@nipafx driving without seat belt is much more comfortable, but we all know the consequences, trying to dictate what people should do in language is just not right, listen to the community, we just want interpolation, we don't want crazy syntax, we don't want "security".
@nipafx
@nipafx 3 ай бұрын
@@mchiareli So you're proposing that most (all?) nations in the world should make coding without proper string templating a crime?
@lubricustheslippery5028
@lubricustheslippery5028 3 ай бұрын
@@shadeblackwolf1508 You could always concatenate strings and then use it as an parameter for the StringTemplate. I think the string template must take an String? If that isn't possible I would be in trouble because then it would be impossible to make the queries more dynamic than just use variables.
@darenkster
@darenkster 3 ай бұрын
I really wished they wouldn't have use \ for escaping. It's just so cumbersome to type on a german keyboard. i get the backwords compatibility aspect of it. I just hpped they would have considered the internationalizational aspect of that feature.
@nipafx
@nipafx 3 ай бұрын
Specifically on a German keyboard, this argument seems so strange to me! 0, =, ß, ?, ` are all frequently used characters and they're all right there on the same or neighboring keys. Are you really saying that you embed so many variables in strings that it will significantly increase your use of those keys, overshadowing `=`? Also, \{ is only one modifier whereas ${ are two, which makes it feel much more cumbersome to me.
@jay_sensz
@jay_sensz 3 ай бұрын
Not sure why you're complaining about the backslash given how hilariously bad the placement of the curly braces is on the German keyboard.
@darenkster
@darenkster 3 ай бұрын
​@@nipafx The number of variables embeded in string qould increase significantly if String templates would have made it as a full feature. But that is not my point. If you look at the american keyboard layout, frequently used characters in programming like \, [, ], /, ` etc are primary characters, meaning you do not need to hold another key to type them. On the german keyboard, these are either secondary or tertiary characters, so you need two or more key additionaly to type them, which in my optinion makes them automatically more cumbersome to type. I am sure there are other keyboard layouts with similar issues with different characters, and you can not accomondate all of them, but by using the backslash it seems like the designers were only looking at the american keyboard layout and did not consider the typing experience on other layouts.
@samuelteixeiras
@samuelteixeiras 3 ай бұрын
Just keep trying. It's better to not add it if you are doing it ugly.
@jay_sensz
@jay_sensz 3 ай бұрын
Could you implement it such that String Template literals look just the same as regular Strings (i.e. just regular double quoted or text block) and keep the type of the literal indeterminate until it is either assigned to a variable, gets typecast, or a method is invoked on it (e.g. `"myString".length()`)? Here's what I mean: - When the literal is assigned or cast to anything other than StringTemplate, treat it as a String, otherwise as StringTemplate - When a method is invoked on literals directly or `+` concatenation is used, always treat them as a String - When assigned to `var`, treat it as either a String or StringTemplate depending on whether it contains String Template sequences - When treating the literal as a String, produce a compiler error in case it contains any String Template sequences This would be somewhat similar to how lambda expressions are already being handled by the compiler.
@vytah
@vytah 3 ай бұрын
It was discussed somewhere in that mailing list thread by Maurizio Cimadamore, the result was that it doesn't work that well: there are problems with overloads (choosing between m(String) and m(StringTemplate) for m("X")) and with generics (List l = List.of("X"); fails to typecheck, and fixing that would require overhauling the entire typechecker)
@jay_sensz
@jay_sensz 3 ай бұрын
@@vytah My suggestion would be that these cases are treated as String unless cast explicitly to StringTemplate (e.g. m((StringTemplate)"X") or a type witness is used (e.g. List.of("X")). Considering these are probably fairly niche usages I would argue that the cumbersome syntax is justifiable. But maybe there are problems with that which aren't obvious from a non-language engineer perspective.
@nipafx
@nipafx 3 ай бұрын
The mailing list conversation @vtah mentioned started with this mail: mail.openjdk.org/pipermail/amber-spec-experts/2024-March/004016.html I recommend to give it a read. If you think you found a solution that doesn't have these issues (which is entirely possible!), I recommend to send it to the mailing list. It can really make a difference there! (Unlike here on KZbin. 😉)
@jay_sensz
@jay_sensz 3 ай бұрын
@@nipafx Thanks for the link. It seems what I was trying to argue for is called "target typing".
@TJ-wc3iq
@TJ-wc3iq 3 ай бұрын
Offtopic: Year 12,024, Nikolai? Kurzgezagt mich! 😆
@nipafx
@nipafx 3 ай бұрын
😁
@percival477
@percival477 3 ай бұрын
Can we get a video on why not valhalla now?
@nipafx
@nipafx 3 ай бұрын
No need for a video: "It's complicated work and not the only / most important thing that's happening right now. It's ready when it's ready - hopefully soon." There you go, video avoided. PS: Trust me, there are very few people in our community that want it to happen NOW more than me. 😖 kzbin.info/www/bejne/oavNeKNtgdKKZqs
@percival477
@percival477 3 ай бұрын
@@nipafx I thought it would be neat to explore some of the challenges and seeing some things that people tried but decided it was not the best idea.
@nipafx
@nipafx 3 ай бұрын
@@percival477 A Valhalla history lesson? Not a bad idea, but challenging. If you want to look into it yourself, search for "Brian Goetz Valhalla" and pick some of the presentations, e.g. kzbin.info/www/bejne/Z3mXp6CKYruUatE
@aymo-lh4nq
@aymo-lh4nq 3 ай бұрын
What's wrong with String.format()?
@nipafx
@nipafx 3 ай бұрын
Syntactically it's incovenient that the placeholder and the variable are so far apart, performance-wise it's just slow compared to concatenation, and from a security point of view it lacks the capability to apply format-specific rules (e.g. SQL, JSON, etc.) before user content is interpolated into the string. Not all of those issues matter in all situations and `String::format` is definitely ok to use (I do it a lot and generally prefer it over string concatenation), but there's room for improvement.
@peacemakerle
@peacemakerle 3 ай бұрын
It is damn expensive. I wrote an alternative implementation using an iterative approach, instead of transforming the format string to an object presentation at first. That performs ways faster, but with the downside, that it may output some part of the result at first, before failing due a syntax error. Furthermore, in my humble opinion, String.format() is overbloated with much too many features. In 99.9% of all cases people are just using "%s".
@nipafx
@nipafx 3 ай бұрын
@@peacemakerle Can't confirm the 99.9% - maybe 1-2% would be `%d`. 😂 Otherwise true. 👍
@ahmadfx8962
@ahmadfx8962 3 ай бұрын
لقد كانت من اهم الخصائص المفيدة... للاسف😢
@VuLinhAssassin
@VuLinhAssassin 3 ай бұрын
We need interpolation, pretty please, ok?
@nipafx
@nipafx 3 ай бұрын
You're nicer than the person I portray at 5:20 but everything I say in that section applies to your request. TL;DW: The mild inconvenience of typing ` + ` is orders of magnitude less important to fix than the security issues caused by injections.
@pockpicket9360
@pockpicket9360 3 ай бұрын
the character to use in template does not really matter. The bad part is the STR."" The only good way is to be able to do "my \{variable}" and to be able to pass it every where I can pass a String. We don't want to call toString() every time we want to use it, this should be a "String" by default nothing else.
@nipafx
@nipafx 3 ай бұрын
The section starting at 5:20 was made for you!
@kitkarson4226
@kitkarson4226 3 ай бұрын
i hated the "\{}" format. i am glad it got removed.
@nipafx
@nipafx 3 ай бұрын
In case you didn't watch the whole video, you probably wanna watch the two minutes starting at 7:35. 😬
@jackfrosch
@jackfrosch 3 ай бұрын
Enjoyed the video and learned a lot about the state of string interpolation. However, the arguments presented against the dollar sign as a special character in string interpolation are extremely weak. First, devs would use string interpolation 100x or 1000x times more often than a currency indicator or whatever other purpose it is used for. Second, while someone's top 10 languages list may only include one that only uses dollar sign interpolation, that one is used in 99% of all web applications. That's like saying that of the top 10 substances found in the ocean, only one is water. Not to mention that there are two close cousins to the top 10, namely Typescript and Groovy, that use dollar sign and curly braces for string interpolation.
@nipafx
@nipafx 3 ай бұрын
The point about water is pretty good - made me chuckle. 👍But what about 99% of all system code being written in a language that doesn't have any interpolation? There is zero water in... (well, that's actually unfair because water is everywhere) ... the sun, there's zero water on the sun. So I can apply your logic and then we don't need string interpolation? 😉 What I'm trying to say is that across all languages, interpolation by dollar sign is far from ubiquitous. We don't agree on how strong the arguments against $ are but we seem to agree on there being some. Given that I've heard none in favor, \{ still seems to come out ahead.
@jutsufly
@jutsufly 3 ай бұрын
Why not just `\{var}` like javascript?
@nipafx
@nipafx 3 ай бұрын
See 5:20
@rtorello75
@rtorello75 3 ай бұрын
I don't understand why you can't just start with both the triple-quote """ and the \{var}, and then leave the rest of the crap out! Those two compiler-syntactic structures seem to capture the essence of what Java is trying to accomplish here. I mean, I will admit I haven't even used these templates yet, but the value of it all looks (to me) like it can be summarized in those two features. After that - adding "RAW", "STR", "FMT", and "ARBITRARY" is where the actual "featur-itis" starts to occur. - Please disagree with me. Sincerely, Ralph
@nipafx
@nipafx 3 ай бұрын
var s = """\{var}"""; What type is `s`?
@rtorello75
@rtorello75 3 ай бұрын
"It is a non-goal to perform an altered version / Syntactic-Sugar for String Concatenation" ... Take that out of the JEP. That's my suggestion.
@rtorello75
@rtorello75 3 ай бұрын
@@nipafx Well ... Clearly the answer isn't `java.lang.String`, or you wouldn't have posted this as a reply. Ummm... So... May I ask what on earth is preventing the answer from being `java.lang.String`?
@nipafx
@nipafx 3 ай бұрын
@@rtorello75 Hey, you're designing this language feature, it can be whatever you want. 😉 `String` would absolutely work. What would the effects be? Every Java developer would be a bit happier when mixing strings and variables - that's nice. But we would've done nothing to reduce the prevalence of a security problem (specifically, injection attacks) that is a serious problem in our industry and causes some of the applications these developers write to lose all their user data. Oops. What if we instead find a way to make this new feature more elegant than concatenation (so developers will actually use it) but as safe as The Proper Way to combine strings and variables? (What exactly that is depends on the domain, but for, e.g., SQL it would be prepared statements.)
@mralix9566
@mralix9566 3 ай бұрын
That was a special video just like your explanation ♥ We trust Java architects are going to propose something great like they always did for past three decades
@guai9632
@guai9632 3 ай бұрын
like fucked up generics?
@mralix9566
@mralix9566 2 ай бұрын
@@guai9632 What's wrong with them
@guai9632
@guai9632 2 ай бұрын
@@mralix9566 in kotlin they made them right, you declare variance of a generic parameter once. if the class is both covariant and contravariant on the same parameter, you have to introduce two interfaces. this makes generics much less verbose and easier to use. in java you have to declare variance on every method. as a result, in kotlin skilled dev can design generic api once and then less skilled devs would just use it barely noticing. in java everyone has to deal with them leading to more confusion and bugs. some teams even chose not to bother with generics at all, and you'll have less expressive apis in the end I guess they didn't want to redesign again their new and shiny collections, which they designed mutable by default. mutable collections are an example of both co- and contravariant type and had to be redesigned if they went the kotlin way from the start also there is type erasure. usable metainfo just absent from the class files and one cannot get it back via reflections. thus poorer metaprogramming also primitive generic params have to be boxed, and it's slower
@static-m-s
@static-m-s 3 ай бұрын
dudes ... just slow down the tempo
@qwalers
@qwalers 3 ай бұрын
I don’t understand why Java cannot keep it simple
@pockpicket9360
@pockpicket9360 3 ай бұрын
Because Java dev want a high retrocompatibility and a good safety. That's why we use Java in enterprise software
@qwalers
@qwalers 3 ай бұрын
@@pockpicket9360 i don’t think that this is a problem. Backticks could be enough and simple $ interpolation is enough what most of us need
@LA-fb9bf
@LA-fb9bf 3 ай бұрын
Why don’t do the whole mess like in Kotlin. That’s pragmatic enough!
@nipafx
@nipafx 3 ай бұрын
This 5:20 you?
@sergiyscherban219
@sergiyscherban219 3 ай бұрын
Why we can not use %s{} as a combination of existing string format syntax and new possibility? We can even have %{} for cases when we do not want force processor to interpolate value as string and give it ability to decide which representstion is better.
@AndiRadyKurniawan
@AndiRadyKurniawan 3 ай бұрын
I prefer the %{someVar} syntax.
@vytah
@vytah 3 ай бұрын
For the exact same reason we cannot use $
@prdoyle
@prdoyle 3 ай бұрын
Every syntax that can appear today in a valid Java string literal suffers the same backward-compatibility problem. \{} is better because no existing string literal can contain it.
@Aqwsftuvccnktefjopp
@Aqwsftuvccnktefjopp 3 ай бұрын
The real problem is all those “Java Neanderthalers” who specify the java heavy syntax - kick them out!!!
@nikitamyazin6586
@nikitamyazin6586 3 ай бұрын
If only there was any language in the JVM world that did have an interpolation working elegant and secure for years. That would’ve made all of these arguments against templates and interpolation quite awkward. Luckily, we live in 2001 and Scala hasn’t been invented yet.
@nipafx
@nipafx 3 ай бұрын
I don't recall a single argument against templates and it seems Scala had the same thoughts on interpolation or they wouldn't have picked the approach they did. So on those two topics Scala and Java agree. And even Scala's solution and Java's retracted proposal are very similar. I think the main difference is that Java balked at the weird syntax, something that never bothered Scala.
@nikitamyazin6586
@nikitamyazin6586 3 ай бұрын
@@nipafx would do you mean by “weird syntax”? Here’s an example of valid Scala code s”Hello, World! 1 + 1 = ${1 + 1}” sql”insert into users (name, age) values (${user.name}, ${user.age})” The second one needs a library though, but it’ll create SQL statements and handle escaping for you. If that looks weird, I’d be happy to see not-so-weird Java version of examples above
@nipafx
@nipafx 3 ай бұрын
@@nikitamyazin6586 Have you ever called a method in Java with `method args` without parenthesis? The non-weird way would be `sql("...")`. A lot of people, Java users as well people working on the language, were uneasy about introducing an additional, one-off method invocation syntax. (Personally, I didn't mind that much.)
@nikitamyazin6586
@nikitamyazin6586 3 ай бұрын
@@nipafx for me that sounds like an issue with people that don’t want to learn anything new. Programming languages should evolve over time, you can’t make them meet modern expectations based purely on ideas that existed 30 years ago. So while it’s valid a concern, it shouldn’t be a show stopper.
@nipafx
@nipafx 3 ай бұрын
@@nikitamyazin6586 It's not a show stopper - it was proposed like that after all. But it's a downside of the proposal. And I think it's you who doesn't want to learn anything new (if you balk at that statement, you were just as unkind to other people), in this case the considerations behind designing a language and the benefits of conceptual simplicity.
@hristoistoyanov
@hristoistoyanov 3 ай бұрын
So it won't be re-introduced as a Java 24 JEP? Really? You are kidding, right? A lot of us who want string templates will be stuck on Java 22. for a while ... Thank you Oracle, you could not just ship the feature "as is" in Java 23 without officially listing in the JEPs list?
@nipafx
@nipafx 3 ай бұрын
If you're stuck on any version, please don't make it 22! I'm not aware of any vendor providing updates for that after September. If you absolutely have to, you can use the feature just the same on JDK 21. More importantly, though: If you committed to a preview feature so hard that you're now stuck on a JDK release, you're doing it wrong. You must've ignored _all_ the warning signs - the barrier tape, the blinking red light, the sirens, the people in yellow vests hectically yelling and waving at you from afar... They were all trying to tell you to never write more code against a preview feature than you're willing to throw away and rewrite.
@kamurashev
@kamurashev 3 ай бұрын
Cough *kotlin* cough
@mchiareli
@mchiareli 3 ай бұрын
No one cares about this security bs, just give us interpolation
@shadeblackwolf1508
@shadeblackwolf1508 3 ай бұрын
Strong disagree. I was looking forward to a nice way to not have to think about SQL injection risks every time i write an sql query with dynamically included parts.
@sjzara
@sjzara 3 ай бұрын
One of the main benefits of Java is security.
@nipafx
@nipafx 3 ай бұрын
That opinion is exactly why simple string interpolation is dangerous and won't be introduced in Java.
@behindthemind1825
@behindthemind1825 3 ай бұрын
@@shadeblackwolf1508 But the thing is that most SQL library APIs use positional/named parameters, so it's not really a security problem as you say. Saying string templates are there for security also is not good enough of an argument. String templates/interpolation should be there for convenience and not for security. Security aspect is already handled by widely used SQL libraries.
@shadeblackwolf1508
@shadeblackwolf1508 3 ай бұрын
@@behindthemind1825 the security argument is the reason the feature is considered at all. If it gets fully scrapped, interpolation isn't coming.
@ramdaneoualitsen1323
@ramdaneoualitsen1323 3 ай бұрын
I think java is not between safe hands.
@MeriaDuck
@MeriaDuck 3 ай бұрын
The java community process is one of its kind. Moving an important language is hard. The last 20+ years Oracle and the java community have done (remarkably) well in my opinion.
@ramdaneoualitsen1323
@ramdaneoualitsen1323 3 ай бұрын
​@@MeriaDuck what you said is correct. I started working with Java 6 and java 7 and thing went really well recently. But some features are really needed for the language such as ?. (that returns null instead of NPE) string templates as any other language. rethink getters/setter (so we don't have to use lombok). default parameters for methods and constructors. I know this is not easy because of backward compatibility but people are still using Java 7 and 8 anyways. I mean we should not be afraid to break things if we want java to live in this era.
@MeriaDuck
@MeriaDuck 3 ай бұрын
@@ramdaneoualitsen1323 many of those features are available on the JVM in the form of kotlin. Java may or may not follow everything that is fun in Kotlin
@bluemeriadoc
@bluemeriadoc 3 ай бұрын
if you're going to use backticks instead of double quotes then \{} is unnecessary. You can just use \variable
@TheBigLou13
@TheBigLou13 3 ай бұрын
I think that would ot always work well.
@bluemeriadoc
@bluemeriadoc 3 ай бұрын
@@TheBigLou13 parsing rules could be completely different in backticks
@nipafx
@nipafx 3 ай бұрын
@@bluemeriadoc But then users have to learn two completely different rulesets for what's essentially the same thing: a string of characters. And the sole benefit is a little less typing - and of curly braces of all things, which Java devs already have on speed dial. 😉
@bluemeriadoc
@bluemeriadoc 3 ай бұрын
@@nipafx which is why using backticks is dumb
@nipafx
@nipafx 3 ай бұрын
@@bluemeriadoc I'm not convinced of backticks either. I think "..." with some prefix would work best. I just used backticks in the video as the simplest-to-understand example syntax.
All Java 23 Features - Inside Java Newscast #70
11:46
Java
Рет қаралды 20 М.
Java 21 String Templates - THIS FEATURE IS SHELVED
10:52
Viraj Shetty
Рет қаралды 1,1 М.
The joker favorite#joker  #shorts
00:15
Untitled Joker
Рет қаралды 30 МЛН
💩Поу и Поулина ☠️МОЧАТ 😖Хмурых Тварей?!
00:34
Ной Анимация
Рет қаралды 2 МЛН
小天使和小丑太会演了!#小丑#天使#家庭#搞笑
00:25
家庭搞笑日记
Рет қаралды 33 МЛН
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 390 М.
(Dirty?) Tricks in Java 22 - Inside Java Newscast #64
13:05
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 201 М.
Laravel vs Rails for Javascript developers
19:50
Sam Lewis
Рет қаралды 3,3 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,7 МЛН
Java 21 Is Good?! | Prime Reacts
27:08
ThePrimeTime
Рет қаралды 240 М.
Reacting to Controversial Opinions of Software Engineers
9:18
Fireship
Рет қаралды 2,1 МЛН
Java 8 to 18: Most important changes in the Java Platform
31:24
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 86 М.