On Monday, 7 December 2015 at 15:13:31 UTC, Meta wrote:
On Monday, 7 December 2015 at 11:40:45 UTC, Martin6265 wrote:
Hello,
I think nullable condition operator and null coalescending operator should be a nice new features in D.

https://msdn.microsoft.com/library/dn986595.aspx
https://msdn.microsoft.com/library/ms173224.aspx

Same as operator `as`
https://msdn.microsoft.com/library/cscsdfbt.aspx

Why?
Is better to write
(variable as FooBar)?.callMethod();

than
auto var = cast(FooBar)variable;
if (var !is null)
var.callMethod();


or
auto x = (variable as FooBar)?.getRandomNumber() ?? 42;

As per Rumbu's link, D is powerful enough to implement this in a library function, and have it optimize down to a set of if-else statements.

But the syntax of it will be like calling template func, and its not desirable. The trick is in the simplicity of the pattern not only in functionality.

Look, Im developing multiplatform GUI framework (based on .NET conventions and Cocoa) & ID. I can make my custom version of D (anyway, Ill distribute it as a one package product) but Im not happy to make new, uncompatibile version.

Reply via email to