PhobosV3+ Fundamental Elements

Steven Schveighoffer schveiguy at gmail.com
Sun Aug 30 10:10:21 UTC 2026


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


More information about the Digitalmars-d mailing list