Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.062 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'argument': 0.05; 'advocate': 0.07; 'option,': 0.09; 'parameter': 0.09; 'subject:design': 0.09; 'wrapper': 0.09; 'subject:Help': 0.11; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'parameter.': 0.16; 'parameter:': 0.16; 'subject:API': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'meant': 0.20; 'adds': 0.24; 'header :In-Reply-To:1': 0.27; 'michael': 0.29; 'related': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'argue': 0.31; 'omitted': 0.31; 'could': 0.34; 'subject: (': 0.35; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'functions.': 0.36; 'grateful': 0.36; 'keyword': 0.36; 'words,': 0.36; 'possible': 0.36; 'received:209': 0.37; 'window': 0.38; 'handle': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'dave': 0.60; 'new': 0.61; 'march': 0.61; 'course': 0.61; 'back': 0.62; 'sample': 0.67; 'mar': 0.68; '26,': 0.68; 'default': 0.69; 'complexity': 0.84; 'decorate': 0.84; 'much,': 0.84; "they'd": 0.84; 'angel': 0.91; 'increases': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=7ar2+cvzBI2J0zIn4n0papfybKlGsRIOQnLyzM+hG88=; b=qU8JNtKxkU+BRM/6339eVX1YzGkf6nj8flONbaB9w++GrmNZWwgi68ZlZDUphvgZyU Ltq4FoX4t+5pxP+JEGl2rxgEFM57ZO5vdc69duTUQCNRo6LBjBksD8x6PALCiz+T7ZzU AVTM4zQ9uiZLItt8flhXGLbuZRHZCZfA0Y+0eSvgdPdJWHhIGF3/DLPU08TAtvkwR+kr bE3GKYh2fU/BdZxJGr5IjpNQiYsFZSPBxk9hAdgJqlq0DzDfLlvQ04Zi5TWW2GxhK0VI OkQKF4kBY6ZKOSJJ4EZ36lrTHt9FRiOk69stKcg8SSMow6Oc1gTufKkrIHJtcHIfCTHz qYwg== MIME-Version: 1.0 X-Received: by 10.220.88.145 with SMTP id a17mr22615830vcm.66.1364384689671; Wed, 27 Mar 2013 04:44:49 -0700 (PDT) In-Reply-To: <5483aad6-221e-46f8-8909-bf743e9fcb5c@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> <5483aad6-221e-46f8-8909-bf743e9fcb5c@googlegroups.com> Date: Wed, 27 Mar 2013 22:44:49 +1100 Subject: Re: Help me pick an API design (OO vs functional) From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364384691 news.xs4all.nl 6892 [2001:888:2000:d::a6]:60807 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42005 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=3Dfocused): >> focus.write(*args) > > I understood what you meant - I'm not so worried about the invocations, a= s of course the parameter can be omitted if there's a default value/behavio= ur. 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 tha= t much, but then you have to maintain and document it for all functions tha= t have the new keyword parameter. In other words, a single functionality th= at is not needed 90% of the time increases the complexity of several, not r= eally 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=3D parameter: def focusable(func): @functools.wraps(func) def wrapper(*args,focus=3DNone): 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