Safe Navigation Operator “?.” for D2 ?

Chris Williams yoreanon-chrisw at yahoo.co.jp
Thu Feb 27 09:25:20 PST 2014


On Thursday, 27 February 2014 at 17:02:02 UTC, Robert Clipsham 
wrote:
> On Thursday, 27 February 2014 at 16:32:18 UTC, Chris Williams 
> wrote:
>> On Thursday, 27 February 2014 at 16:08:26 UTC, Robert Clipsham 
>> wrote:
>>> D doesn't need this, you can implement monadic null checking 
>>> in the library:
>>
>> By that argument, I can implement anything that D can do in 
>> assembler, hence I don't need D.
>
> I'm not sure I understand your point. I'm simply stating that 
> in D, right now, without adding any complexity to the language, 
> you can do:
>
> just(myObject).method1().method2().method3()

You can't do that. You're reducing your example code - which was 
several dozen lines and only applied to objects for which you had 
added the special handler code - to the end result. After you've 
laid the framework for doing this, yes, you can do it. But 
there's a bunch of work that has to go into it before you get to 
that point. (Also, your implementation is far less efficient than 
something which rewrites the code as a bunch of nested "if (not 
null)" checks.)

If your argument was that there are more important things for the 
compiler team to work on, or that the syntax of the language was 
already large enough without adding more things for people to 
remember, then sure. But if we lived under the premise that 
there's no reason to add features to a compiler that abstract 
code down into a simpler syntax, then we'd have never developed 
variables or functions.


More information about the Digitalmars-d mailing list