Elegant D

Richard Andrew Cattermole (Rikki) richard at cattermole.co.nz
Tue Nov 25 04:09:05 UTC 2025


1. External import path, make dllimport very easy without any 
warnings.

     ``$ ldc2 -oflibrary.dll -shared library/lib.d 
--fvisibility=public``

     ``$ ldc2 -extI library --dllimport=externalOnly main.d 
library.lib``

     ```d
	module lib;

     int var = 2;
     ```

     ```d
     module main;
     import lib;
     import std.stdio;

     void main() {
         writeln(var);
     }
     ```

2. Vector array ops make SIMD simple with ldc:
     Instead of going to these lengths: 
https://salykova.github.io/gemm-cpu

     You can write:

     ```d
     void kernel4(ref float[16] o, ref const float[16] a, ref 
const float[16] b, ref const     float[16] c) {
         o[] = b[] * a[];
         o[] += c[];
     }
     ```

     Needs https://github.com/ldc-developers/ldc/issues/4991 fixed 
to get the benefit of avx512vl.

3. Unittests add ddoc comment, and now it's an example

4. You don't have to rely on the signal handler to handle a 
segfault appropriately. You can also catch some really stupid 
problems at compile time too!

     ``dmd -preview=fastdfa main.d``

     ```d
     module main;

     void func(int* ptr) {
         int val = *ptr;
     }

     void main() {
         func(null);
     }
     ```

     No attributes required! All inferred.

     If that is not enough, you can use the null check to catch 
problems before they have a chance to infect a task and cause you 
problems. But alas that is waiting on a review from you Walter: 
https://github.com/dlang/dmd/pull/22040

     The elegance here is you don't have to infect your code with 
attributes and you will be able to get mostly protected that you 
can catch problems. Also allows for quicker turn around times.

5. opCast!bool can be used for error handling / to test the 
presence of a value with if statement



More information about the Digitalmars-d mailing list