[Python-Dev] Store timestamps as decimal.Decimal objects

Antoine Pitrou solipsis at pitrou.net
Wed Feb 1 12:08:42 CET 2012


On Wed, 1 Feb 2012 14:08:34 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Wed, Feb 1, 2012 at 12:35 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> > It strikes me as inelegant to have to do so much typing for something
> > as simple as getting the current time. We should approach the
> > simplicity of ``time.time(format='decimal')`` or
> > ``time.decimal_time()``.
> 
> Getting the current time is simple (you can already do it), getting
> access to high precision time without performance regressions or
> backwards incompatiblities or excessive code duplication is hard.

The implementation of it might be hard, the API doesn't have to be.
You can even use a callback system under the hood, you just don't have
to *expose* that complication to the user.

> There's a very simple rule in large scale software development:
> coupling is bad and you should do everything you can to minimise it.

The question is: is coupling worse than exposing horrible APIs? ;)

If Decimal were a core object as float is, we wouldn't have this
discussion because returning a Decimal would be considered "natural".

> Victor's approach throws that out the window by requiring that time
> and os know about every possible output format for time values.

Victor's proposal is maximalist in that it proposes several different
output formats. Decimal is probably enough for real use cases, though.

> For example, it would become *trivial* to write Alexander's suggested
> "hirestime" module that always returned decimal.Decimal objects:

Right, but that's not even a plausible request. Nobody wants to write a
separate time module just to have a different return type.

Regards

Antoine.


More information about the Python-Dev mailing list