[Python-Dev] an alternative to embedding policy in PEP 418 (was: PEP 418: Add monotonic clock)
cs at zip.com.au
Tue Apr 3 23:42:55 CEST 2012
On 03Apr2012 09:07, Ethan Furman <ethan at stoneleaf.us> wrote:
| Lennart Regebro wrote:
| > On Tue, Apr 3, 2012 at 08:03, Cameron Simpson <cs at zip.com.au> wrote:
| >> clock = get_clock(MONOTONIC|HIRES) or get_clock(MONOTONIC)
| >> If the symbol names are not the horribleness, can you qualify what API
| >> you would like more?
| > Well, get_clock(monotonic=True, highres=True) would be a vast
| > improvement over get_clock(MONOTONIC|HIRES).
| Allowing get_clock(True, True)? Ick. My nomination would be
| get_clock(MONOTONIC, HIGHRES) -- easier on the eyes with no |.
get_clock already has two arguments - you can optionally hand it a clock
list - that's used by monotonic_clock() and hires_clock().
Have a quick glance at:
(I finally found out how to point at the latest revision on BitBucket;
it's not obvious from the web interface itself.)
| > I also think it should
| > raise an error if not found. The clarity and easy of use of the API is
| > much more important than how much you can do in one line.
How much you can do _clearly_ in one line is a useful metric.
| What's unclear about returning None if no clocks match?
The return of None is very deliberate. I _want_ user specified fallback
to be concise and easy. The example:
clock = get_clock(MONOTONIC|HIRES) or get_clock(MONOTONIC)
seems to satisfy both these criteria to my eye. Raising an exception
makes user fallback a royal PITA, with a horrible try/except cascade
Exceptions are all very well when there is just one thing to do: parse
this or fail, divide this by that or fail. If fact they're the very
image of "do this one thing or FAIL". They are not such a good match for do
this thing or that thing or this other thing.
When you want a simple linear cascade of choices, Python's short circuiting
"or" operator is a very useful thing. Having an obsession with exceptions is
Cameron Simpson <cs at zip.com.au> DoD#743
Because of its special customs, crossposting between alt.peeves and normal
newsgroups is discouraged. - Cameron Spitzer
More information about the Python-Dev