Help me pick an API design (OO vs functional)

Michael Herrmann michael.herrmann at getautoma.com
Wed Mar 27 09:55:22 CET 2013


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:
> >>    <SNIP>
> >> 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)
> 
> > It's an interesting new idea but I somehow feel it makes the existing functions too complicated. Also, having to add it to all existing, and future functions sounds a bit too cumbersome to me.
> 
> Perhaps Neil didn't make it clear enough.  I figure he meant a keyword 
> argument with an explicit default value of None.  (or if you followed my 
> earlier discussion, default value of focused)
> 
> That way your user can keep using the functions for when there's no 
> ambiguity, but add a focus= parameter only when needed.
> 
> 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.

Thanks,
Michael
www.getautoma.com



More information about the Python-list mailing list