I love D

Vitaliy Fadeev vital.fadeev at gmail.com
Tue Sep 19 04:43:25 UTC 2023


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

I like foreach.
I like templates.
I like ranges.

Just look at this SDL event pool implementation:

```d
         foreach( e; pool )
             process( e );
```

I love short text blocks, like this:

```d
// using pool
struct Game
{
     static
     Pool    pool;
     Sensors sensors;

     void go()
     {
         foreach( d; pool )
             sensors.sense( d );
     }
}
```

Nice:

```d
void main()
{
     game.go();	
}
```

I love structured types, like this:

```d
// event pool
import bindbc.sdl;
import types;


struct Pool
{
     D front;

     void popFront()
     {
         if ( SDL_WaitEvent( cast( SDL_Event* )&this.front ) == 0 )
             throw new SDLException( "Pool.popFront: " );
     }

     bool empty()
     {
         return ( front.type == SDL_QUIT );
     }

     void opOpAssign( string op : "~" )( SDL_EventType t )
     {
         SDL_Event event;
         event.type = t;
         SDL_PushEvent( &event ); // The event is copied into the 
queue.
     }
}

```



More information about the Digitalmars-d mailing list