D community's view on syntactic sugar
Jacob Carlborg
doob at me.com
Thu Jun 21 09:57:25 UTC 2018
On 2018-06-16 04:44, 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.
There's code in the DMD front end which screams for this operator.
The AST is built out of classes. It uses virtual functions to do down
casting, i.e.
class Statement
{
ForStatement isForStatement()
{
return null;
}
}
class ForStatement : Statement
{
ForStatement isForStatement()
{
return null;
}
}
Statement s;
if (auto f = s.isForStatement) { f. ... }
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list