TickDuration deprecation

Rumbu rumbu at rumbu.ro
Sun Nov 19 17:56:37 UTC 2017


On Sunday, 19 November 2017 at 17:26:04 UTC, Jonathan M Davis 
wrote:

> Duration doesn't have any ticks. As its documentation states, 
> it holds its time internally in hecto-nanoseconds. Its total 
> function can be used to convert the entire Duration to whatever 
> units you want:
>
> https://dlang.org/phobos/core_time.html#.Duration.total
>
> whereas its split function allows you to split it into whatever 
> units you want:
>
> https://dlang.org/phobos/core_time.html#.Duration.split
>
> And simply converting a Duration to a string prints out the 
> units with them split out in a human readable manner. e.g.
>
>     writeln(usecs(502397292));
>
> would print
>
> 8 minutes, 22 secs, 397 ms, and 292 μs
>
> https://dlang.org/phobos/core_time.html#.Duration.toString
>
> Subtracting MonoTimes specifically gives a Duration rather than 
> a TickDuration or anything else representing the number of 
> ticks, because you don't normally care about the number of 
> ticks, and its cleaner to have only one duration type. Anyone 
> who wants the number of ticks would have to use MonoTime's 
> ticks property to get at them and then subtract those directly.
>
> So, anything holding the monotonic time now uses MonoTime to 
> hold the times and gives the length of time as a Duration.
>
> - Jonathan M Davis

Thank you Jonathan for the effort of explaini g, better put all 
this in the docs. Believe me, total is not the first word that 
comes to my mind when I want to use a conversion. More than that, 
total is documented on another page. The documentation is lost in 
details like internal representation (I don't care), mono time (I 
don't even want to know what is this), operators (I don't see the 
point of documenting internals) instead of highlighting the main 
usage.

Now put yourself in the user's shoes. You had something like 
x.usecs in your code, now you get a deprecation message.

You resolve the deprecation, but the compiler complains:

On Sunday, 19 November 2017 at 17:26:04 UTC, Jonathan M Davis 
wrote:

> Duration doesn't have any ticks. As its documentation states, 
> it holds its time internally in hecto-nanoseconds. Its total 
> function can be used to convert the entire Duration to whatever 
> units you want:
>
> https://dlang.org/phobos/core_time.html#.Duration.total
>
> whereas its split function allows you to split it into whatever 
> units you want:
>
> https://dlang.org/phobos/core_time.html#.Duration.split
>
> And simply converting a Duration to a string prints out the 
> units with them split out in a human readable manner. e.g.
>
>     writeln(usecs(502397292));
>
> would print
>
> 8 minutes, 22 secs, 397 ms, and 292 μs
>
> https://dlang.org/phobos/core_time.html#.Duration.toString
>
> Subtracting MonoTimes specifically gives a Duration rather than 
> a TickDuration or anything else representing the number of 
> ticks, because you don't normally care about the number of 
> ticks, and its cleaner to have only one duration type. Anyone 
> who wants the number of ticks would have to use MonoTime's 
> ticks property to get at them and then subtract those directly.
>
> So, anything holding the monotonic time now uses MonoTime to 
> hold the times and gives the length of time as a Duration.
>
> - Jonathan M Davis

Thank you Jonathan for the effort of explaini g, better put all 
this in the docs. Believe me, total is not the first word that 
comes to my mind when I want to use a conversion. More than that, 
total is documented on another page. The documentation is lost in 
details like internal representation (I don't care), mono time (I 
don't even want to know what is this), operators (I don't see the 
point of documenting internals) instead of highlighting the main 
usage.

Now put yourself in the phobos user's shoes.  You had something 
like sometickdurationresult.usecs in your code, now you get a 
deprecation message.

I skip the part where I must write now my own benchmarkig 
functions because someone had the brilliant idea to deprecate 
them too (why?).

Finally, you resolve the deprecation, but the compiler throws an 
error like this:

core.time.dur!"usecs".dur (long length) is not callable using 
argument types (Duration)

Based on the error above, how in the world can I deduce that I 
must use something like "total"?

Note: I understood what happens, I'm just playing the devil's 
advocate here :)




More information about the Digitalmars-d mailing list