X-Received: by 10.224.172.200 with SMTP id m8mr7442617qaz.0.1364290681808; Tue, 26 Mar 2013 02:38:01 -0700 (PDT) X-Received: by 10.49.104.144 with SMTP id ge16mr521736qeb.19.1364290681758; Tue, 26 Mar 2013 02:38:01 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!ca1no7704283qab.0!news-out.google.com!k8ni11100qas.0!nntp.google.com!ca1no7704280qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Tue, 26 Mar 2013 02:38:01 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=89.68.221.197; posting-account=oknH1QoAAABqzbD_5ziFTvLQsqNk2LbU NNTP-Posting-Host: 89.68.221.197 References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Subject: Re: Help me pick an API design (OO vs functional) From: Michael Herrmann Injection-Date: Tue, 26 Mar 2013 09:38:01 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.python:41868 On Tuesday, March 26, 2013 12:40:45 AM UTC+1, Mitya Sirenef wrote: > ... >=20 > I think I would prefer context managers. I don't think it's a big=20 > problem for > win users because this behaviour would be one of the first things documen= ted > in the start guide and would be all over example scripts, so a new user= =20 > missing > or forgetting it is not a realistic scenario. >=20 > The advantages are that it's explicit, blocks are indented and it's=20 > 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? He wrote: > What happens at the __exit__ of the context manager? What happens if=20 > context managers are nested? I'd be inclined to the simpler option of=20 > an explicit switch (since focus doesn't really "stack" and it'd feel=20 > weird for focus to *sometimes* switch away when you're done working=20 > with one window), though the context manager syntax does have its=20 > advantages too.=20 What I am most afraid of: that the window that's currently the context "dis= appears": notepad =3D start("Notepad") with notepad: press(ALT + TAB) write("Am I in Notepad now?") What do you think of designs #3 and #4? notepad_1 =3D start("Notepad")=20 notepad_2 =3D start("Notepad")=20 switch_to(notepad_1)=20 write("Hello World!")=20 press(CTRL + 'a', CTRL + 'c')=20 switch_to(notepad_2)=20 press(CTRL + 'v')=20 notepad_1 =3D start("Notepad")=20 notepad_2 =3D start("Notepad")=20 notepad_1.activate()=20 write("Hello World!")=20 press(CTRL + 'a', CTRL + 'c')=20 notepad_2.activate()=20 press(CTRL + 'v') I somehow prefer "activate" over "focus" as in my feeling, you'd normally s= ay that you focus *on* something, so it should be called "focus_on" or "giv= e_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. Thanks, Michael