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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'represents': 0.05; 'explicit': 0.07; 'logic': 0.09; 'subject:design': 0.09; 'used)': 0.09; 'window.': 0.09; 'window?': 0.09; 'subject:Help': 0.11; 'def': 0.12; 'creates': 0.14; 'thread': 0.14; 'changes': 0.15; "'a',": 0.16; "'s')": 0.16; 'backwards': 0.16; 'invocation': 0.16; 'it),': 0.16; 'magic': 0.16; 'subject:API': 0.16; 'syntactic': 0.16; 'world!")': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'adds': 0.24; 'lets': 0.24; '(or': 0.24; 'script': 0.25; 'define': 0.26; 'mention': 0.26; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'michael': 0.29; 'am,': 0.29; 'points': 0.29; 'change,': 0.30; 'along': 0.30; '(which': 0.31; 'lines': 0.31; 'concern': 0.31; 'dialog': 0.31; 'go.': 0.31; 'trivial': 0.31; 'interface': 0.32; 'another': 0.32; 'text': 0.33; 'sense': 0.34; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'subject: (': 0.35; 'something': 0.35; 'good.': 0.35; 'objects': 0.35; 'version': 0.36; 'really': 0.36; 'object,': 0.36; 'method': 0.36; 'should': 0.36; 'being': 0.38; 'window': 0.38; 'needed': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'anything': 0.39; 'does': 0.39; 'moving': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'break': 0.61; 'new': 0.61; 'march': 0.61; 'here:': 0.62; 'save': 0.62; 'skip:n 10': 0.64; 'more': 0.64; 'different': 0.65; 'between': 0.67; '26,': 0.68; 'received:74.208': 0.68; 'introduce': 0.78; 'distinguish': 0.84; 'ethan': 0.84; 'functions:': 0.84; 'furman': 0.84; 'received:74.208.4.194': 0.84; 'technically': 0.84; 'opens': 0.91; 'thing,': 0.91; '2013': 0.98 Date: Tue, 26 Mar 2013 06:26:30 -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: <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:bK9dR4Z8zIGDA4+OW27E/dQpjY+9NevDBYV5gvp+tfy GkdaNxNbyKsBZq81S0+UxV73z9Alzediy9xC8YrMV5Ra8YkDnL tvCtEGGxoHgAFkzgNwlCFRT4A4nKxCSGJHtdRqPBHv6mgeYhfp aO2k4yQkLXCqt84vRf65hyZAORDQo3h5BVWvYc7zb6GQKkcFYx MxoYveCM+YwMc0qhYyL0n/HjBcMozgyGN81IWCJQYBKYwJqvi7 GvvJ6xIWk7jjKOSLI5oSK3nji58ZyJcowqAB111aTRHqIoXAJ8 NMFBWuHaHTIOlSwUpaIsWMFDvoz+DGIJHBIsWq9xd/iMGs9TQ= = 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: 74 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364293611 news.xs4all.nl 6987 [2001:888:2000:d::a6]:43639 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41873 On 03/26/2013 05:06 AM, Michael Herrmann wrote: > On Tuesday, March 26, 2013 12:11:34 AM UTC+1, Ethan Furman wrote: >> On 03/25/2013 12:29 PM, Michael Herrmann wrote: >> ... >>> >>> notepad_1 = start("Notepad") >>> notepad_2 = start("Notepad") >>> notepad_1.write("Hello World!") >>> notepad_1.press(CTRL + 'a', CTRL + 'c') >>> notepad_2.press(CTRL + 'v') >> >> This is the way to go. Just move your global functions into the Window object (or whatever you call it), break >> backwards compatibility (major version number change, perhaps?), and call it good. >> >> It makes much more sense to call methods of several different objects (which is explicit -- you always know which object >> is being used) than having a magic function that changes the object in the background (plus you now have to search >> backwards for the last magic invocation to know -- and what if a called function changes it?). > > Your points are valid and I cannot really say anything against them. The problem with moving all global functions into the Window object is that this adds a lot of syntactic baggage that isn't needed in 90% of the cases. We really prefer 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). > > Also, there's a problem here: The "Save" dialogue that opens in the above script is technically a different window so in theory you would have to introduce a new object to distinguish between the original window that lets you edit your text document from the "Save" window. This is very tedious and error-prone. You are right, though, that we have to do some logic in the background to remember the last window. > > In light of this, could you live with something along the lines of design #4? > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.focus() > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > notepad_2.focus() > press(CTRL + 'v') > > Thanks, > Michael > 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) 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. 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? -- DaveA