mixin identifiers concept
bachmeier
no at spam.net
Tue Feb 1 01:52:25 UTC 2022
On Monday, 31 January 2022 at 20:45:53 UTC, Paul Backus wrote:
> On Monday, 31 January 2022 at 07:19:49 UTC, bauss wrote:
>> I believe a DIP would be necessary, but to be honest I don't
>> see a reason for this.
>>
>> You can just do this which isn't really much less readable.
>>
>> ```d
>> static foreach (name; ["boo", "foo"])
>> {
>> mixin(`string file_%1$s =
>> readText("%1$s.txt");`.format(name));
>> }
>>
>> writeln(file_boo);
>> writeln(file_foo);
>> ```
>
> Using `std.format` for this incurs a substantial compile-time
> performance penalty--dozens of templates must be instantiated,
> memory must be allocated for CTFE, the format string must be
> validated, etc. If the mixin is inside a template which is
> itself instantiated many times, this overhead can really add up.
You have to balance that (which in the absence of benchmarks or
other empirical evidence is a theoretical problem) against the
horrendous cost in terms of complexity of the language. It's not
just the syntax - which would be a substantial burden for new
users - but also understanding the details of what it's doing.
It's hard to see this being worthwhile for only gains in
compilation time.
More information about the Digitalmars-d
mailing list