Interpolated strings and SQL
Nickolay Bukreyev
buknik95 at ya.ru
Tue Jan 9 09:25:28 UTC 2024
On Tuesday, 9 January 2024 at 08:29:08 UTC, Walter Bright wrote:
> It happens at runtime.
No. This line is inside `enum string query = () { ... }();`. So
CTFE-performance considerations do apply.
> I'm sorry to say, that looks like tty noise.
That’s sad. In my opinion, it is at least as readable, plus I see
a few objective advantages in it. We don’t have to agree on this
though.
> It will rarely need to be escaped, but when one does need it,
> one needs it!
Yes, but I see a benefit in reducing the number of characters
that _have_ to be escaped in the first place. While `$` rarely
appeared in examples we’ve been thinking of so far, if someone
faces a need to create a string full of dollars, escaping them
all will uglify the string.
> DIP1027 does not require ( ) if it's just an identifier. That
> makes for the shortest, simplest
> istring syntax. The ( ) usage will be relatively rare. The idea
> is the most common cases should
> require the least syntactical noise.
Totally agree. Personally, I prefer omitting parentheses in
interpolations when a language supports such syntax, but it’s a
matter of taste.
> Also, the reason I picked the SQL example is because that is
> the one most cited as being needed
> and in showing the power of DIP1036 and because I was told that
> DIP1027 couldn't do it :-)
DIP1027 is unable to do it _at compile time_. I cannot argue that
compile-time string creation doesn’t give us much if we call an
SQL engine afterwards. So we need another example where
CTFE-ability is desired. Alexandru Ermicioi asked about logging;
I agree it is nice to rule out format-string parsing from every
`log` call.
More information about the Digitalmars-d
mailing list