Help me pick an API design (OO vs functional)

Michael Herrmann michael.herrmann at
Wed Mar 27 10:10:58 CET 2013

On Tuesday, March 26, 2013 11:01:08 PM UTC+1, Mitya Sirenef wrote:
> On 03/26/2013 10:59 AM, Michael Herrmann wrote:
>  > ...
>  > Forcing the library user to always use the "with ..." seems like 
> overkill though. I think the gained precision does not justify this 
> burden on the library user. Hm....
> I don't see why that's a big deal, I've used AHK extensively and in my
> experience you don't switch windows all that often. I think it's best to
> optimize to have easy to type and read commands while you're working in
> the same window.
> I think you could argue that dialogs that belong to the main window
> should be handled implicitly, though. I think for other windows it'd
> definitely be good to use context managers, but for quick/simple dialogs
> it's too much hassle, although for large, complex dialogs that have
> inner tabs and require a lot of work, it again starts to make sense.
> At the very least, for small dialogs it's sipmpler to do:
> with press(CTRL + 's'):
>      write("test.txt", into="File name")
>      click("Save")

I think what the context manager approach really has going for itself is the syntactic structure it gives to scripts, that makes it easy to see what is going on in which window. Semantically, however, I think the fit of this approach has some rough edges: The fact that there needs to be some special treatment for ALT + TAB, that actions such as `press` "sometimes" return values that are needed to continue the script and so on. It really has its appeal, but I think it's a bit too special and intricate to be used by a broad audience.

> Calamities are of two kinds: misfortunes to ourselves, and good fortune 
> to others.



More information about the Python-list mailing list