Tuples, CTFE, and Sliding Template Arguments

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Jan 14 03:09:23 UTC 2024


On Saturday, January 13, 2024 10:12:14 AM MST Steven Schveighoffer via 
Digitalmars-d wrote:
> The compiler is *required* to parse out the parameters. It has,
> sitting in it's memory, the list of literals. Why would it
> reconstruct a string, with an arbitrarily decided placeholder,
> that you then have to deal with at runtime or CTFE? You are
> adding unnecessary work for the user, for the benefit of hooking
> `writef` -- a function *we control and can change to do whatever
> we want*.
>
> The SQL example *DOES NOT* generate a format string, I've told
> you this multiple times. It generates a string with placeholders.
> There is no formatting. In fact, the C function doesn't even
> accept the parameters, those happen later after you generate the
> prepared statement.
>
> But also, SQL requires you do it this way. And the C libraries
> being used require construction of a string (because that's the
> API C has). An sql library such as mysql-native, which is fully
> written in D, would not require building a string (and I intend
> to do this if string interpolation ever happens).
>
> Things other than SQL *do not require building a string*.

To be honest, this is the only part of the string interpolation proposals
that seems even vaguely desirable to me. I absolutely hate their syntax in
comparison to just calling format. IMHO, it's extremely hard to read strings
with variables put into the middle of them, whereas format allows you to see
the string's contents with minimal interference from what's going to be
inserted into it (and when the interference is greater, it's because you're
doing something fancier than %s, and you need to be doing something that
you're not gonig to be doing with string interpolation anwyay). Obviously,
that's a very subjective thing, but given that I hate the syntax, string
interpolation would need to provide an actual technical benefit for it to
have any value for me.

So, if the string interpolation produces information for the function being
called in a manner that lets it see all of the individual pieces and what
their types are such that it can do whatever is appropriate with that
information rather than necessarily dealing with a format string that it has
to parse, then there's value in that. I question that it's worth the
terrible syntax, but at least it is providing some technical benefit at that
point rather than just a different syntax to produce format strings. IMHO,
if you're just going to create a format string out of the deal, then I see
no value over calling format (though obviously, there's some disagreement on
that or string interpolation wouldn't have even been proposed in the first
place.

Of course, ultimately, I'm not sure that it matters much to me what the
exact specification for interpolated strings is if they make it into the
language, since I'd rather simply never have to deal with them, but if we're
going to get them, I would hope that they would at least provide a technical
benefit rather than just a different syntax that some folks think is an
improvement.

- Jonathan M Davis





More information about the Digitalmars-d mailing list