Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'syntax': 0.04; 'explicitly': 0.05; 'context': 0.07; 'correct.': 0.07; 'explicit': 0.07; 'imply': 0.09; 'subject:design': 0.09; 'window.': 0.09; 'api': 0.11; 'subject:Help': 0.11; 'windows': 0.15; '"with"': 0.16; 'api,': 0.16; 'command,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inclined': 0.16; 'lying,': 0.16; 'subject:API': 0.16; 'then?': 0.16; 'weird': 0.16; 'wrote:': 0.18; 'otherwise,': 0.22; 'simpler': 0.24; 'looks': 0.24; 'options': 0.25; 'switch': 0.26; 'second': 0.26; 'header:In-Reply- To:1': 0.27; 'michael': 0.29; 'chris': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'too.': 0.31; '(since': 0.31; '25,': 0.31; 'indentation': 0.31; 'keys': 0.31; 'post.': 0.31; 'though.': 0.31; 'allows': 0.31; 'there.': 0.32; 'probably': 0.32; 'option': 0.32; 'text': 0.33; 'open': 0.33; 'running': 0.33; 'monday,': 0.33; 'actual': 0.34; 'sense': 0.34; 'maybe': 0.34; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'subject: (': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'sequence': 0.36; 'done': 0.36; 'method': 0.36; 'possible': 0.36; 'should': 0.36; 'so,': 0.37; 'two': 0.37; 'received:209': 0.37; 'manager': 0.38; 'actions': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'system.': 0.39; 'either': 0.39; 'skip:u 10': 0.60; 'identify': 0.61; 'managers': 0.61; 'march': 0.61; "you're": 0.61; 'first': 0.61; 'kind': 0.63; 'such': 0.63; 'happen': 0.63; 'our': 0.64; 'effectively': 0.66; 'side': 0.67; 'between': 0.67; 'mar': 0.68; '26,': 0.68; 'advantages': 0.68; 'brain': 0.68; 'risk': 0.72; 'obvious': 0.74; '(yet)': 0.84; 'fourth': 0.84; "it'd": 0.84; 'tie': 0.84; 'absolutely': 0.87; '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=ixpTjGSftUl5wtK4QV56kA6t9MOZQuEakn+LVtVmr5k=; b=jPVTVZYgKeczcdbAZfJbkkIGFB/pOTE3Q0T97C2M3Ln2okhSI3EoDQ0ZlZCRbA7IKL 0Bpw4RFBGOAuJd01i/KpsFdlm1qb6OwZtacy68DJVP6RaVtnOy4nLSknxzMCVNr0XJFA lTKtezHzyjeFGExCLukqWquwJXNCeeSOQzvVLj9PwD9WZk/lzWf6TNTSwHcgUSEZlLbO nYja6DqDQIsIhC+bAtYBeSTHZa6fpifjBnUHvD3Mm1DM22WE0n9AL5pB63nTNNDotyQH 4kNhG8Irz8LIIwp81MouH3QacV5fmxpWRN1wwjpV4m3Ot74c3QQVDpmGQpHv9A8cmVNP O9Wg== MIME-Version: 1.0 X-Received: by 10.52.22.194 with SMTP id g2mr16420035vdf.91.1364297915588; Tue, 26 Mar 2013 04:38:35 -0700 (PDT) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <4b2d2295-cffd-4965-8d75-ebd4f0b9da32@googlegroups.com> Date: Tue, 26 Mar 2013 22:38:35 +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: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364297923 news.xs4all.nl 6864 [2001:888:2000:d::a6]:55724 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41881 On Tue, Mar 26, 2013 at 7:53 PM, Michael Herrmann wrote: > On Monday, March 25, 2013 10:08:53 PM UTC+1, Chris Angelico wrote: >> ... >> > I kind of like the context manager solution because the indentation ma= kes it very obvious what happens in which window. You are right about our t= arget group though. Also, the "with" is not as explicit as it probably shou= ld be. >> >> What happens at the __exit__ of the context manager? What happens if >> context managers are nested? I'd be inclined to the simpler option of >> an explicit switch (since focus doesn't really "stack" and it'd feel >> weird for focus to *sometimes* switch away when you're done working >> with one window), though the context manager syntax does have its >> advantages too. > > You are right, an __exit__ for a window doesn't really make sense and nei= ther does stacking. There's also the problem that the focus window may chan= ge - for instance when closing it. What happens if you're still inside the = "with ..." then? At first glance, I think the context manager solution look= s nice syntactically, but maybe it isn't the way to go here. Fundamental point: As I understand the API, it doesn't *actually* tie to a window. You don't locate the Notepad window and send it keys - you switch focus to Notepad and then send keys to the whole system. Is this correct? I'm basing my understanding on this paragraph from your original post: > 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. If so, then all of the method-based options are effectively lying, because they imply a binding that's not there. The actual sequence of actions includes imperatives of "switch to some other window", so I think that's what the API should reflect. Otherwise, there's risk that something will get horribly horribly confused between the programmer's brain and the end result (which could happen on either side of your code). But if you can unambiguously identify a running instance of something and switch to it, then a method on the object that start() returns would be absolutely correct. So I'd be looking at either your second or fourth options from the original post. ChrisA