Update on String Templates (JEP 459)
Mark Reinhold
mark.reinhold at oracle.com
Tue Mar 19 18:49:45 UTC 2024
2024/3/19 14:33:20 -0400, brian.goetz at oracle.com:
>>> 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
>>
>> Maybe I’m missing something, but: Why do we need both `String::process`
>> and `StringTemplate::interpolate`? What are the use cases?
>
> 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.
>
> 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.
Ah, so you’re really asking not about these three methods (modulo
naming) but about just two things, a way to interpolate a template and
a way to concatenate templates, and you consider the (not necessarily
bijective) mapping from those things to API points to be the bikeshed.
- Mark
More information about the amber-spec-experts
mailing list