<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
The overlap between string literals and string template literals is indeed a tricky one, and bears some review of the options. Obviously string templates and strings have some things in common (its in the name!), but they are also different and evaluate to
different types. So how “same” or “different” should they look?
<div class=""><br class="">
</div>
<div class="">Simplistic arguments in favor of “different”:</div>
<div class=""> - Ambiguity is bad, clarity is good</div>
<div class=""> - String / string template literals can be both wide and tall; having to examine the entirety to know which it is could be confusing</div>
<div class=""> - Simpler for compiler and specification writers</div>
<div class=""><br class="">
</div>
<div class="">Simplistic arguments in favor of “same”:</div>
<div class=""> - Will be perceived as “fussy” or distracting</div>
<div class=""> - Users are already grumpy that we’re not doing “string interpolation” and calling it a day</div>
<div class=""> - Most of the time, it is perfectly obvious which one it is </div>
<div class=""> - Have to make up yet another new and unfamiliar syntax to disambiguate, think of the bike shedding</div>
<div class=""><br class="">
</div>
<div class="">There are probably others, but none of these seem like slam-dunks one way or the other. </div>
<div class=""><br class="">
</div>
<div class="">There are a few choices here:</div>
<div class=""><br class="">
</div>
<div class=""> - Keep the current syntax approach</div>
<div class=""> - Give STs a new syntax</div>
<div class=""> - Give both STs and string literals an _optional_ new syntax, such as I_IZ_STRING”…” and TEMPLATZ”…”, but allow the current approach when disambiguation is not needed</div>
<div class=""><br class="">
</div>
<div class="">The last seeks a compromise between the current path and the desire for explicitness. Suppose we allowed s”…” and t”…” literals, where the sigils were optional. What then? </div>
<div class=""><br class="">
</div>
<div class="">Obviously in the cases which are currently ambiguous-seeming, users could disambiguate explicitly. The prefix sigil means no one has to “buffer” when interpreting the code. That’s nice. Having two ways to write classical string literals might
confuse people who haven’t seen them before, or stimulate unproductive “style wars”. That’s probably not too big a problem here. </div>
<div class=""><br class="">
</div>
<div class="">Overall, though, I am not so enthused about creating yet another new lexical mechanism for having different kinds of stringy things. The value is … meh, and it seems an attractive nuisance. In other languages with multiple “flavors” of string,
there is a tendency to proliferate more flavors. (Raw strings, anyone?). </div>
<div class=""><br class="">
</div>
<div class="">My take is that this is something that is bothering us a lot because it is new, but I’m skeptical that it carries its weight.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Mar 11, 2024, at 9:07 AM, Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" class="">archie.cobbs@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">On Mon, Mar 11, 2024 at 9:37 AM Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank" class="">forax@univ-mlv.fr</a>> wrote:</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class="">
I vote for making string templates explicit.<br class="">
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">Caveat: I've been following this discussion only loosely so I'm likely to say something stupid/ignorant/redundant; if so please ignore.<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">But I am tending to agree with Remi. The recent simplifications Brian described are a definite improvement, but now we're left with a new question:<br class="">
</div>
</div>
<div class="gmail_quote"><br class="">
</div>
<div class="gmail_quote">What is the advantage of having the language literals for String and StringTemplate look so confusingly similar?<br class="">
</div>
<div class="gmail_quote"><br class="">
</div>
<div class="gmail_quote">Reversing that question, I'm not seeing the big downside of having a simple prefix for literals like this:<br class="">
</div>
<div class="gmail_quote"><br class="">
</div>
<div class="gmail_quote"> var s = "this is a string";<br class="">
</div>
<div class="gmail_quote"> var st1 = $"this is a (degenerate) template";</div>
<div class="gmail_quote"> var st2 = $"this is also a \{template}";</div>
<div class="gmail_quote"> var x = "this is a \{lexical_error}";<br class="">
</div>
myobj.someOverloadedMethod($"this is definitely a template");
<div class="">
<div class=""> myobj.someOverloadedMethod("this is definitely a string!"); // no need to consult javadoc here<br class="">
<div class=""><br class="">
</div>
</div>
</div>
<div class="">Seems like the trade-off is straightforward:</div>
<div class=""><br class="">
</div>
<div class="gmail_quote">Cost: one character<br class="">
</div>
<div class="gmail_quote">Benefit: instant disambiguation clarity in the developer's mind<br class="">
</div>
<div class="gmail_quote"><br class="">
</div>
<div class="gmail_quote">At least, it makes the whole API design/overload question straightforward.<br class="">
</div>
<div class="gmail_quote"><br class="">
</div>
<div class="gmail_quote">Put another way, StringTemplates are a cool new language feature, and as such it seems like they deserve a "first-class" allotment in the syntax of the language.<br class="">
</div>
<div class="gmail_quote"><br class="">
</div>
<div class="gmail_quote">-Archie</div>
<div class="gmail_quote"><br class="">
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>