New candidate JEP: 430: String Templates (Preview)

Attila Kelemen attila.kelemen85 at gmail.com
Wed Sep 21 23:17:49 UTC 2022


Thanks for the responses. See some of my clarifications below.

> >
> > 1. Might be a personal preference, but I find the
> > `TemplateProcessorExpression . Template` syntax bizarre.
>
> We knew that at least one out of the 10M Java developers would loudly
> proclaim "I hate the syntax", so congratulations, it's you :)   New
> syntaxes are risky; people are used to "${foo}" in other languages, and
> this is new and different, and sometimes different is scary.  But, it
> wasn't picked out of a hat; a good deal of thought has gone into this,
> and so while it may seem weird now, give it a year and I suspect it will
> not seem so odd.  (In any case, amber-dev isn't the forum for syntax
> discussions, so let's leave this here.)

Just to clear the misunderstanding: I was not commenting on the "\{foo}",
I consider that a good thing (better than "${foo}" for sure, and "${foo}"
would not even be a compatible change). I was talking about the:
`STR."bla ${myVar} bla"`. As opposed to just calling the respective methods.

>
> > 2. The `TemplatedString` is more complicated than necessary. It is not
> > obvious by just looking at it, how to
> > implement a `TemplateProcessor`.
>
> Perhaps, but the ratio of people who *use* TemplateProcessor to those
> who *write* it is probably 1,000 to one or more.  And there are a lot of
> hidden requirements that have been sussed out as a result of writing not
> only the obvious processors, but some less common ones as well.  So what
> seems unnecessary to you may simply be that you are thinking of simpler
> use cases.

Technically, both can do the same (except that the current way sacrifices
a single character), and you might even provide such iterators, if you want
to with the effective `List<TemplatePart>`  way. Also true the other way around,
you could provide a `List<TemplatePart> getAllParts()` (or maybe better with
`Iterator`).

I know it might sound so, but I'm not trying to be nit picky. I'm
honestly curious
what is the benefit of the current way? Less memory usage?

>
> > 4. Last time I saw, the compiler generated a new class for each
> > `TemplatedString` instance
>
> You are aware there is a class generated per lambda / mref too, right?
> And yet no one is saying "Lambda translation is too heavy."  (There are
> also options available to improve the translation, but it's still early
> for that game.)

Sure, but there it is obviously needed. It was just very surprising to me,
that this was deemed more efficient. Though, I'm not too concerned about
this one, since this is not covered by the JEP, and can be changed even
after introducing it, and I'm sure eventually the more efficient way will win.
I was just surprised.


More information about the jdk-dev mailing list