On Mar 19, 2024, at 10:23 AM, Brian Goetz <[email protected]> wrote:
Let's pull on this string some more. Assuming we settled on disjoint types and
syntaxes, with no magic conversions, what library support do we need directly
for ST? I am thinking (please, let's focus on the functionality before we
nitpick the names):
// on String
static join(StringTemplate) // previously STR
I assume the return type for the preceding method should be `String`.
// on StringTemplate
String join() // STR, instance/suffix
version
static StringTemplate join(StringTemplate...) // + for string templates
This is a pleasantly short set; is anything missing? (Not addressing the
"which things were previously processors, but now need API points" right now --
that's a separate discussion.)
Actually, Brian, I _am_ going to nitpick your use of the name “join” here for
all three of those methods, because, given the comments, they do very different
things; the first two do “string interpolation” on a single template (and in
the process convert the values in the template to strings) whereas the last
combines multiple templates into a single template (but does not convert any of
the values to strings).
Moreover, the existing `join` method of String does yet a different operation:
concatenate a sequence of strings, using a given delimiter string (repeatedly,
if necessary) as a separator. So I think “join” was a particularly infelicitous
choice of name for these three examples.
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
—Guy