I made std.time for Phobos, please review my code.

Steven Schveighoffer schveiguy at yahoo.com
Tue Apr 27 10:26:46 PDT 2010


On Tue, 27 Apr 2010 12:32:44 -0400, SHOO <zan77137 at nifty.com> wrote:

> Steven Schveighoffer さんは書きました:
>> On Tue, 27 Apr 2010 04:55:28 -0400, SHOO <zan77137 at nifty.com> wrote:
>>
>>> Tango is great library for D1. I am Tango user and I am indebted to
>>> Tango well. But Tango has some probrems.
>>>
>>> - Tango's license is BSD lisence or AFL. This license is incompatible  
>>> to
>>> Phobos's Boost license.
>>> - The specification is disregarded, for example Object.dispose and  
>>> string.
>>> - Tango supports only D1
>>> - In particular, deep regret is to have split resources of D into two
>>> halves.
>>>
>>> If possible, I want to migrate to D2. And I want to be separated from
>>> Tango. However, some functions are insufficient for Phobos compared  
>>> with
>>> Tango.
>>> The std.date module is one of the list of dissatisfaction to Phobos.
>>> I summarize my (and some of Japanese users's) opinion following:
>>>
>>> - I want to handle it as another thing for the time and the time span.
>>> - I want a more structural class for time operating.
>>> - std.date is a bit buggy...
>>>
>>> By these reasons, I made std.time module as the first step of the
>>> contribution for Phobos.
>>  I like what you've done.  It's very similar to what was done in  
>> Tango.  I hate to ask this, but I just want to verify that you did not  
>> base your code on Tango, especially since you have used Tango.  I was  
>> planning to implement a Time system for Tango that mimics Tango's  
>> design, if that is what you have done, I think that's perfectly legit.   
>> Basically, I want to verify that you rewrote all your implementation  
>> from scratch.
>
> I wrote it by own hand.
> But I referred to Tango, Phobos or some web site some interfaces and  
> physical quantities(The thing which becomes the same quantity even if  
> anyone calculates).
>
> Please point out the point where you noticed.

If you wrote it by your own hand and only used interfaces for guidance,  
then I think it is free and clear from copyright issues.  Thanks for  
clarifying!

>> More comments:
>>  I'd like accessors for seconds/milliseconds/etc from Span.
>
> For integer?
> I dislike that precision is cut off.
> You can get seconds with a real number in interval, or calculate by  
> ticks and TICKSPERSEC.

The internal storage is via integer, so if for example the integer number  
of milliseconds is desired, doing the calculation via converting to a  
floating point, and then scaling/truncating is inefficient, subject to  
floating point error, and more convoluted than it has to be.  I'd rather  
have an exact method that is as fast as possible, and is as simple as  
possible.  It is not too much extra to add these methods (they are pretty  
much boilerplate code).

Many existing C libraries and network protocols encode time via integers,  
so there is real need to be able to convert to these units, and to allow  
it with as little syntax as possible is good.

>> I'm not sure I like the Clocks structure.  Why have a separate Span  
>> that is in terms of some arbitrary OS resolution?  Can you give an  
>> example of why I'd want to use Clocks instead of Span?
>>  -Steve
>
> Clocks.TICKSPERSEC may have better precision than Span.TICKSPERSEC.
> Sacrificing precision in the middle of a calculation is MOTTAINAI.
> Clocks may be used for benchmarks or exact time measurement.

Ah, I didn't think that Clocks.TICKSPERSEC could have *better* resolution,  
that is a good benefit.

Then all that is left is the name, Clocks is not a good name for a value  
type entity.  It seems more suited for a static entity that contains  
clocks.  You already have defined interval, so that is out.  I can't think  
of anything good right now, but it definitely should not be a plural word.

This is a very solid library, very little to complain about!

One thing I would suggest if this is assimilated into druntime/phobos is  
that we split the Span functionality out into it's own module (or put it  
in object.di) so it can be used in druntime for things like Thread.sleep.

-Steve


More information about the Digitalmars-d-announce mailing list