X-Received: by 10.180.10.230 with SMTP id l6mr590057wib.3.1364301769015; Tue, 26 Mar 2013 05:42:49 -0700 (PDT) Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!209.85.212.215.MISMATCH!yt3no2727099wib.0!news-out.google.com!p18ni18765wiv.0!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.134.4.91.MISMATCH!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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'represents': 0.05; 'apps,': 0.07; 'attribute': 0.07; 'practice,': 0.07; 'function,': 0.09; 'methods,': 0.09; 'scripting': 0.09; 'seemed': 0.09; 'subject:design': 0.09; 'window.': 0.09; 'window?': 0.09; 'subject:Help': 0.11; 'def': 0.12; 'assume': 0.14; 'creates': 0.14; 'thread': 0.14; 'changes': 0.15; 'windows': 0.15; "'s')": 0.16; 'conditional': 0.16; 'globals.': 0.16; 'other,': 0.16; 'subject:API': 0.16; 'thread,': 0.16; 'unexpected': 0.16; 'world!")': 0.16; 'writable': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'all,': 0.19; 'bit': 0.19; 'seems': 0.21; 'header:User-Agent:1': 0.23; 'now?': 0.24; "haven't": 0.24; 'script': 0.25; 'define': 0.26; 'mention': 0.26; 'switch': 0.26; 'least': 0.26; 'somewhere': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'michael': 0.29; 'on,': 0.29; 'am,': 0.29; 'respective': 0.29; '(like': 0.30; 'concern': 0.31; 'dialog': 0.31; 'implied': 0.31; 'minor': 0.31; 'trivial': 0.31; 'yields': 0.31; 'supposed': 0.32; 'interface': 0.32; 'run': 0.32; 'another': 0.32; 'bugs': 0.33; 'cases': 0.33; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'subject: (': 0.35; 'something': 0.35; 'but': 0.35; 'really': 0.36; 'accessing': 0.36; 'functions.': 0.36; 'interface,': 0.36; 'much.': 0.36; 'object,': 0.36; 'next': 0.36; 'method': 0.36; 'should': 0.36; 'application': 0.37; 'too': 0.37; 'two': 0.37; 'problems': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'anything': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'address.': 0.39; 'users': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'read': 0.60; 'commands': 0.60; 'dave': 0.60; 'simple,': 0.60; 'most': 0.60; 'black': 0.61; 'new': 0.61; 'march': 0.61; 'no.': 0.61; 'simple': 0.61; "you're": 0.61; 'first': 0.61; 'save': 0.62; 'soon': 0.63; 'refer': 0.63; 'skip:n 10': 0.64; 'different': 0.65; 'within': 0.65; 'side': 0.67; '26,': 0.68; 'received:74.208': 0.68; 'sound': 0.68; '95%': 0.84; 'decades,': 0.84; 'functions:': 0.84; 'obvious.': 0.84; 'received:74.208.4.194': 0.84; 'advances,': 0.91; 'angel': 0.91; 'opens': 0.91; 'thing,': 0.91; '2013': 0.98 Date: Tue, 26 Mar 2013 08:42:26 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Help me pick an API design (OO vs functional) References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> In-Reply-To: X-Provags-ID: V02:K0:HDS9fzsWsZx4THoZkVz6GzbVVL4uDhfL8mP09mIbRhj Z9ruEojtqIkS0vmPD4j92KarC0k8dY0vtWsrDiks79YRo/p2D8 6puN6hv4paCOeugQKGHNJygM+QSY2QW78ODHkPgfp2XZYe7F0a Ae9GJPfcuyrPPS51ljru++yxEDlY6g3hYAhYrcUs68mTIo5TVj zmkseNEVH0b1DCVrSVmpJZBVBa/TZh5ufwFkrkC4FSWDzCul/B Zztvvi01R9kUeOHaRwq8LjN2wxVcEhkyjLp76QrNFrW6Vd5LBA lYcL1IybbO+67tju5YQqGU2t8I3BZDpNWJM5R0byWVN0RgF9A= = 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: 83 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364301768 news.xs4all.nl 6864 [2001:888:2000:d::a6]:47075 X-Complaints-To: abuse@xs4all.nl Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Xref: csiph.com comp.lang.python:41894 On 03/26/2013 08:04 AM, Michael Herrmann wrote: > On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: >> ... >> Seems to me that the official interface should all be methods. However, >> you could have a new object which always represents the "focus" window. >> Then the USER could define trivial functions: >> >> def write(*args): >> focused.write(*args) > > It's an interesting idea. But why not give this write(...) to them in the first place? Just to be clear, I was avoiding the problem of having two ways of accessing each function, since most of us prefer the methods, and you have some users who prefer simple functions. > Am I the only one who appreciates the simplicity of > > start("Notepad") > write("Hello World!") > press(CTRL + 's') > write("test.txt", into="File name") > click("Save") > press(ALT + F4) > > over > > notepad = start("Notepad") > notepad.write("Hello World!") > notepad.press(CTRL + 's') > notepad.write("test.txt", into="File name") > notepad.click("Save") > notepad.press(ALT + F4)? > >> Somewhere in this thread you mention that save() creates a new window, >> so a method-oriented approach would require that the user get that >> window object, and call its methods rather than the original window's. >> I say that's a very good thing, since the things you send may very well >> have very different meanings to the save dialog than they do in the >> original one. > > save() is not a function, but I assume you mean the action that opens the "Save" dialogue (I think that'd be `press(CTRL + 's')`). You are right that it's nice for it to be explicit. However, in 95% of cases, the window you want the next action to be performed in is the window that is currently active. I appreciate the explicitness, but to force it on the user for only 5% of cases seems a bit much. > >> Another concern I'd have is what happens if the user changes focus with >> his mouse? Does that change the meaning you had for focus() in the >> above exchange? Do you want your press() method to apply to a different >> window when the user changes to that window? > > No. Internally, we remember which window is the currently active window. If you just run a script without user-intervention, this will be the respective foreground window. If some other window is in the foreground - which most typically happens when the user is interactively entering commands one after the other, so the foreground window is the console window, we do switch to the window that's supposed to be the active one. It may sound like black magic, but it works very well in practice, and really is not too ambiguous. When you read a script like > > start("Notepad") > write("Hello World") > press(CTRL + 's') > write("test.txt", into="File name") > click("Save") > click("Close") > > I hold that you intuitively know what's going on, without even thinking about window switching. > Until the program you're scripting makes some minor change in its interface, or has something conditional on an attribute not intuitively obvious. Also, it seems that in this thread, we are using "window" both to refer to a particular application instance (like Notepad1 and Notepad2), and to refer to windows within a single application. Anyway, if you're only automating a few specific apps, you're not likely to run into the problems that methods were intended to address. After all, Notepad's bugs haven't seemed to change for a couple of decades, so why should they fix anything now? Having a selected window be an implied object for those global functions yields at least the same problems as any writable global. Multithreading, unexpected side effects from certain functions, callbacks, etc. As long as you know the program is going to be simple, pile on the globals. But as soon as it advances, each of them is a trap to fall into. -- DaveA