<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
On general principle, I would agree about instance methods often being better than static methods for various reasons, other things being equal.
<div><br>
</div>
<div>But in this specific discussion we have heard concerns about confusing templates with string interpolation. When it comes to safety of (say) SQL processing, which of the following would we prefer:</div>
<div><br>
</div>
<div><font face="Menlo"><span class="Apple-tab-span" style="white-space:pre"></span>SQL($"SELECT * FROM \{tableName} blah blah blah”.xyzpdq());</font></div>
<div><font face="Menlo"><br>
</font></div>
<div>
<div><font face="Menlo"><span class="Apple-tab-span" style="white-space: pre;"></span>SQL(xyzpdq($"SELECT * FROM \{tableName} blah blah blah”));</font></div>
</div>
<div><br>
</div>
<div>The first one avoids nested parentheses. The second one says right up front, “Danger, Will Robinson, danger! The template will not be processed in the way you might think!"<br id="lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On Mar 19, 2024, at 2:53 PM, Maurizio Cimadamore <maurizio.cimadamore@oracle.com> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div>
<div class="markdown-here-wrapper" data-md-url="" style="" markdown-here-wrapper-content-modified="true">
<p style="margin: 0px 0px 1.2em !important;">Of course a static method is enough (I find the name “process” not very clear on what that method does though).</p>
<p style="margin: 0px 0px 1.2em !important;">One case where the instance syntax comes out on top if in method context:</p>
<pre style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;font-size: 1em; line-height: 1.2em;margin: 1.2em 0px;"><code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;white-space: pre; overflow: auto; border-radius: 3px; border: 1px solid rgb(204, 204, 204); padding: 0.5em 0.7em; display: block !important;">foo($"Hello, \{world}".xyz())
</code></pre>
<p style="margin: 0px 0px 1.2em !important;">Which reads better than:</p>
<pre style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;font-size: 1em; line-height: 1.2em;margin: 1.2em 0px;"><code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;white-space: pre; overflow: auto; border-radius: 3px; border: 1px solid rgb(204, 204, 204); padding: 0.5em 0.7em; display: block !important;"> foo(xyz($"Hello, \{world}"))
</code></pre>
<p style="margin: 0px 0px 1.2em !important;">at least IMHO (no doubly nested parens).</p>
<p style="margin: 0px 0px 1.2em !important;">Even though, at the end of the day, interpolation is just a processor, just a method which takes a StringTemplate and returns a String, it is also a very common one, so allowing for an instance method could be a
possible way to offset the loss of the STR syntax.</p>
<p style="margin: 0px 0px 1.2em !important;">Maurizio<br>
</p>
<p style="margin: 0px 0px 1.2em !important;">On 19/03/2024 18:33, Brian Goetz wrote:</p>
<div style="margin: 0px 0px 1.2em !important;"><br class="webkit-block-placeholder">
</div>
<div class="markdown-here-exclude">
<div><br class="webkit-block-placeholder">
</div>
<blockquote type="cite" cite="mid:5e4ebcef-9773-42e4-838c-3506e0236616@oracle.com">
<span style="white-space: pre-wrap"></span>
<blockquote type="cite" cite="mid:20240319141945.795026959@eggemoggin.niobe.net">
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">Here I set forth your three examples with new names that are related
to those already used in the existing preview implementation of
StringTemplate in JDK 21 (and JDK 22—I just checked). I do this not to
suggest that these other names should be used, but only in the hopes
of reducing confusion as we begin this discussion. Later we can decide
whether the names “process” and “interpolate” and “combine” should be
changed (possibly all into the same single name).
// on String
static String process(StringTemplate) // previously STR
// on StringTemplate
String interpolate() // STR, instance/suffix version
static StringTemplate combine(StringTemplate...) // + for string templates
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">Maybe I’m missing something, but: Why do we need both `String::process`
and `StringTemplate::interpolate`? What are the use cases?
</pre>
</blockquote>
<br>
For a similar reason we currently have String::valueOf(int) and Integer::toString(int). In some use cases, the "prefix" usage (static method) feels more natural, whereas in others, the "suffix" usage (instance method) feels more natural.
<br>
<br>
Even if we end up with only one, I would rather not bias towards "of course it is the static version" at this early point; I am trying to sketch out scope right now.<br>
<br>
<br>
</blockquote>
<div><br class="webkit-block-placeholder">
</div>
</div>
<div style="margin: 0px 0px 1.2em !important;"><br class="webkit-block-placeholder">
</div>
<div title="MDH:PHA+T2YgY291cnNlIGEgc3RhdGljIG1ldGhvZCBpcyBlbm91Z2ggKEkgZmluZCB0aGUgbmFtZSAi
cHJvY2VzcyIgbm90IHZlcnkgY2xlYXIgb24gd2hhdCB0aGF0IG1ldGhvZCBkb2VzIHRob3VnaCku
PC9wPjxwPk9uZSBjYXNlIHdoZXJlIHRoZSBpbnN0YW5jZSBzeW50YXggY29tZXMgb3V0IG9uIHRv
cCBpZiBpbiBtZXRob2QgY29udGV4dDo8L3A+PHA+YGBgPGJyPmZvbygkIkhlbGxvLCBce3dvcmxk
fSIueHl6KCkpPGJyPmBgYDwvcD48cD5XaGljaCByZWFkcyBiZXR0ZXIgdGhhbjo8L3A+PHA+YGBg
PGJyPgpmb28oeHl6KCQiSGVsbG8sIFx7d29ybGR9IikpPGJyPgpgYGA8L3A+CjxwPmF0IGxlYXN0
IElNSE8gKG5vIGRvdWJseSBuZXN0ZWQgcGFyZW5zKS48L3A+PHA+R2k8YnI+PC9wPjxwPjwvcD48
cD48YnI+PC9wPjxkaXYgY2xhc3M9Im1vei1jaXRlLXByZWZpeCI+T24gMTkvMDMvMjAyNCAxODoz
MywgQnJpYW4gR29ldHogd3JvdGU6PGJyPjwvZGl2PjxibG9ja3F1b3RlIHR5cGU9ImNpdGUiIGNp
dGU9Im1pZDo1ZTRlYmNlZi05NzczLTQyZTQtODM4Yy0zNTA2ZTAyMzY2MTZAb3JhY2xlLmNvbSI+
Cgo8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5cGUi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b3dhcmRzICJvZgogICAgY291cnNlIGl0IGlzIHRoZSBzdGF0aWMgdmVyc2lvbiIgYXQgdGhp
cyBlYXJseSBwb2ludDsgSSBhbSB0cnlpbmcgdG8KICAgIHNrZXRjaCBvdXQgc2NvcGUgcmlnaHQg
bm93Ljxicj4KICAgIDxicj4KICAgIDxicj4KICAKCgo8L2Jsb2NrcXVvdGU+" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0;">
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</body>
</html>