August 29

On Friday, 29 August 2025 at 02:48:21 UTC, H. S. Teoh wrote:

>

On Fri, Aug 29, 2025 at 01:52:59AM +0000, Lance Bachmeier via Digitalmars-d-learn wrote:

>

On Thursday, 28 August 2025 at 18:47:19 UTC, Brother Bill wrote:

>

It seems like 'templates' are the 'Achilles heel' of D.

Without starting a flame war, has D gotten to the point where ordinary mortals have difficulty coding in D with 'templates' such as 'cycle' requiring rewrites into 'myCycle'?

Templates are in general a horrible way to program. Therefore I don't use them very much. When I do, I don't do anything complicated. But everyone has their opinion on that. I similarly don't use attributes. I prefer simple code with a simple language. Hard to avoid ranges in Phobos, which can be crazy complex/inconvenient at times, but every language has its warts.
[...]

Interesting how opinions differ on this. :-D I couldn't live without templates. I might be tempted to quit D if I couldn't use templates... ;-) but OTOH there are times when templates are overused where they aren't actually needed.

Templates are obviously useful in a lot of cases, but I don't consider them fun to read.

Another thing I don't like is that functions like foo(T)(T x) throw away relevant information. Then you decide to use a template constraint, you read the code, and you realize it's better to write out stubs for the relevant argument types instead.

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. Now, if someone's coming from C++, the story is different because templates are just how you do it when you're writing C++. He who writes the most generic code is the king in that world.

August 29

On Friday, 29 August 2025 at 04:52:26 UTC, Sergey wrote:

>

On Friday, 29 August 2025 at 02:48:21 UTC, H. S. Teoh wrote:

>

Interesting how opinions differ on this. :-D I couldn't live without templates. I might be tempted to quit D if I couldn't use templates... ;-) but OTOH there are times when templates

You probably gonna like comptime in Zig

Is Zig usable? Or is it still a half-done project that the zealous users tell people to use?

August 29

On Friday, 29 August 2025 at 02:48:21 UTC, H. S. Teoh wrote:

>

Interesting how opinions differ on this. :-D I couldn't live without templates. I might be tempted to quit D if I couldn't use templates... ;-) but OTOH there are times when templates are overused where they aren't actually needed.

I use templates for simple things C# style: collections and allocators; real code is nontemplated.

August 31

On Thursday, 28 August 2025 at 21:51:23 UTC, monkyyy wrote:

>

On Thursday, 28 August 2025 at 21:33:27 UTC, Brother Bill wrote:

>

The 'old book' pdf seems to be the most current approach, and it should only be about 3 years old.

Its not even close to only 3 years old, it mayve been updated some but its like 15 years old

From Programming in D PDF:

Programming in D
D version: 2.098.1
Book revision: 2022-02-21 1
The most recent electronic versions of this book are available online 2.
Copyleft (ɔ) 2009-2022 Ali Çehreli

6 days ago

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:

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

Insane way to do things:

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...
}
6 days ago

On Monday, 1 September 2025 at 12:20:02 UTC, Kapendev wrote:

>

Insane way to do things:

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...
}

I don't know other languages which like more insanity than D :)

6 days ago

On Monday, 1 September 2025 at 12:20:02 UTC, Kapendev wrote:

>

Insane way to do things:

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...
}

This example is actually an issue very specific to constructors, which cannot be overloaded if templatized. Non-ctor functions can be both overloaded and templatized.

I think the D style to prevent that is to use "static factories", i.e thanks to a global function you prevent the problem of having both template constraints and static ifs.

6 days ago

On Monday, 1 September 2025 at 13:37:11 UTC, user1234 wrote:

>

On Monday, 1 September 2025 at 12:20:02 UTC, Kapendev wrote:

>

Insane way to do things:

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...
}

This example is actually an issue very specific to constructors, which cannot be overloaded if templatized. Non-ctor functions can be both overloaded and templatized.

I think the D style to prevent that is to use "static factories", i.e thanks to a global function you prevent the problem of having both template constraints and static ifs.

Wrong, now I remember what is the issue I thought about... it is that you cannot explicitly instantiate a templatized ctor... as there are not named (they is the workaround sub mentioned however).

1 2 3
Next ›   Last »