Units Of Measurement Options Stated Using Lowest Common Denominator Unit Practical

1 view
Skip to first unread message

Joran Greef

unread,
Oct 9, 2009, 9:18:54 AM10/9/09
to Prototype: Core
I've been using some Number extensions of my own for some time:
Number.seconds, Number.minutes, Number.hours etc. where (2).minutes()
would return the 2 minutes expressed as milliseconds e.g. 120000,
(2).seconds() would return 2000 etc.

It's been great for defining config files e.g.:

Config.Database.recentThreshold = (2).minutes();
Config.Http.timeout = (60).seconds();

I think Rails does the same and that may be where I got the idea from.
I've also added Number.kilobytes, Number.megabytes, etc.

It would be great if interfaces which receive a time or quantity value
as an option, such as PeriodicalExecuter, could expect the value to be
expressed in the lowest common denominator unit practical, i.e.
milliseconds rather than seconds. Java does it, and so does
Javascript's own setInterval, setTimeout etc. It would follow the
principle of least surprise and make units of measurement easier to
compare.

Allen Madsen

unread,
Oct 9, 2009, 9:39:28 AM10/9/09
to prototy...@googlegroups.com
Joran,

The type of number extensions you described aren't part of prototype.
Therefore, it is simpler for developers who aren't using such an
extension to use seconds. I'm not opposed to the switch, but I wanted
to throw out a possible explanation for the way it is today.

Allen Madsen
http://www.allenmadsen.com

T.J. Crowder

unread,
Oct 10, 2009, 8:30:22 AM10/10/09
to Prototype: Core
I, for one, found the units used by Function#delay (for example) to be
very surprising when I first saw them, and I have to stop and think
every time I use Function#delay. The usual unit for that sort of
thing in every language I've worked in other than BASIC is
milliseconds.

That said, I don't see changing them barring a wholescale Prototype
API rewrite.

-- T.J.

On Oct 9, 2:39 pm, Allen Madsen <bla...@gmail.com> wrote:
> Joran,
>
> The type of number extensions you described aren't part of prototype.
> Therefore, it is simpler for developers who aren't using such an
> extension to use seconds. I'm not opposed to the switch, but I wanted
> to throw out a possible explanation for the way it is today.
>
> Allen Madsenhttp://www.allenmadsen.com
Message has been deleted

Tobie Langel

unread,
Oct 11, 2009, 10:25:29 PM10/11/09
to Prototype: Core
For the record, the unit of time measurement in Ruby is seconds, which
explains the reason behind that choice for Prototype.

Given the backwards compatibility issues, and the benefits of using
seconds rather than milliseconds in most but edge cases, there's litte
chance of seeing that change.

Best,

Tobie

Joran Greef

unread,
Oct 19, 2009, 5:24:53 AM10/19/09
to Prototype: Core
Thanks Tobie.

Re: "...the unit of time measurement in Ruby is seconds, which
explains the reason".
Can we optimize for those familiar with Javascript? Is there any time-
related API in Javascript which uses seconds?

Re: "Given ... the benefits of using seconds rather than milliseconds
in most but edge cases".
Do you have some data on this?

Re: "backwards compatibility".
A semantically correct API may be better than a backwards compatible
API.

Izidor Jerebic

unread,
Oct 21, 2009, 5:42:06 AM10/21/09
to prototy...@googlegroups.com

On 19.10.2009, at 11:24, Joran Greef wrote:

>
> Thanks Tobie.
>
> Re: "...the unit of time measurement in Ruby is seconds, which
> explains the reason".
> Can we optimize for those familiar with Javascript? Is there any time-
> related API in Javascript which uses seconds?

Well, programmers versed in more than one language can tell you that
in general time APIs are in seconds, because second is canonical
measure unit of time. Javascript is exception, and not in a good way.
No need to follow bad examples...


> Re: "backwards compatibility".
> A semantically correct API may be better than a backwards compatible
> API.

Semantically correct API for time has units in seconds, because second
is canonical unit for time, not 10e-3 seconds....

izidor

Reply all
Reply to author
Forward
0 new messages