Rant: Date and Time fall short of simplicity in D
Jonathan M Davis
jmdavisProg at gmx.com
Fri Mar 29 12:22:19 PDT 2013
On Friday, March 29, 2013 10:03:31 Steven Schveighoffer wrote:
> On Fri, 29 Mar 2013 01:42:41 -0400, Andrej Mitrovic
> > sw.stop();
> >
> > TickDuration time = sw.peek();
> >
> > long secs = time.seconds;
> > long msecs = time.msecs - (1000 * secs);
> > long usecs = time.usecs - (1000 * msecs) - (1000 * 1000 * secs);
> >
> > writefln("secs: %s, msecs: %s, usecs: %s", secs, msecs, usecs);
> >
> > }
>
> This one is VERY annoying, Duration has some of the necessary properties.
> The sub-second values you must obtain with FracSecs, and once you get
> there, it does NOT give you properties which remove the higher units.
>
> So I can't really do this any better than you did.
Clearly, I need to take another look at FracSec then.
> core.time needs to be fixed. Duration is really what you should use when
> doing duration math. I don't know why TickDuration still exists actually.
I tend to agree. We _do_ need a separate time type which is in system ticks
for the monotonic clock, but the stopwatch stuff doesn't need to use it. I'd fix
it, but I don't know if we can do so without breaking code. I'll have to think
about it.
> 3. I HATE "safe" cast conversions. If you want to make a conversion, use
> a method/property. I don't even know why D allows overloading casting.
> Casts are way too blunt for this.
It's how you define coversions to work with std.conv.to, so you could do
to!DateTime(sysTime), which is shorter and avoids the explicit cast in your
code (though the cast still occurs within std.conv.to).
- Jonathan M Davis
More information about the Digitalmars-d
mailing list