I love D

IchorDev zxinsworld at gmail.com
Thu Sep 21 17:49:38 UTC 2023


On Tuesday, 19 September 2023 at 04:34:30 UTC, Vitaliy Fadeev 
wrote:
> Just know this.

One thing I really love, personally, is how expressive you can 
get with APIs in D.
In C I expect stuff like this:
```c
/*
  bla bla ... is deprecated and should not be used ... bla bla
*/
void run(const Data* val, unsigned char* msg, const void* usr);
```

Whereas, in D I can write:
```d
deprecated("should not be used ... bla bla")
noreturn run(U)(scope const(Data)* val, string msg, in U usr) 
nothrow pure;
```
(without `-preview=in`: swap `in` for `auto ref const`)

The specificity that D offers, particularly with `pure`, and 
`scope`, and `scope`'s derivatives, becomes really useful when 
you have to declare a public API with interfaces & classes. You 
can make sure that when you call something inheriting from a 
public interface that the call won't have side-effects, or that 
the foreign function won't store a pointer passed to it (that it 
doesn't own) anywhere.


More information about the Digitalmars-d mailing list