Help me pick an API design (OO vs functional)

Michael Herrmann michael.herrmann at getautoma.com
Tue Mar 26 07:52:49 EDT 2013


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)



More information about the Python-list mailing list