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


Groups > comp.lang.python > #42005

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

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 <rosuav@gmail.com>
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> <mailman.3706.1364254851.2939.python-list@python.org> <ardooaF3o0oU1@mid.individual.net> <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> <mailman.3755.1364316131.2939.python-list@python.org> <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 <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3804.1364384691.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web