Challenge: write a template-instance free dispatcher for text printing
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Wed May 27 16:44:56 UTC 2026
On 27/05/2026 6:33 PM, Atila Neves wrote:
> On Monday, 25 May 2026 at 15:19:51 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> I have a challenge for all to try!
>>
>> For Walter says templates must be avoided in some core code!
>>
>> So let's see if D can do it, but... There are two rules.
>>
>> 1. You cannot use ANY template instantiations to do the work itself
>>
>> 2. No string mixins!
>>
>> Both of these are expensive, and they need to go.
>
> What's expensive about string mixins?
That snippet of code, needs: new file name, lexed, parsed, create parse
tree, then semantic, then combined back into previous AST.
Versus: copy parse tree, run semantic, append to list.
Compared to the base line there is a lot of infrastructure being touched
that doesn't need to be if it was modelled by the language.
String mixins are fundamentally an escape hatch of last resort, and
should be audited for necessity. I generally class them in one of two
categories:
- Unnecessary evil and should be removed.
- Language needs to model it.
See tuples and bit fields for PhobosV2 as an example of the latter.
They also happen to encourage templates, which on top of the base line
create at a minimum one new symbol that may get emitted into the object
file.
So avoiding string mixins is a good thing for a library to do, at least
in hot code.
More information about the Digitalmars-d
mailing list