DIP 1027---String Interpolation---Format Assessment
Walter Bright
newshound2 at digitalmars.com
Thu Feb 27 18:58:40 UTC 2020
On 2/27/2020 1:45 AM, Rainer Schuetze wrote:
> The string buffer could also be stack allocated or manually managed with
> malloc/free by the string interpolation type.
It's quite a big deal to make that work, and does not address the inherent
inefficiency of it.
printf, for all its faults, is very efficient, and one reason is it does not
require arbitrary temporary storage. Another is it does not require exception
handlers. I, for one, simply would not use such when printf is available.
People often overlook how *expensive* RAII is. Turn exception handling on and
have a look at the generated code.
It's a minor syntactic convenience with an unexpected large and hidden cost.
That's not what D is about.
Leave this at the user's discretion with:
f(format("hello %betty"));
where the user chooses via the format function which method of handling
temporaries he finds appropriate.
---
Note that the reason outbuffer.d has a printf member function is because it is
fast and efficient to format data directly into the output buffer rather than
going through a series of temporary strings first.
More information about the Digitalmars-d-announce
mailing list