dao icon indicating copy to clipboard operation
dao copied to clipboard

Compile-time-controlled string interpolation

Open Night-walker opened this issue 10 years ago • 2 comments

It is frequently needed to embed values into a string template. string::expand(), .replace() or str.format() are just not convenient enough; besides, they offer no compile-time checks. And manual concatenation with casting is way too cumbersome.

Earlier, there was string embedding, as I called it, for verbatim strings. It was deemed redundant -- well, I think it is indeed so in case of verbatim strings. But ordinary strings would benefit greatly from such embedding/interpolation. As an example, Ceylon uses double backquotes for it, and Swift utilizes \(...) escaping.

Any type which supports casting to string could be used with such feature, obviating the need to use string::expand(), string streams or any similar stuff here.

Night-walker avatar Sep 11 '15 10:09 Night-walker

besides, they offer no compile-time checks.

Do you have any specific examples, where compile-time checks make sense? I can hardly imagine I would leverage it, because all my work with strings is in runtime (with the minor exception of constant values and expressions).

In general, I like the overloaded / operator, but don't see any firm reason to have string interpolation (I'm not afraid of manual concatenation and using it a lot).

dumblob avatar Sep 11 '15 16:09 dumblob

Do you have any specific examples, where compile-time checks make sense?

They always make sense to prevent mismatch in the number of arguments or their types, names, etc. Obviously, detecting that kind of errors at compile time saves time and nerves.

In general, I like the overloaded / operator, but don't see any firm reason to have string interpolation (I'm not afraid of manual concatenation and using it a lot).

The reason is as good as any -- write simpler and nicer code instead of ugly and clunky one.

Night-walker avatar Sep 11 '15 22:09 Night-walker