How to simplify nested ifs

drug drug2004 at bk.ru
Fri Mar 16 09:51:03 UTC 2018


On 16.03.2018 09:34, Satoshi wrote:
> On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote:
>> Hi
>>
>> I have a construction like the following
>>
>> if (source) {
>>   if (source.pool) {
>>     if (source.pool.repository) {
>>       if (source.pool.repository.directory) {
>>     if (source.pool.repository.directory.users) {
>>       // do something
>>
>> Any chance to simplify this nested ifs?
>> I know some languages has a way like.
>>
>> if (source?pool?repository?directory?users) // do something
>>
>>
>> Similar ways in D?
>>
>> Thanks and Regards, Ozan
>
> null conditional operators are not implemented in D because, as a (I
> think Walter) said, D is not language designed to work with classes or
> advanced OOP stuff. Nobody uses it, so please, if you are using it, stop
> and use structs and meta programming instead.

I think that null conditional operator is intended for OOP only. It's 
really useful if your data field may be nullable. May be start review 
about this?


More information about the Digitalmars-d-learn mailing list