<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 15/03/2024 00:24, Robbe Pincket
wrote:<br>
</div>
<blockquote type="cite" cite="mid:AS8PR10MB77984941E17CA8589BE4E2C7D3282@AS8PR10MB7798.EURPRD10.PROD.OUTLOOK.COM">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}.MsoChpDefault
{mso-style-type:export-only;}div.WordSection1
{page:WordSection1;}</style>
<div class="WordSection1">
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">On 14/03/2024 23:44 UTC,
Maurizio Cimadamore wrote:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> On 14/03/2024
22:36, Robbe Pincket wrote:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">
(I’m not a big fan of `TEMPLATE"Foo: \{bar}"` either as it’s
just so much longer than `"Foo: " + bar`)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> Note that
when I suggested TEMPLATE as a prefix I was obviously not
being super serious :-)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> Let's do a
test (bear with me). Let's assume the two prefixes were S
and T (not saying I like them, just trying them out for
size). Let's also assume there's no conversion. Then your
examples become:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> ```<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> String s1 =
"test" // still a string literal<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">
StringTemplate st2 = T"test" // allowed, constant strings
can be implicitly converted to templates<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">
StringTemplate st3 = "Foo: \{bar}" // Simple string template<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> String s4c =
S"Foo: \{bar}" // short for String.of("Foo: \{bar}")
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> ```<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> I think
that's not too bad? (please don't focus too much on the
letters).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> In the sense:
the rare cases (st2) has a prefix. And the operation we want
explicit (s4c) also has a prefix. Everything else is fine.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">So the difference is
that `T` (or something else) has to be used for templates
without any holes?
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">To me it feels a bit
weird to have a prefix for the special case of a hole-less
template.</span></p>
</div>
</blockquote>
Ok. Note that T would be required in that case, but one might also
use it as a visual delimiter: if a template is very long, it might
not be too readable to leave it implicit as to whether the thing in
quotes is a template or not.<br>
<blockquote type="cite" cite="mid:AS8PR10MB77984941E17CA8589BE4E2C7D3282@AS8PR10MB7798.EURPRD10.PROD.OUTLOOK.COM">
<div class="WordSection1">
<p class="MsoNormal"><span lang="en-BE"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">I think I saw an
argument passing by, saying something along the line that
`String` and `StringTemplate` are semantically different so
implicit conversion in either direction would be bad because
it would be ambigous.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">If this `T` idea is
based on that, I don't really see why it would be that bad.
If an API accepts either, I would intuitivly expect that
passing a string and passing a hole-less template with the
same string would give me the same result.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> Control
question #1: does the conversion here change things much?
Or, are we reaching for conversions just to have something
"shorter" ?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> Control
question #2: let's now assume that S and T were spelled
(String) and (StringTemplate), respectively. How do we feel
about this?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> ```<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> String s1 =
"test" // still a string literal<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">
StringTemplate st2 = (StringTemplate)"test" // allowed, cast
from constant string to template<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">
StringTemplate st3 = "Foo: \{bar}" // Simple string template<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> String s4c =
(String)"Foo: \{bar}" // allowed, cast from template back to
String (interpolation)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> ```<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">I think I answered #1.
Having the 'T' *just* for the "hole-less" template feels a
bit odd? I don't you can sell me on #2.
</span></p>
</div>
</blockquote>
Fair enough - I had to ask :-)<span lang="en-BE"><o:p></o:p></span>
<blockquote type="cite" cite="mid:AS8PR10MB77984941E17CA8589BE4E2C7D3282@AS8PR10MB7798.EURPRD10.PROD.OUTLOOK.COM">
<div class="WordSection1">
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">If
´(StringTemplate)"test"` and `(String)"Foo: \{bar}"` are
valid, will the following things work too? `"test"
instanceof StringTemplate template` and `"Foo: \{bar}"
instanceof String str`. The second one I'd assume no, the
first one is a bit unclear to me.</span></p>
</div>
</blockquote>
<p>These are questions I raised even in the context of the implicit
conversion you are advocating for: once you add an assignment
conversion, cast comes with it, and with cast, patterns and
instanceof. In other words, that's the price we have to pay for
eliminating the T in the hole-less template in the way you
proposed. Casts just make that trade-off more explicit.</p>
<p>Another thing I don't love about implicit conversion, is that
they don't play with inference too well:</p>
<p>```<br>
List<StringTemplate> ls = List.of("Hello");<br>
```<br>
<br>
The above would be an error. The type-variable (X) for List::of is
seeing two different constraints:<br>
<br>
* X = StringTemplate (from the target type)<br>
* String <: X (from the argument)</p>
<p>This fails, because we'd infer StringTemplate which is a
supertype of String. Even if we could somehow "convince" inference
that StringTemplate is a valid "more general" type, I see lots and
lots of dragons here:</p>
<p>* inference would have to be careful only to do certain moves if
constant strings are involved<br>
* if we pick StringTemplate, we're basically saying that the
method is applicable by conversion, so in overload step 2. But is
this the overload step we used to pick that candidate in the first
place? Probably not, because String <: X requires only
subtyping, not conversion.</p>
<p>Ultimately, implicit conversion would only "kind of work" and
will lead to issues when interacting with generics. While it's
tempting to sweep issues under the rug (after all they do not seem
very important for the examples we're discussing), such
compromises have a tendency to bit us back when feature "grow up"
and start playing more with other feature: any loss of
compositionality there costs quite a bit. Which is why I'm not in
love with implicit conversions</p>
Maurizio<br>
<p><br>
</p>
<blockquote type="cite" cite="mid:AS8PR10MB77984941E17CA8589BE4E2C7D3282@AS8PR10MB7798.EURPRD10.PROD.OUTLOOK.COM">
<div class="WordSection1">
<p class="MsoNormal"><span lang="en-BE"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"> Maurizio<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">Kind regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-BE">Robbe Pincket</span></p>
</div>
</blockquote>
</body>
</html>