3 ms·
How is it better? Just different, and using dollar sign adds another shift press.
by krzyk 3y ago
How is it better?
Just different, and using dollar sign adds another shift press.
- coldtea 3y ago>How is it better? Much more older and common use and association (even their own "Java EE Expression Language" uses it), and not confused with escaping a character (like \n, \t) etc. Pricinple of least surprise, avoiding NIH, and stuff.
- pron 3y ago> Much more older and common use and association (even their own "Java EE Expression Language" uses it) That was one of the main reasons not to use it; even in JS templating libraries use different syntax from that of the language's $ (see my other comment). > and not confused with escaping a character (like \n, \t) etc That would not be a confusion at all but the very point: \{ is just like \n or \t, i.e. gets a special interpretation rather than a literal one. > Pricinple of least surprise \ in Java is standard for that purpose (special interpretation in a literal); it is $ that is foreign. > avoiding NIH That is not so much of a principle, although it could be if the language was rejecting some otherwise universal choice, only that's not the case here at all. Of the other popular language with either a similar feature to Java's string templates or with string interpolation -- JS, Python, PHP, C#, and Ruby -- only JS and PHP use $ (and only PHP uses $ with the "shell" shortcut of $x). Or, if you only want to look at the "big three" -- JS, Python, and Java -- each has a different syntax from the other two, and only one uses $. Even if you look at all programming languages in the world, only a minority of programmers using a language with string templates and/or string interpolation use one where $ is used for the value syntax. Not only is it not a near universal choice, it's a minority choice.
- deleted 3y ago[deleted]
- usrusr 3y agoThe language spec is the only place able to introduce meaning to a source byte sequence starting with a backslash that has been invalid before (e.g. not double-backslash, or backslash-u). ${ on the other hand never been an invalid byte sequence inside a string literal, and was hence already used by many APIs. It's nothing but courteous by the language people to avoid avoidable collisions. Keep in mind that this new syntax is completely open to everybody else who might have a use case for strings-with-expressions, it's not like they are appropriating a previously blank spot for exclusive use.