Elegant D

Dom Disc dominikus at scherkl.de
Wed Nov 26 23:53:57 UTC 2025


On Tuesday, 25 November 2025 at 01:18:21 UTC, Walter Bright wrote:
> I've been thinking about writing an article about what makes D 
> an elegant language to program in. D is indeed an elegant 
> programming language.
>
> I'm interested in anecdotes, experiences and examples of 
> Elegant D to incorporate!

I love to be able to do this:

```d
/// calculate product inplace and return the high bits
/// thanks to a little bit assembler, this is really fast
ulong mulx(ref ulong a, ulong b, ulong c) @safe pure nothrow @nogc
{
    a *= b; // the high bits of this multiplication are in RDX
    a += c; // and the carry of this addition in the carry flag
    asm @trusted pure @nogc nothrow
    {
       adc RDX, 0;   // add the carry to the high bits
       mov RAX, RDX; // and move them to the return value
       ret;          // thats it
    }
}

ulong mul(ulong[] a, ulong b, ulong c =0) @safe pure nothrow @nogc
{
    foreach(i; 0..a.length) c = mulx(a[i], b, c);
    return c;
}
```

And get the same performance as if the whole function would be 
written in fully optimized assembler as it is necessary in C or 
C++.


More information about the Digitalmars-d mailing list