Is D painted into a corner?

Kapendev alexandroskapretsos at gmail.com
Mon Sep 1 12:20:02 UTC 2025


On Friday, 29 August 2025 at 18:44:00 UTC, Lance Bachmeier wrote:
> Classic D code includes types like Matrix!double when you could 
> just use DoubleMatrix.
>
> They're like macros in Lisp. Powerful in principle but 
> routinely a PITA when you actually use them.

Sane way to do things:

```d
struct Matrix(T) {
     this(Blah blah) {
         // Blah blah...
     }
     // Just more functions...
}
```

Insane way to do things:

```d
struct Matrix(R, C, T, bool canFly, bool isCute) if 
((isNumberType!T || isMathType!T) && isGoodType!T && 
isMagicType!T) {
     static if (canFly) {
         this(Blah blah) {
             // Blah blah...
         }
     } else static if (isCute) {
         this(Blah blah) {
             // Blah blah...
         }
     } else {
         // Blah blah...
     }
     // Just more template hell...
}
```


More information about the Digitalmars-d-learn mailing list