Nullable or Optional? Or something else?

Rainer Deyke rainerd at eldwood.com
Thu Sep 10 11:11:55 PDT 2009


Steven Schveighoffer wrote:
> Why not?
> 
> private Optional!double cached_x;
> private bool cachex_valid;
> private Optional!double cached_y;
> private bool cachey_valid;

Because that's horribly non-orthogonal code.  I go by the rule that
whenever two pieces of data are more closely associated with each other
members of the enclosing data structure, then those pieces of data must
be factored out into their own data structure.  *Especially* if, as in
this case, the resulting data structure is reusable.

Ideally, the entire logic of calculating values on demand and then
caching them should be factored out, but that's a bit harder to do in
this case.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list