I don’t disagree.

After some more pondering, while text blocks and string literals clearly have a lot of overlap - e.g. they both end up being String objects, that’s not the case with string templates.

So, if the following assignment fails:

|String s = "foo \{bar}"; |

One might argue that perhaps the syntax should be “more obviously different”.

Maurizio

On 13/03/2024 14:48, Archie Cobbs wrote:

Consider how we handle float vs. double literals. They overlap for 32-bit values, which is very convenient, but you can also "force" a narrower interpretation by adding an "f" suffix. That seems like pretty much the best of both worlds to me.

So is this an analogous situation? Then we'd allow a StringTemplate literal to have an /optional/ "$" prefix:

obj.takingString("abcd");             // ok - string
obj.takingTemplate("abcd"); // ok - template
obj.takingStringOrTemplate($"abcd"); // ok - template
obj.takingStringOrTemplate("abcd"); // ok - string or template (personally I don't care)
obj.takingString($"abcd"); // fail
obj.takingTemplate($"abcd"); // ok - template
obj.takingString("x = \{var}"); // fail
obj.takingTemplate("x = \{var}"); // ok - template

Reply via email to