Weird interaction of design choices: Duration + sum

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Oct 13 19:33:42 UTC 2017


On Friday, October 13, 2017 15:28:03 Steven Schveighoffer via Digitalmars-d 
wrote:
> On 10/13/17 3:24 PM, Steven Schveighoffer wrote:
> > On 10/13/17 3:11 PM, jmh530 wrote:
> >> On Friday, 13 October 2017 at 18:36:58 UTC, Luís Marques wrote:
> >>> [snip]
> >>
> >> What if it were package instead of private?
> >
> > This wouldn't help, sum is in phobos, Duration in druntime.
> >
> > The answer is that sum shouldn't be too clever. IMO, initializing to 0
> > should be only done if the type's .init value doesn't match 0. Since
> > only floating points and char/wchar/dchar do this, just do the Seed(0)
> > for those, else use Seed.init.
>
> I take the last part back a bit. Some custom types may default to
> NaN-like values, so Seed(0) is necessary.
>
> What should happen is that sum should test if Seed(0) is viable, and if
> not, use Seed.init.

The other advantage to that is that it wouldn't risk breaking anything (at
least, I don't think that it would), whereas even if Seed.init would work
for a type that accepted 0 with its constructor, the semantics might not be
the same, which could then break code if we just started using Seed.init for
those types.

- Jonathan M Davis




More information about the Digitalmars-d mailing list