Help me pick an API design (OO vs functional)

Kwpolska kwpolska at gmail.com
Mon Mar 25 20:42:25 CET 2013


On Mon, Mar 25, 2013 at 8:29 PM, Michael Herrmann
<michael.herrmann at getautoma.com> wrote:
>         notepad_1 = start("Notepad")
>         notepad_2 = start("Notepad")
>         notepad_1.write("Hello World!")
>         notepad_1.press(CTRL + 'a', CTRL + 'c')
>         notepad_2.press(CTRL + 'v')

Explicit is better than implicit.  Changing windows should be explicit
and not implified by your library.

>         notepad_1 = start("Notepad")
>         notepad_2 = start("Notepad")
>         switch_to(notepad_1)
>         write("Hello World!")
>         press(CTRL + 'a', CTRL + 'c')
>         switch_to(notepad_2)
>         press(CTRL + 'v')

Much better.

>         notepad_1 = start("Notepad")
>         notepad_2 = start("Notepad")
>         with notepad_1:
>                 write("Hello World!")
>                 press(CTRL + 'a', CTRL + 'c')
>         with notepad_2:
>                 press(CTRL + 'v')

That’s ugly, and don’t forget that your users aren’t Pythonistas most
of the time.

>         notepad_1 = start("Notepad")
>         notepad_2 = start("Notepad")
>         notepad_1.activate()
>         write("Hello World!")
>         press(CTRL + 'a', CTRL + 'c')
>         notepad_2.activate()
>         press(CTRL + 'v')

That is nice and makes sense, because a global function feels wrong,
at least for me.

> It would be extremely helpful for us if you could let me know which way of using the API you would prefer. If you opt for an explicit version, how would you call the respective method? "activate" / "switch_to" / "focus" or something else?

Window().focus() is the best IMO.

PS. do you plan a version for non-Windows OSes?  Also, €99 is too expensive.

-- 
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html



More information about the Python-list mailing list