Re: Help me pick an API design (OO vs functional)

2013-04-04 Thread Michael Herrmann
Hi everyone, we just released the new version of our GUI automation tool with the improved API: http://www.getautoma.com/blog/Automa-1-5-1-window-switching. Thank you again for your help. Best regards, Michael On Monday, March 25, 2013 8:29:23 PM UTC+1, Michael Herrmann wrote: > Hello everyone

Re: Help me pick an API design (OO vs functional)

2013-03-28 Thread Michael Herrmann
On Thursday, March 28, 2013 1:42:35 AM UTC+1, Steven D'Aprano wrote: > On Wed, 27 Mar 2013 02:34:09 -0700, Michael Herrmann wrote: > > > On Tuesday, March 26, 2013 11:37:23 PM UTC+1, Steven D'Aprano wrote: > >> > >> Global *variables* are bad, not global functions. You have one global > >> variab

Re: Help me pick an API design (OO vs functional)

2013-03-28 Thread Michael Herrmann
On Wednesday, March 27, 2013 5:45:49 PM UTC+1, Ethan Furman wrote: > On 03/27/2013 02:34 AM, Michael Herrmann wrote: > > Design #2: > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > switch_to(notepad_1) > > write("Hello World!") > > p

Re: Help me pick an API design (OO vs functional)

2013-03-28 Thread Michael Herrmann
On Wednesday, March 27, 2013 2:56:55 PM UTC+1, Mitya Sirenef wrote: > ... > > I think alt-tab has to be special in any case. Regular alt-tab would act > like the GOTO statement. As a programmer looking at a script you have no > idea where you just alt-tabbed to without possibly looking through > d

Re: Help me pick an API design (OO vs functional)

2013-03-27 Thread Steven D'Aprano
On Wed, 27 Mar 2013 02:34:09 -0700, Michael Herrmann wrote: > On Tuesday, March 26, 2013 11:37:23 PM UTC+1, Steven D'Aprano wrote: >> >> Global *variables* are bad, not global functions. You have one global >> variable, "the current window". So long as your API makes it obvious >> when the curren

Re: Help me pick an API design (OO vs functional)

2013-03-27 Thread Ethan Furman
On 03/27/2013 02:34 AM, Michael Herrmann wrote: After everybody's input, I think Design #2 or Design #4 would be the best fit for us: Design #2: notepad_1 = start("Notepad") notepad_2 = start("Notepad") switch_to(notepad_1) write("Hello World!") pres

Re: Help me pick an API design (OO vs functional)

2013-03-27 Thread Mitya Sirenef
On 03/27/2013 05:10 AM, Michael Herrmann wrote: 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 synt

Re: Help me pick an API design (OO vs functional)

2013-03-27 Thread Michael Herrmann
On Wednesday, March 27, 2013 12:44:49 PM UTC+1, Chris Angelico wrote: > ... > Not seeking to advocate this particular option, but it would be > possible to make a single wrapper for all your functions to handle the > focus= parameter: > > def focusable(func): > @functools.wraps(func) >

Re: Help me pick an API design (OO vs functional)

2013-03-27 Thread Chris Angelico
On Wed, Mar 27, 2013 at 7:55 PM, Michael Herrmann wrote: > On Tuesday, March 26, 2013 5:41:42 PM UTC+1, Dave Angel wrote: >> To go back to my sample wrapper functions, they'd look something like >> (untested): >> >> def write(*args, focus=focused): >> focus.write(*args) > > I understood what

Re: Help me pick an API design (OO vs functional)

2013-03-27 Thread Michael Herrmann
On Tuesday, March 26, 2013 11:37:23 PM UTC+1, Steven D'Aprano wrote: > > Global *variables* are bad, not global functions. You have one global > variable, "the current window". So long as your API makes it obvious when > the current window changes, implicitly operating on the current window is

Re: Help me pick an API design (OO vs functional)

2013-03-27 Thread Michael Herrmann
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. H

Re: Help me pick an API design (OO vs functional)

2013-03-27 Thread Michael Herrmann
On Tuesday, March 26, 2013 5:41:42 PM UTC+1, Dave Angel wrote: > On 03/26/2013 10:40 AM, Michael Herrmann wrote: > > > On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: > >> > >> Have you considered adding a keyword argument to each of your > >> global functions, which is normal

Re: Help me pick an API design (OO vs functional)

2013-03-27 Thread Michael Herrmann
On Tuesday, March 26, 2013 4:16:57 PM UTC+1, Chris Angelico wrote: > On Wed, Mar 27, 2013 at 1:59 AM, Michael Herrmann > > wrote: > > save_dialogue = press(CTRL + 's') > > Does every single API need to then consider the possibility of focus > changing? How does the press() function know that thi

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Steven D'Aprano
On Tue, 26 Mar 2013 07:33:18 -0700, Michael Herrmann wrote: >> As long as you know the program is going to be simple, pile on the >> globals. But as soon as it advances, each of them is a trap to fall >> into. > > You're right with everything you say. globals are bad and it may happen > that thi

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Mitya Sirenef
On 03/26/2013 10:59 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 2:41:38 PM UTC+1, Mitya Sirenef wrote: >> ... >> At the __exit__, further commands are no longer routed to that window; >> if it was a nested context, window is switched to the outer context, >> WHEN there are commands i

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Neil Cerutti
On 2013-03-26, Dave Angel wrote: > On 03/26/2013 10:40 AM, Michael Herrmann wrote: >> On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: >>> >>> >>> Have you considered adding a keyword argument to each of your >>> global functions, which is normally None, but allows a user to >>

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Dave Angel
On 03/26/2013 10:40 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: 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.tx

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 1:59 AM, Michael Herrmann wrote: > save_dialogue = press(CTRL + 's') Does every single API need to then consider the possibility of focus changing? How does the press() function know that this will (or might - if the file's already been named, Ctrl-S won't open a dlg) chan

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 2:41:38 PM UTC+1, Mitya Sirenef wrote: > ... > At the __exit__, further commands are no longer routed to that window; > if it was a nested context, window is switched to the outer context, > WHEN there are commands in it (i.e. on the first command). This seems > pretty i

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: > On 2013-03-25, Mitya Sirenef 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 wou

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 1:42:26 PM UTC+1, Dave Angel wrote: > ... > > Also, it seems that in this thread, we are using "window" both to refer > to a particular application instance (like Notepad1 and Notepad2), and > to refer to windows within a single application. > > > > Anyway, if you'r

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 1:59:58 PM UTC+1, Steven D'Aprano wrote: > On Tue, 26 Mar 2013 05:04:43 -0700, Michael Herrmann wrote: > ... > Am I the only one who appreciates the simplicity of > > > start("Notepad") > > write("Hello World!") > > press(CTRL + 's') > > w

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Neil Cerutti
On 2013-03-25, Mitya Sirenef 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

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Mitya Sirenef
On 03/26/2013 05:38 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 12:40:45 AM UTC+1, Mitya Sirenef 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 >> i

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Steven D'Aprano
On Tue, 26 Mar 2013 05:04:43 -0700, Michael Herrmann wrote: > On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: >> ... >> Seems to me that the official interface should all be methods. >> However, you could have a new object which always represents the >> "focus" window. >> Then t

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Dave Angel
On 03/26/2013 08:04 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: ... Seems to me that the official interface should all be methods. However, you could have a new object which always represents the "focus" window. Then the USER could define trivi

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 1:16:56 PM UTC+1, Jean-Michel Pichavant wrote: > - Original Message - > > > > notepad_1 = start("Notepad") > > > > notepad_2 = start("Notepad") > > > > notepad_1.write("Hello World!") > > > > notepad_1.press(CTRL + 'a', CTRL + 'c')

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 12:57:21 PM UTC+1, Chris Angelico wrote: > On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann > > Doesn't the IPython do auto-completion for "global" functions? > > Even if it does, it'll be polluted with every other global. Methods > don't have that problem. On the flip

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 12:43:18 PM UTC+1, Chris Angelico wrote: > On Tue, Mar 26, 2013 at 8:38 PM, Michael Herrmann > > > What do you think of designs #3 and #4? > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > switch_to(notepad_1) > > wr

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Jean-Michel Pichavant
- Original Message - > On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant > wrote: > > - Original Message - > > > notepad_1 = start("Notepad") > > > notepad_2 = start("Notepad") > > > notepad_1.write("Hello World!") > > > notepad_1.press(CTRL + 'a', CTRL +

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 12:38:35 PM UTC+1, Chris Angelico wrote: > ... > Fundamental point: As I understand the API, it doesn't *actually* tie > to a window. You don't locate the Notepad window and send it keys - > you switch focus to Notepad and then send keys to the whole system. Is > this cor

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: > ... > Seems to me that the official interface should all be methods. However, > you could have a new object which always represents the "focus" window. > Then the USER could define trivial functions: > > def write(*args): >

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Chris Angelico
On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann wrote: > Doesn't the IPython do auto-completion for "global" functions? Even if it does, it'll be polluted with every other global. Methods don't have that problem. On the flip side, since presumably this is (will be) a module, anyone who wants a

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant wrote: > - Original Message - > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > notepad_1.write("Hello World!") > > notepad_1.press(CTRL + 'a', CTRL + 'c') > > notepad_2.press(CTRL +

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Chris Angelico
On Tue, Mar 26, 2013 at 8:38 PM, Michael Herrmann wrote: > What do you think of designs #3 and #4? > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > switch_to(notepad_1) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > switch

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Chris Angelico
On Tue, Mar 26, 2013 at 7:53 PM, Michael Herrmann wrote: > On Monday, March 25, 2013 10:08:53 PM UTC+1, Chris Angelico wrote: >> ... >> > I kind of like the context manager solution because the indentation makes >> > it very obvious what happens in which window. You are right about our >> > targ

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Dave Angel
On 03/26/2013 05:06 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 12:11:34 AM UTC+1, Ethan Furman wrote: On 03/25/2013 12:29 PM, Michael Herrmann wrote: ... notepad_1 = start("Notepad") notepad_2 = start("Notepad") notepad_1.write("Hello World!") notepa

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Jean-Michel Pichavant
- Original Message - > 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') > > The problem with this design is that it effectively duplicates our

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 12:40:45 AM UTC+1, Mitya Sirenef 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, s

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 12:11:34 AM UTC+1, Ethan Furman wrote: > On 03/25/2013 12:29 PM, Michael Herrmann wrote: > ... > > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > notepad_1.write("Hello World!") > > notepad_1.press(CTRL + 'a', CTRL + 'c') > > not

Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Monday, March 25, 2013 10:08:53 PM UTC+1, Chris Angelico wrote: > ... > > I kind of like the context manager solution because the indentation makes > > it very obvious what happens in which window. You are right about our > > target group though. Also, the "with" is not as explicit as it proba

Re: Help me pick an API design (OO vs functional)

2013-03-25 Thread Mitya Sirenef
On 03/25/2013 03:29 PM, Michael Herrmann wrote: Hello everyone, my name is Michael, I'm the lead developer of a Python GUI automation library for Windows called Automa: http://www.getautoma.com. We want to add some features to our library but are unsure how to best expose them via our API. It

Re: Help me pick an API design (OO vs functional)

2013-03-25 Thread Ethan Furman
On 03/25/2013 12:29 PM, Michael Herrmann wrote: Hello everyone, my name is Michael, I'm the lead developer of a Python GUI automation library for Windows called Automa: http://www.getautoma.com. We want to add some features to our library but are unsure how to best expose them via our API. It

Re: Help me pick an API design (OO vs functional)

2013-03-25 Thread Chris Angelico
On Tue, Mar 26, 2013 at 7:48 AM, Michael Herrmann wrote: > On Monday, March 25, 2013 8:42:25 PM UTC+1, Kwpolska wrote: >> ... >> >> > notepad_1 = start("Notepad") >> > notepad_2 = start("Notepad") >> > with notepad_1: >> > write("Hello World!") >> >

Re: Help me pick an API design (OO vs functional)

2013-03-25 Thread Michael Herrmann
Hi Kwpolska, thanks for your reply (as last time I posted here!). On Monday, March 25, 2013 8:42:25 PM UTC+1, Kwpolska wrote: > ... > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > with notepad_1: > > write("Hello World!") > >

Re: Help me pick an API design (OO vs functional)

2013-03-25 Thread Kwpolska
On Mon, Mar 25, 2013 at 8:29 PM, Michael Herrmann 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

Help me pick an API design (OO vs functional)

2013-03-25 Thread Michael Herrmann
Hello everyone, my name is Michael, I'm the lead developer of a Python GUI automation library for Windows called Automa: http://www.getautoma.com. We want to add some features to our library but are unsure how to best expose them via our API. It would be extremely helpful for us if you could l