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


Groups > comp.lang.python > #41870 > unrolled thread

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

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2013-03-26 11:07 +0100
Last post2013-03-26 04:52 -0700
Articles 5 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Re: Help me pick an API design (OO vs functional) Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-03-26 11:07 +0100
    Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 04:52 -0700
      Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-26 22:57 +1100
        Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 05:20 -0700
    Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 04:52 -0700

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

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2013-03-26 11:07 +0100
SubjectRe: Help me pick an API design (OO vs functional)
Message-ID<mailman.3727.1364292472.2939.python-list@python.org>
----- Original Message -----
> 	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')
> 
> The problem with this design is that it effectively duplicates our
> API: We want to keep our "global" functions because they are so easy
> to read. 

So is the example above. This is the best solution in my opinion. 
I think you're having the same issue that some other APIs, let's say matplotlib for example. They try to accommodate scientists (matlab) and programmers(python) by having a double API style.

One looks like

legend()
title()
plot()
save()

the other looks like

fig = figure()
fig.add_legend()
fig.title()
fig.plot()
fig.save()

The problem is, when searching for example on the net, you'll end up with a mix of both, it can become a nightmare.
I definitely prefer the later, for the reasons that have already been given to you in this thread and by the fact that with the correct (I)python shell, you can create your window object and get auto-completion on its methods just by hitting <tab>, very helpful when introspecting objects. Can be achieved of course in any python shell with function like dir() ; my point being that OOO design keeps things in their place, see the zen of python "Namespaces are one honking great idea -- let's do more of those!"

JM



-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

[toc] | [next] | [standalone]


#41883

FromMichael Herrmann <michael.herrmann@getautoma.com>
Date2013-03-26 04:52 -0700
Message-ID<dd54c915-9c81-4fa2-8b4a-99e8b45a2f5d@googlegroups.com>
In reply to#41870
On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant wrote:
> ----- Original Message -----
> > 	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')
> > 
> > The problem with this design is that it effectively duplicates our
> > API: We want to keep our "global" functions because they are so easy
> > to read. 
> 
> So is the example above. This is the best solution in my opinion. 

Thanks for your reply. What do you mean by "So is the example above" though? 

> I think you're having the same issue that some other APIs, let's say matplotlib for example. They try to accommodate scientists (matlab) and programmers(python) by having a double API style.
> 
> One looks like
> 
> legend()
> title()
> plot()
> save()
> 
> the other looks like
> 
> fig = figure()
> fig.add_legend()
> fig.title()
> fig.plot()
> fig.save()
> 
> The problem is, when searching for example on the net, you'll end up with a mix of both, it can become a nightmare.

Interesting point. I'll google a little about matplotlib.

> I definitely prefer the later, for the reasons that have already been given to you in this thread and by the fact that with the correct (I)python shell, you can create your window object and get auto-completion on its methods just by hitting <tab>, very helpful when introspecting objects. Can be achieved of course in any python shell with function like dir() ; my point being that OOO design keeps things in their place, see the zen of python "Namespaces are one honking great idea -- let's do more of those!"

Doesn't the IPython do auto-completion for "global" functions? 

Thanks,
Michael (www.getautoma.com)

[toc] | [prev] | [next] | [standalone]


#41885

FromChris Angelico <rosuav@gmail.com>
Date2013-03-26 22:57 +1100
Message-ID<mailman.3738.1364299470.2939.python-list@python.org>
In reply to#41883
On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann
<michael.herrmann@getautoma.com> wrote:
> Doesn't the IPython do auto-completion for "global" functions?

Even if it does, it'll be polluted with every other global. Methods
don't have that problem. On the flip side, since presumably this is
(will be) a module, anyone who wants autocomplete of its top-level
functions can simply "import module" instead of "from module import
*", which will do the same namespacing.

ChrisA

[toc] | [prev] | [next] | [standalone]


#41890

FromMichael Herrmann <michael.herrmann@getautoma.com>
Date2013-03-26 05:20 -0700
Message-ID<1a32e2c4-ca0d-4390-8dde-8345d8f7b28c@googlegroups.com>
In reply to#41885
On Tuesday, March 26, 2013 12:57:21 PM UTC+1, Chris Angelico wrote:
> On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann
> > Doesn't the IPython do auto-completion for "global" functions?
> 
> Even if it does, it'll be polluted with every other global. Methods
> don't have that problem. On the flip side, since presumably this is
> (will be) a module, anyone who wants autocomplete of its top-level
> functions can simply "import module" instead of "from module import
> *", which will do the same namespacing.

True! I don't think "polluting" the global namespace is that much of an issue.

[toc] | [prev] | [next] | [standalone]


#41884

FromMichael Herrmann <michael.herrmann@getautoma.com>
Date2013-03-26 04:52 -0700
Message-ID<mailman.3737.1364298778.2939.python-list@python.org>
In reply to#41870
On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant wrote:
> ----- Original Message -----
> > 	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')
> > 
> > The problem with this design is that it effectively duplicates our
> > API: We want to keep our "global" functions because they are so easy
> > to read. 
> 
> So is the example above. This is the best solution in my opinion. 

Thanks for your reply. What do you mean by "So is the example above" though? 

> I think you're having the same issue that some other APIs, let's say matplotlib for example. They try to accommodate scientists (matlab) and programmers(python) by having a double API style.
> 
> One looks like
> 
> legend()
> title()
> plot()
> save()
> 
> the other looks like
> 
> fig = figure()
> fig.add_legend()
> fig.title()
> fig.plot()
> fig.save()
> 
> The problem is, when searching for example on the net, you'll end up with a mix of both, it can become a nightmare.

Interesting point. I'll google a little about matplotlib.

> I definitely prefer the later, for the reasons that have already been given to you in this thread and by the fact that with the correct (I)python shell, you can create your window object and get auto-completion on its methods just by hitting <tab>, very helpful when introspecting objects. Can be achieved of course in any python shell with function like dir() ; my point being that OOO design keeps things in their place, see the zen of python "Namespaces are one honking great idea -- let's do more of those!"

Doesn't the IPython do auto-completion for "global" functions? 

Thanks,
Michael (www.getautoma.com)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web