What is your favorite D feature?

Ecstatic Coder via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 21 23:27:11 PDT 2017


Lack of verbosity.

Clear concise code, thanks to the automatic initialization of 
class members, native strings/arrays/maps/slices, UFCS, 
declaration-order independence, etc.

class TOTO
{
     bool IsCool;
     int Age;
     TUTU[] Tutus;
     TOTO[string] Totos;

     void Foo( TUTU tutu )
     {
         Tutus ~= tutu;
         Totos[ tutu.Name ] = tutu.Toto;
     }
}

class TUTU
{
     string Name;
     TOTO Toto;

     this( string name )
     {
         Name = name;
         Toto = new TOTO;
     }
}

void Bar(
     ref TOTO toto
     )
{
     toto.IsCool = !toto.IsCool;
}

void main()
{
     TUTU tutu;
     TOTO toto;

     tutu = new TUTU( "tutu" );

     toto = new TOTO;
     toto.Foo( tutu );
     toto.Bar();
}

Absolutely no syntactic noise !!!

This is often overlooked, while D easily beats all its direct 
competitors (C++, Java, C#, etc) on that point.

Just try to implement the same code as simply in C++ and you will 
be convinced that this is D's strongest feature...

And this is also what makes D feel like a super-powered 
JavaScript when I use it :)



More information about the Digitalmars-d mailing list