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


Groups > comp.lang.python > #41901

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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <msirenef@lightbird.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'read.': 0.03; 'syntax': 0.04; 'say,': 0.05; 'context': 0.07; 'explicit': 0.07; 'nested': 0.07; 'english,': 0.09; 'lst': 0.09; 'python:': 0.09; 'scripts,': 0.09; 'subject:design': 0.09; 'wrapper': 0.09; 'subject:Help': 0.11; 'python': 0.11; "'a',": 0.16; 'blocks': 0.16; 'effect.': 0.16; 'inclined': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:API': 0.16; 'vastly': 0.16; 'window;': 0.16; 'world!")': 0.16; 'weird': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'acquired': 0.19; 'normally': 0.19; 'seems': 0.21; 'command': 0.22; 'example': 0.22; 'header:User- Agent:1': 0.23; 'documented': 0.24; 'simpler': 0.24; 'switched': 0.24; 'script': 0.25; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'michael': 0.29; 'rest': 0.29; 'chris': 0.29; 'am,': 0.29; 'generally': 0.29; "doesn't": 0.30; 'ignored.': 0.30; "i'm": 0.30; 'gives': 0.31; 'code': 0.31; 'easier': 0.31; 'reply.': 0.31; 'too.': 0.31; '(since': 0.31; 'block,': 0.31; 'context,': 0.31; 'received:192.168.1.3': 0.31; 'handled': 0.32; 'option': 0.32; '(i.e.': 0.33; 'maybe': 0.34; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'subject: (': 0.35; 'common': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'done': 0.36; 'should': 0.36; 'wrong': 0.37; 'thank': 0.38; 'manager': 0.38; 'actions': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'short': 0.38; 'does': 0.39; 'bad': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'called': 0.40; 'users': 0.40; 'easy': 0.60; 'commands': 0.60; 'dangerous': 0.60; 'most': 0.60; 'managers': 0.61; 'new': 0.61; 'march': 0.61; 'entire': 0.61; "you're": 0.61; 'further': 0.61; 'first': 0.61; "you've": 0.63; 'kind': 0.63; 'different': 0.65; 'afraid': 0.65; 'within': 0.65; '26,': 0.68; 'advantages': 0.68; 'feeling': 0.68; 'of:': 0.68; 'food': 0.72; 'to,': 0.72; 'miss': 0.74; "'with'": 0.84; 'balanced': 0.84; "it'd": 0.84; 'off,': 0.84; 'realistic': 0.93; '2013': 0.98
Date Tue, 26 Mar 2013 09:41:38 -0400
From Mitya Sirenef <msirenef@lightbird.net>
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.3706.1364254851.2939.python-list@python.org> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com>
In-Reply-To <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
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.3746.1364305302.2939.python-list@python.org> (permalink)
Lines 120
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364305302 news.xs4all.nl 6971 [2001:888:2000:d::a6]:53367
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41901

Show key headers only | View raw


On 03/26/2013 05:38 AM, Michael Herrmann wrote:
> On Tuesday, March 26, 2013  12:40:45 AM UTC+1, Mitya Sirenef wrote:
 >> ...
 >>
 >> I think I would prefer context managers. I don't think it's a big
 >> problem for
 >> win users because this behaviour would be one of the first things 
documented
 >> in the start guide and would be all over example scripts, so a new user
 >> missing
 >> or forgetting it is not a realistic scenario.
 >>
 >> The advantages are that it's explicit, blocks are indented and it's
 >> impossible to
 >> miss which window is the action applied to, and at the same time 
actions are
 >> short and easy to type and read.
 >
 > Thank you for your reply. What do you think of Chris Angelico's points?


At the __exit__, further commands are no longer routed to that window;
if it was a nested context, window is switched to the outer context,
WHEN there are commands in it (i.e. on the first command). This seems
pretty intuitive to me:

with notepad1:
     ^S
     with notepad2:
         ^S
     write('something')

>
 > He wrote:
 >> 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.
 >
 > What I am most afraid of: that the window that's currently the 
context "disappears":
 >     notepad = start("Notepad")
 >     with notepad:
 >         press(ALT + TAB)
 >         write("Am I in Notepad now?")


Alt-tab needs to be handled by a wrapper function that gives you the
object of the window you've switched to:

otherwin = alt_tab()
with otherwin:
     ...

If window is changed within 'with' block, the rest of block should be
ignored. Perhaps there could also be a way to switch this behaviour off,
for the entire script or for current block only.

>
 > What do you think of designs #3 and #4?
 >
 >         notepad_1 = start("Notepad")
 >         notepad_2 = start("Notepad")
 >         switch_to(notepad_1)
 >         write("Hello World!")
 >         press(CTRL + 'a', CTRL + 'c')
 >         switch_to(notepad_2)
 >         press(CTRL + 'v')
 >
 >         notepad_1 = start("Notepad")
 >         notepad_2 = start("Notepad")
 >         notepad_1.activate()
 >         write("Hello World!")
 >         press(CTRL + 'a', CTRL + 'c')
 >         notepad_2.activate()
 >         press(CTRL + 'v')
 >
 > I somehow prefer "activate" over "focus" as in my feeling, you'd 
normally say that you focus *on* something, so it should be called 
"focus_on" or "give_focus[_to]". Can you say, in everyday English, that 
you "focus a window"? I'm not a native speaker so maybe my feeling is 
misguided.


These are ok, too, but I feel it's much easier to send commands to a
wrong window vs. context managers. The same command in a different
window can have vastly different and dangerous effect. In other python
code that's generally not common at all, and would be bad style:

lst = lst1
lst.append('x')
del lst[3]
lst.insert(0, 'a')
lst = lst2
del lst[2]
lst.append('y')
lst = lst3
lst.insert(0, 'x')
lst += [1,2]


I think current window should also be acquired explicitly:

with get_current_window():
     type("some kind of snippet")

For usage when a command should apply to all types of windows.

HTH, -m



-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Food is an important part of a balanced diet.
Fran Lebowitz

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