Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41826 > unrolled thread

Help me pick an API design (OO vs functional)

Started byMichael Herrmann <michael.herrmann@getautoma.com>
First post2013-03-25 12:29 -0700
Last post2013-04-04 00:05 -0700
Articles 4 on this page of 44 — 8 participants

Back to article view | Back to comp.lang.python


Contents

  Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-25 12:29 -0700
    Re: Help me pick an API design (OO vs functional) Kwpolska <kwpolska@gmail.com> - 2013-03-25 20:42 +0100
      Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-25 13:48 -0700
        Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-26 08:08 +1100
          Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 01:53 -0700
            Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-26 22:38 +1100
              Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 05:13 -0700
              Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 05:13 -0700
      Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-25 13:48 -0700
    Re: Help me pick an API design (OO vs functional) Ethan Furman <ethan@stoneleaf.us> - 2013-03-25 16:11 -0700
      Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 02:06 -0700
        Re: Help me pick an API design (OO vs functional) Dave Angel <davea@davea.name> - 2013-03-26 06:26 -0400
          Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 05:04 -0700
            Re: Help me pick an API design (OO vs functional) Dave Angel <davea@davea.name> - 2013-03-26 08:42 -0400
              Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 07:33 -0700
                Re: Help me pick an API design (OO vs functional) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 22:37 +0000
                  Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 02:34 -0700
                    Re: Help me pick an API design (OO vs functional) Ethan Furman <ethan@stoneleaf.us> - 2013-03-27 09:45 -0700
                      Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-28 03:54 -0700
                    Re: Help me pick an API design (OO vs functional) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-28 00:42 +0000
                      Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-28 04:41 -0700
            Re: Help me pick an API design (OO vs functional) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 12:59 +0000
              Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 07:26 -0700
    Re: Help me pick an API design (OO vs functional) Mitya Sirenef <msirenef@lightbird.net> - 2013-03-25 19:40 -0400
      Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 02:38 -0700
        Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-26 22:43 +1100
          Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 05:18 -0700
        Re: Help me pick an API design (OO vs functional) Mitya Sirenef <msirenef@lightbird.net> - 2013-03-26 09:41 -0400
          Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 07:59 -0700
            Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-27 02:16 +1100
              Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 01:45 -0700
            Re: Help me pick an API design (OO vs functional) Mitya Sirenef <msirenef@lightbird.net> - 2013-03-26 18:01 -0400
              Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 02:10 -0700
                Re: Help me pick an API design (OO vs functional) Mitya Sirenef <msirenef@lightbird.net> - 2013-03-27 09:56 -0400
                  Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-28 03:52 -0700
      Re: Help me pick an API design (OO vs functional) Neil Cerutti <neilc@norwich.edu> - 2013-03-26 14:13 +0000
        Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 07:40 -0700
          Re: Help me pick an API design (OO vs functional) Dave Angel <davea@davea.name> - 2013-03-26 12:41 -0400
            Re: Help me pick an API design (OO vs functional) Neil Cerutti <neilc@norwich.edu> - 2013-03-26 17:25 +0000
            Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 01:55 -0700
              Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-27 22:44 +1100
                Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 05:23 -0700
                Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 05:23 -0700
    Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-04-04 00:05 -0700

Page 3 of 3 — ← Prev page 1 2 [3]


#42005

FromChris Angelico <rosuav@gmail.com>
Date2013-03-27 22:44 +1100
Message-ID<mailman.3804.1364384691.2939.python-list@python.org>
In reply to#41992
On Wed, Mar 27, 2013 at 7:55 PM, Michael Herrmann
<michael.herrmann@getautoma.com> 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 you meant - I'm not so worried about the invocations, as of course the parameter can be omitted if there's a default value/behaviour. What I am worried about is the complexity this approach adds to several functions. Yes, you could argue that one keyword argument really isn't that much, but then you have to maintain and document it for all functions that have the new keyword parameter. In other words, a single functionality that is not needed 90% of the time increases the complexity of several, not really related functions. I am very grateful for your suggestions! But I don't think adding this keyword parameter is the way to go for us.
>

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)
	def wrapper(*args,focus=None):
		if focus: focus.activate()
		return func(*args)
	return wrapper

Then you just decorate all your functions with that:
def write(string):
    # do something with the active window

ChrisA

[toc] | [prev] | [next] | [standalone]


#42008

FromMichael Herrmann <michael.herrmann@getautoma.com>
Date2013-03-27 05:23 -0700
Message-ID<d64ec93b-b398-4ad1-894f-dd3d938f2b1a@googlegroups.com>
In reply to#42005
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)
> 	def wrapper(*args,focus=None):
> 		if focus: focus.activate()
> 		return func(*args)
> 	return wrapper
> 
> Then you just decorate all your functions with that:
> 
> def write(string):
>     # do something with the active window

Hi, sure, I wouldn't have copy-pasted the code and of course there are techniques to avoid code duplication. It's not so much what I'm worried about. What I'm worried about is that the concept of window-switching gets "smeared" over several other not-really related concepts such as clicking and typing. I feel it violates orthogonality: http://www.artima.com/intv/dry3.html is the best freely available resource I could find but I think it's best explained in The Pragmatic Programmer http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X.

Michael
www.getautoma.com

[toc] | [prev] | [next] | [standalone]


#42010

FromMichael Herrmann <michael.herrmann@getautoma.com>
Date2013-03-27 05:23 -0700
Message-ID<mailman.3807.1364387690.2939.python-list@python.org>
In reply to#42005
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)
> 	def wrapper(*args,focus=None):
> 		if focus: focus.activate()
> 		return func(*args)
> 	return wrapper
> 
> Then you just decorate all your functions with that:
> 
> def write(string):
>     # do something with the active window

Hi, sure, I wouldn't have copy-pasted the code and of course there are techniques to avoid code duplication. It's not so much what I'm worried about. What I'm worried about is that the concept of window-switching gets "smeared" over several other not-really related concepts such as clicking and typing. I feel it violates orthogonality: http://www.artima.com/intv/dry3.html is the best freely available resource I could find but I think it's best explained in The Pragmatic Programmer http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X.

Michael
www.getautoma.com

[toc] | [prev] | [next] | [standalone]


#42741

FromMichael Herrmann <michael.herrmann@getautoma.com>
Date2013-04-04 00:05 -0700
Message-ID<c1261f3b-afb7-4c58-b9f7-1b2f56bec6c3@googlegroups.com>
In reply to#41826
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, 
> 
> 
> 
> 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 let us know which API design feels "right" to you.
> 
> 
> 
> Our API already offers very simple commands for automating the GUI of a Windows computer. For example:
> 
> 
> 
> 	from automa.api import *
> 
> 	start("Notepad")
> 
> 	write("Hello World!")
> 
> 	press(CTRL + 's')
> 
> 	write("test.txt", into="File name")
> 
> 	click("Save")
> 
> 	click("Close")
> 
> 
> 
> When you execute this script, Automa starts Notepad and simulates key strokes, mouse movements and clicks to perform the required commands. At the moment, each action is performed in the currently active window. 
> 
> 
> 
> We do not (yet) have a functionality that allows you to explicitly switch to a specific window. Such a functionality would for instance make it possible to open two Notepad windows using the start(...) command, and copy text between them.
> 
> 
> 
> One API design would be to have our start(...) function return a "Window" (say) object, whose methods allow you to do the same operations as the global functions write(...), press(...), click(...) etc., but in the respective window. In this design, the example of operating two Notepad windows could be written as
> 
> 
> 
> 	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 API: We want to keep our "global" functions because they are so easy to read. If we add methods to a new "Window" class that do more or less the same, we feel that we are violating Python's principle that "There should be one - and preferably only one - obvious way to do it."
> 
> 
> 
> An alternative design would be to make the window switching an explicit action. One way of doing this would be to add a new global function, say "switch_to" or "activate", that takes a single parameter that identifies the window to be switched to. We could still have start(...) return a Window object, that could then be passed to our function:
> 
> 
> 
> 	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')
> 
> 
> 
> Maybe our Window objects could also be used as context managers:
> 
> 
> 
> 	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')
> 
> 
> 
> As a final idea, switching could also be done as a method of the Window class:
> 
> 
> 
> 	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')
> 
> 
> 
> 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?
> 
> 
> 
> Thank you so much!
> 
> 
> 
> Best wishes,
> 
> Michael

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.python


csiph-web