If you could make any changes to D, what would they look like?

IGotD- nise at nise.com
Wed Oct 20 17:55:05 UTC 2021


On Wednesday, 20 October 2021 at 17:27:45 UTC, jmh530 wrote:
>
> What is the benefit of different pointer types?
>
> If you have a function that takes a pointer but doesn't make 
> any allocations or anything, then you would need to have two 
> versions of it to work with each type. This introduces a 
> similar issue as what led to inout. It might make some kind of 
> generics with type erasure that can handle all of these cases 
> more useful.

Correct, that is the drawback with different pointer types, that 
you might need two implementations, one for pointers and one for 
reference types. Normally generics takes care of that pretty well.

The benefit is that references/fat-pointers enables operations 
under the hood that raw pointers don't allow. For example 
increasing/decreasing a reference count. If everything in 
Phobos/Druntime would use references instead of raw pointers 
where applicable, the a recompile would have enabled a complete 
change of the GC algorithm. Reference types enables more 
versatility.


More information about the Digitalmars-d mailing list