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


Groups > comp.lang.python > #41894

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

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 <davea@davea.name>
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 <davea@davea.name>
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> <mailman.3704.1364253688.2939.python-list@python.org> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> <mailman.3729.1364293611.2939.python-list@python.org> <ecc055cc-0126-4356-9458-278a630b102c@googlegroups.com>
In-Reply-To <ecc055cc-0126-4356-9458-278a630b102c@googlegroups.com>
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 <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.3741.1364301768.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

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