Open question: what code pattern you use usually for null safety problem

Dukc ajieskola at gmail.com
Fri Jan 15 18:07:17 UTC 2021


On Thursday, 14 January 2021 at 18:24:44 UTC, ddcovery wrote:
> This is only an open question to know what code patterns you 
> usually use to solve this situation in D:
>
>   if(person.father.father.name == "Peter") doSomething();
>   if(person.father.age > 80 ) doSomething();
>
> knowing that *person*, or its *father* property can be null
>

Probably the incremental check solution. A helper function if I 
find myself doing that more than two or three times.

On the other hand, I don't have to do this that often. I usually 
design the functions to either except non-null values, or to 
return early in case of null.




More information about the Digitalmars-d-learn mailing list