Re: [web-animations] NaN vs null to represent unresolved / invalid times

On Tue, Jul 8, 2014 at 5:58 PM, Brian Birtles <bbirtles@mozilla.com> wrote:
> Hi,
>
> Currently Web Animations uses null to represent time values that are somehow
> invalid or unresolved.
>
> For example, if an animation is not attached to a player, its local time
> will be null to indicate that it's not playing and nor does it have any
> intention of doing so.
>
> Likewise, an animation timeline that is not yet ready to play can return
> null for its current time to distinguish between a timeline that has just
> begun and one that is somehow inactive.
>
> However, this can be problematic if application code has, e.g.
>
>   var timeRemaining =
>      animation.computedTiming.activeDuration -
>      animation.computedTiming.localTime;
>
> since localTime, if null, will be treated as 0 giving the wrong result
> (particularly when startTime != 0).
>
> I'm thinking, therefore, that we should use NaN across the board to
> represent unresolved/invalid times.
>
> So
>      readonly double? localTime
> becomes
>      readonly unrestricted double localTime
>
> It probably makes sense to update the timing model description to refer to
> generic "unresolved" values (SMIL does this, by coincidence) and convert
> them to NaN at the interface.
>
> Any thoughts?

Changing it will give results just as wrong, it'll just be a NaN
rather than an incorrect number.  It's more idiomatic to represent
missing information as null, so barring a fairly strong reason to use
NaN instead, I suggest keeping it as it is.

~TJ

Received on Tuesday, 15 July 2014 19:31:33 UTC