Hacker News new | ask | show | jobs
by _old_dude_ 886 days ago
You can not use the excuse of the backward compatibility twice.

If the string template is prefixed by a processor STR."foo" instead of "foo" then you do not need \{variable} instead of $variable.

2 comments

You don't want friction on the default path to be too low because that would inevitably increase the occurrence of default path where it must not be used, e.g. cause sql injections.

Much easier to accidentally write something that boils down to

   "\{bobby}" 
where it should have been

   SQL."\{bobby}"
than

   STR."\{bobby}"
instead of

   SQL."\{bobby}"
(i admit that this argument would work better if STR was typographically more different from the name you'd inevitably use for an SQL statement processor)
They want to ensure the new interpolation sequence is a compiler error in non-template strings, so that the incorrect “hi \{name}” is an error instead of silently doing the wrong thing. Using \{ accomplished this because it’s an unknown escape sequence in older Java (so forbidden there), and in new Java will have the more specific error of “yo you forgot the template processor at the start of your template”.
Yes, you do not get a compile time error, but visually a big STR is front is enough "${variable}" vs STR."${variable}"

And editors will use different colors.

Using \ or $ is not about backward compatibility but about ergonomics.