Help me pick an API design (OO vs functional)

Dave Angel davea at davea.name
Tue Mar 26 17:41:42 CET 2013


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)

Of course, the user should only use the wrappers when things are sure to 
remain "simple."


-- 
DaveA



More information about the Python-list mailing list