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

2021-01-15 Thread Basile B. via Digitalmars-d-learn
On Thursday, 14 January 2021 at 18:24:44 UTC, ddcovery wrote: I know there is other threads about null safety and the "possible" ways to support this in D and so on. [...] If it's not a bother, I'd like to know how you usually approach it [...] Thanks!!! I have a opDispatch solution here

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

2021-01-15 Thread Dukc via Digitalmars-d-learn
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

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

2021-01-15 Thread ddcovery via Digitalmars-d-learn
On Friday, 15 January 2021 at 14:25:09 UTC, Steven Schveighoffer wrote: On 1/15/21 9:19 AM, Steven Schveighoffer wrote: Something similar to BlackHole or WhiteHole. Essentially there's a default action for null for all types/fields/methods, and everything else is passed through. And now

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

2021-01-15 Thread ddcovery via Digitalmars-d-learn
On Friday, 15 January 2021 at 14:19:35 UTC, Steven Schveighoffer wrote: On 1/14/21 7:27 PM, ddcovery wrote: On Thursday, 14 January 2021 at 20:23:08 UTC, Steven Schveighoffer wrote: You could kinda automate it like: struct NullCheck(T) {    private T* _val;    auto opDispatch(string mem)()

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

2021-01-15 Thread Imperatorn via Digitalmars-d-learn
On Friday, 15 January 2021 at 14:25:09 UTC, Steven Schveighoffer wrote: On 1/15/21 9:19 AM, Steven Schveighoffer wrote: Something similar to BlackHole or WhiteHole. Essentially there's a default action for null for all types/fields/methods, and everything else is passed through. And now

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

2021-01-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/15/21 9:19 AM, Steven Schveighoffer wrote: Something similar to BlackHole or WhiteHole. Essentially there's a default action for null for all types/fields/methods, and everything else is passed through. And now reading the other thread about this above, it looks like this type is

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

2021-01-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/14/21 7:27 PM, ddcovery wrote: On Thursday, 14 January 2021 at 20:23:08 UTC, Steven Schveighoffer wrote: You could kinda automate it like: struct NullCheck(T) {    private T* _val;    auto opDispatch(string mem)() if (__traits(hasMember, T, mem)) {    alias Ret = typeof(() { return

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

2021-01-15 Thread ddcovery via Digitalmars-d-learn
On Thursday, 14 January 2021 at 18:24:44 UTC, ddcovery wrote: I know there is other threads about null safety and the "possible" ways to support this in D and so on. This is only an open question to know what code patterns you usually use to solve this situation in D I'm writing a

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

2021-01-14 Thread ddcovery via Digitalmars-d-learn
On Thursday, 14 January 2021 at 20:35:49 UTC, Dennis wrote: On Thursday, 14 January 2021 at 18:24:44 UTC, ddcovery wrote: If it's not a bother, I'd like to know how you usually approach it Usually I don't deal with null because my functions get primitive types, slices, or structs. `ref`

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

2021-01-14 Thread ddcovery via Digitalmars-d-learn
On Thursday, 14 January 2021 at 20:23:08 UTC, Steven Schveighoffer wrote: You could kinda automate it like: struct NullCheck(T) { private T* _val; auto opDispatch(string mem)() if (__traits(hasMember, T, mem)) { alias Ret = typeof(() { return __traits(getMember, *_val, mem);

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

2021-01-14 Thread ddcovery via Digitalmars-d-learn
On Thursday, 14 January 2021 at 19:24:54 UTC, Adam D. Ruppe wrote: 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: I'm almost never in this situation except for reading things

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

2021-01-14 Thread Dennis via Digitalmars-d-learn
On Thursday, 14 January 2021 at 18:24:44 UTC, ddcovery wrote: If it's not a bother, I'd like to know how you usually approach it Usually I don't deal with null because my functions get primitive types, slices, or structs. `ref` parameters can be used to replace pointers that may not be null.

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

2021-01-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/14/21 1:24 PM, ddcovery wrote: I know there is other threads about null safety and the "possible" ways to support this in D and so on. 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")

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

2021-01-14 Thread mw via Digitalmars-d-learn
On Thursday, 14 January 2021 at 18:24:44 UTC, ddcovery wrote: I know there is other threads about null safety and the "possible" ways to support this in D and so on. This is only an open question to know what code patterns you usually use to solve this situation in D:

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

2021-01-14 Thread Adam D. Ruppe via Digitalmars-d-learn
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: I'm almost never in this situation except for reading things like xml or json data that may be missing. So I just special