D community's view on syntactic sugar

Nick Sabalausky (Abscissa) SeeWebsiteToContactMe at semitwist.com
Sat Jun 23 05:59:27 UTC 2018


On 06/20/2018 05:44 PM, Kamil Koczurek wrote:
> On Saturday, 16 June 2018 at 02:44:04 UTC, Jonathan M Davis wrote:
>>> * The null conditional operator `?.`
>>
>> It's been discussed before, and maybe we'll get it or something like 
>> it at some point, but it really wouldn't help much with idiomatic D. 
>> The average D program does a _lot_ less with classes than a language 
>> like C# does. Most stuff is done with structs on the stack - 
>> especially with range-based programming. That's not to say that 
>> certain types of programs couldn't benefit from such syntax, but it's 
>> going to be a lot less common than it is with C#. But it's also pretty 
>> trivial to write a helper function that does the same thing if you 
>> really want a short-hand way to do it.
> 
> That's not the only use case. Recently I'm using Algebraic pretty often 
> and I really wish that this would work: alg.peek!AThing?.method();

That is a good point, however, it could (and has been) be argued that 
Phobos's Algebraic is a sub-optimal design to begin with. For example, 
see these alternatives which cleanly eliminate the need for ".peek":

https://github.com/s-ludwig/taggedalgebraic
https://github.com/pbackus/sumtype

Although, granted, there's still Variant...

(But in any case, I'd still like to see null conditional operator in D 
anyway. It may not be applicable in a lot of idiomatic D code, but that 
doesn't mean it wouldn't be useful and worth having.)


More information about the Digitalmars-d mailing list