PhobosV3+ Fundamental Elements

libxmoc libxmoc at gmail.com
Sun Aug 30 17:58:35 UTC 2026


On Sunday, 30 August 2026 at 10:10:21 UTC, Steven Schveighoffer 
wrote:
> On Thursday, 27 August 2026 at 22:39:04 UTC, Richard (Rikki) 
> Andrew Cattermole wrote:
>> One of the key design elements that is wanted, is to remove 
>> the requirement for templates where possible. Templates are 
>> expensive, especially if they are not needed to solve a 
>> problem.
>>
>> A notable example of this is the dispatch and handling of 
>> formatting to a string. There is unfortunately only one really 
>> good solution that has been come up with to date, and that is 
>> a single type that can be used for composition. It is also 
>> important for use cases like pretty printing to support 
>> removal of text, not just appending. The solution to this is 
>> to introduce a string builder, similar to C#'s that is not 
>> templated.
>>
>> To format a type using such a string builder would require the 
>> following signature for the hook method:
>>
>> ```d
>> struct Type {
>> 	void toString(scope StringBuilder) scope const;
>> }
>> ```
>
> I fully disagree with this. Templates are way way better. I 
> don't want to build strings, I want to have a type add itself 
> to a string stream. I want that stream to be defined however 
> you wish, and compile down to the fastest code possible. It 
> could just build a string if that's what you want.
>
> The place where this breaks down is virtual interfaces. But we 
> have a way to do this, already shown in 
> [Throwable.toString](https://dlang.org/phobos/object.html#.Throwable.toString.2).
>
> Is there a place where this discussion is happening other than 
> the forum? Why are we deciding to move away from templates? Why 
> do you consider them expensive, is it just the compile time?
>
> -Steve

C# doesn't have templates, so naturally Phobos v3 won't have 
templates either :^) (/s)

Jokes aside, I think you are both touching on real problems from 
opposite angles.

The issue with Phobos v2 is not templates, it's it was that they 
were abused to death.

Every other function was a template, for "problems" that didn't 
need them, leading to:

- Massive code bloat and binary sizes
- Compilation times that grow exponentially, visible just by 
importing std
- Error messages that require a PhD in template metaprogramming 
to decipher

I also agree with on the toString, D doesn't have the luxury that 
C# has: a JIT compiler.

As for Phobos v3 itself, I am personally skeptical, I fail to see 
what problem it tries to solve other than template bloat.

I personally think D doesn't need phobos at all, it would be 
better split and proposed as dub packages, leaving just a base D 
that's good enough to get going and port to other platforms.

I'd like to see druntime v2 (without libc/EH/GC and with a 
unified allocator API), than a phobos v3.





More information about the Digitalmars-d mailing list