On Tue, Nov 06, 2001 at 12:55:29PM +0300, Alexander V. Lukyanov wrote:
> > 
> > I'm still confused as to the point of a "difference of time" class; what
> > is gained?  Time is an amount of time (and acts as time of day using the
> > standard epoch paradigm, storing time in terms of "amount of time".)
> 
> Time+TimeDiff is a time since epoch, Time+Time is not defined. That's the main
> difference. Other difference is in the name, TimeDiff underlines that it is
> not a time but amount of time.

Strictly speaking, it's clearly defined.  Time is the amount of time
since epoch; Time + Time is the sum of both times since the epoch.
(It's defined; it's just not useful, and in practice it'll overflow.)
Likewise, other operations work for both: interval * int (ie. 10 seconds
* 2) works the same for time since epoch; again, it's just not useful.

The only thing to gain from making two classes is preventing operations
that probably aren't intended (the above) from being done accidentally.
But, in practice, I've never seen that happen, and it's almost always
painfully obvious if it's done accidentally (ie. things will break
quickly.)  Is it worth going to lengths to prevent something that rarely
happens?

If you just want names, typedef them; that way they're still
type-compatible.

> Of course Time and TimeDiff can be encoded in time_t and an int, but this
> does not make them equivalent. Maybe a lower level base class would be
> useful here.

I'll restate my definition; if yours are different, let me know:

A time_t is an interval of time.  (This is implicitely used in many--but
not all--places to *represent* a time of day, but the actual value stored
is, in fact, an interval of time.)

This applies to Time, which is a time_t with a fractional portion.

> > Since Time is always an amount of time, that makes TimeDiff confusing--a
> > data type that's effectively the difference of two numbers?  That's like
> > having separate (incompatible) time_t and time_diff_t data types, or int
> > and int_diff.  (Same thing, the latter just shows the problem more clearly.)
> 
> Would you argue that no classes consisting of a single int are needed?

No (think member function grouping), but that wasn't the point.  (I'm
using comparable examples that aren't classes for simplicity.)  Based
on the above definition ("class Time is an interval of time"),
"Time - Time" is also an interval of time--so they're the same type with
different names.

If you really want this, I might suggest the derived class idea.  (I'll
have to think about it a bit more ...)  class TimeBase, class TimeInter,
class TimeOfDay.  (I recommend TimeInter over TimeDiff; it's really an
interval.  You can form a time interval explicitely, by multiplying
another interval by a scalar, etc; I wouldn't associate classes with single
operations.  Avoiding "TimeInt" to avoid confusion with "int".)  The penalty
is a vptr; minor, since we don't carry around tons of times.

(Sorry for being a pest. :)

-- 
Glenn Maynard

Reply via email to