Help me pick an API design (OO vs functional)

Jean-Michel Pichavant jeanmichel at sequans.com
Tue Mar 26 11:07:45 CET 2013


----- 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.


More information about the Python-list mailing list