Elegant D

Kapendev alexandroskapretsos at gmail.com
Mon Dec 8 10:33:17 UTC 2025


On Tuesday, 25 November 2025 at 02:04:59 UTC, Kapendev wrote:
> 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 like how this looks in my code :)
>
> ```d
> /// A generic 2D rectangle.
> struct GRect(P, S = P) if (P.sizeof >= S.sizeof) {
>     GVec2!P position; /// The position of the rectangle.
>     GVec2!S size;     /// The size of the rectangle.
>     // ...
> }
> ```

Here is one more elegant Dlang thing where you can use `with` and 
dtors to control an arena:

```d
auto arena = Arena(512);
with (ScopedArena(arena)) {
     make!char('C');
     with (ScopedArena(arena)) {
         make!short(2);
         make!char('D');
         assert(arena.offset == 5);
     }
     assert(arena.offset == 1);
}
assert(arena.offset == 0);
arena.free();
```

Mostly showing this because arenas are really cool and trendy 
right now :)


More information about the Digitalmars-d mailing list