Help me pick an API design (OO vs functional)

Neil Cerutti neilc at norwich.edu
Tue Mar 26 10:13:30 EDT 2013


On 2013-03-25, Mitya Sirenef <msirenef at lightbird.net> wrote:
> I think I would prefer context managers. I don't think it's a
> big problem for win users because this behaviour would be one
> of the first things documented in the start guide and would be
> all over example scripts, so a new user missing or forgetting
> it is not a realistic scenario.

If window focus switching is really a rarity, and only done
briefly then I agree that a context manager makes a nice and neat
solution.

But it's too powerful a generalisation for such a small corner
case.

Have you considered adding a keyword argument to each of your
global functions, which is normally None, but allows a user to
provide a prefered focus window?

enter_text("test.txt", focus=save_dialog)
press_button(Savebutton, focus=save_dialog)

(Those are just guesses at your API functions; sorry.)

When focus remains None, your usual assumptions about focus would
apply, otherwise the user preference overrides it.

-- 
Neil Cerutti



More information about the Python-list mailing list