Hacker News new | ask | show | jobs
by coltonweaver 889 days ago
Edit: This comment was written when the original comment was just "Would it hurt them to use ${x} instead of \{x}?"

This is covered in the article under "Alternatives", in the section beginning with:

> For embedded expressions in string templates, we considered adopting the ${...} syntax from the Java EE Expression Language (EL) rather than \{...}. However, this would force developers to escape every $ sign in the literal text of a string template while continuing to write $ without escapes in string literals and text blocks. This inconsistency could all too easily lead to errors.

...

> With the syntax we have chosen, frameworks can ease migration by providing a template processor that understands EL syntax. Developers can continue using ${...} while also having access to the Java environment via \{...}:

1 comments

>However, this would force developers to escape every $ sign in the literal text of a string template while continuing to write $ without escapes in string literals and text blocks.

The other side is that now they'll make them think they can also write \{foo} in string literals and text blocks, and they'll find out it doesn't work.

I would assume that will keep being a compilation error.

It also seems to be a very "think of the morons" point to raise.

Correct, this example is also in the JEP:

  String name = "Joan";
  String info = "My name is \{name}";
  | error: processor missing from template expression