[Python-Dev] an alternative to embedding policy in PEP 418 (was: PEP 418: Add monotonic clock) (original) (raw)

Cameron Simpson 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 = getclock(MONOTONIC|HIRES) or getclock(MONOTONIC) | >> | >> If the symbol names are not the horribleness, can you qualify what API | >> you would like more? | > | > Well, getclock(monotonic=True, highres=True) would be a vast | > improvement over getclock(MONOTONIC|HIRES). || Allowing getclock(True, True)? Ick. My nomination would be | getclock(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:

https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/clockutils.py

(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 needed.

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 IMO unhealthy.

Cheers,

Cameron Simpson <cs at zip.com.au> DoD#743 http://www.cskk.ezoshosting.com/cs/

Because of its special customs, crossposting between alt.peeves and normal newsgroups is discouraged. - Cameron Spitzer



More information about the Python-Dev mailing list