Re: Nullable!T with T of class type

2018-06-28 Thread Jordan Wilson via Digitalmars-d-learn
On Thursday, 28 June 2018 at 19:22:38 UTC, Jonathan M Davis wrote: On Thursday, June 28, 2018 18:10:07 kdevel via Digitalmars-d-learn wrote: On Tuesday, 26 June 2018 at 21:54:49 UTC, Jonathan M Davis wrote: > [H]onestly, I don't understand why folks keep trying to put > nullable types in

Re: Nullable!T with T of class type

2018-06-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 28, 2018 19:45:52 kdevel via Digitalmars-d-learn wrote: > On Thursday, 28 June 2018 at 19:22:38 UTC, Jonathan M Davis wrote: > > Nullable makes sense in generic code, because the code isn't > > written specifically for them, but something like > > Nullable!MyClass in non-generic

Re: Nullable!T with T of class type

2018-06-28 Thread aliak via Digitalmars-d-learn
On Thursday, 28 June 2018 at 18:10:07 UTC, kdevel wrote: On Tuesday, 26 June 2018 at 21:54:49 UTC, Jonathan M Davis wrote: [H]onestly, I don't understand why folks keep trying to put nullable types in Nullable in non-generic code. How do you signify that a struct member of class type is

Re: Nullable!T with T of class type

2018-06-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 June 2018 at 19:22:38 UTC, Jonathan M Davis wrote: Nullable makes sense in generic code, because the code isn't written specifically for them, but something like Nullable!MyClass in non-generic code is pointless IMHO, because a class reference is already nullable. It is

Re: Nullable!T with T of class type

2018-06-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 28, 2018 18:10:07 kdevel via Digitalmars-d-learn wrote: > On Tuesday, 26 June 2018 at 21:54:49 UTC, Jonathan M Davis wrote: > > [H]onestly, I don't understand why folks keep trying to put > > nullable types in Nullable in non-generic code. > > How do you signify that a struct

Re: Nullable!T with T of class type

2018-06-28 Thread kdevel via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 21:54:49 UTC, Jonathan M Davis wrote: [H]onestly, I don't understand why folks keep trying to put nullable types in Nullable in non-generic code. How do you signify that a struct member of class type is optional?

Re: Nullable!T with T of class type

2018-06-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 26, 2018 19:03:20 kdevel via Digitalmars-d-learn wrote: > On Monday, 25 June 2018 at 22:58:41 UTC, Jonathan M Davis wrote: > > On Monday, June 25, 2018 19:40:30 kdevel via > > > > Digitalmars-d-learn wrote: > >> R r; > >> > >> if (r.s is null) > >> > >>throw new

Re: Nullable!T with T of class type

2018-06-26 Thread kdevel via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 14:32:59 UTC, Nathan S. wrote: On Monday, 25 June 2018 at 19:40:30 UTC, kdevel wrote: Is it possible to "lower" the Nullable operations if T is a class type such that there is only one level of nullification? Yes: https://run.dlang.io/is/hPxbyf template

Re: Nullable!T with T of class type

2018-06-26 Thread kdevel via Digitalmars-d-learn
On Monday, 25 June 2018 at 22:58:41 UTC, Jonathan M Davis wrote: On Monday, June 25, 2018 19:40:30 kdevel via Digitalmars-d-learn wrote: R r; if (r.s is null) throw new Exception ("some error message"); [...] Why can't this programming error be detected at compile time? If

Re: Nullable!T with T of class type

2018-06-26 Thread Nathan S. via Digitalmars-d-learn
On Monday, 25 June 2018 at 22:58:41 UTC, Jonathan M Davis wrote: Java does try to force you to initialize stuff (resulting in annoying false positives at times), but in general, it still can't guarantee when a variable is null or not and is forced to insert runtime null checks. Java can be

Re: Nullable!T with T of class type

2018-06-26 Thread Nathan S. via Digitalmars-d-learn
On Monday, 25 June 2018 at 19:40:30 UTC, kdevel wrote: Is it possible to "lower" the Nullable operations if T is a class type such that there is only one level of nullification? Yes: https://run.dlang.io/is/hPxbyf template Nullable(S) { import std.traits : isPointer,

Re: Nullable!T with T of class type

2018-06-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 25, 2018 19:40:30 kdevel via Digitalmars-d-learn wrote: > Just stumbled over the following design: > > class S {...} > > class R { > >Nullable!S s; > > } > > s was checked in code like > > R r; > > if (r.s is null) >throw new Exception ("some

Nullable!T with T of class type

2018-06-25 Thread kdevel via Digitalmars-d-learn
Just stumbled over the following design: class S {...} class R { : Nullable!S s; : } s was checked in code like R r; : if (r.s is null) throw new Exception ("some error message"); At runtime the following was caught: fatal error: caught