What were some of your biggest breakthroughs while learning D?

Paulo Pinto pjmlp at progtools.org
Wed Jul 7 12:49:34 UTC 2021


On Wednesday, 7 July 2021 at 00:13:44 UTC, SealabJaster wrote:
> On Tuesday, 6 July 2021 at 20:53:12 UTC, Dylan Graham wrote:
>> ...
>
> How any combination of UFCS, dynamic code generation and 
> introspection, shortened syntax for calling functions, the 
> ability to pass lambdas to templates (which can also be 
> completely inlined by the compiler without sacrificing on code 
> readability), etc can all be used to create and model code 
> almost exactly how you want it to.
>
> I very rarely feel constricted in D like I do in other 
> languages. There's pros and cons to that of course, but when I 
> feel like just tapping out something random, more often than 
> not I can match the code model to my mental model.
>
> e.g. the very existence of UDAs can allow for pretty natural 
> looking code:
>
> ```d
> @Command("command", "This is a command that is totally super 
> complicated.")
> struct ComplexCommand
> {
>     @CommandArgGroup("Debug", "Arguments related to debugging.")
>     {
>         @CommandNamedArg("verbose|v", "Enables verbose 
> logging.")
>         Nullable!bool verbose;
>
>         @CommandNamedArg("log|l", "Specifies a log file to 
> direct output to.")
>         Nullable!string log;
>     }
> }
> ```
>
> The above is *doable* in C#, but has to be done at runtime 
> (assume the same with JVM languages).

Not really, in Java you can do it with annotation processors and 
compiler plugins at compile time, whereas in C# you can do it 
with code generators or T4 templates.


More information about the Digitalmars-d mailing list