Help me pick an API design (OO vs functional)

Michael Herrmann michael.herrmann at
Tue Mar 26 10:06:18 CET 2013

On Tuesday, March 26, 2013 12:11:34 AM UTC+1, Ethan Furman wrote:
> On 03/25/2013 12:29 PM, Michael Herrmann wrote:
> ...
> >
> > 	notepad_1 = start("Notepad")
> > 	notepad_2 = start("Notepad")
> > 	notepad_1.write("Hello World!")
> > + 'a', CTRL + 'c')
> > + 'v')
> This is the way to go.  Just move your global functions into the Window object (or whatever you call it), break 
> backwards compatibility (major version number change, perhaps?), and call it good.
> It makes much more sense to call methods of several different objects (which is explicit -- you always know which object 
> is being used) than having a magic function that changes the object in the background (plus you now have to search 
> backwards for the last magic invocation to know -- and what if a called function changes it?).

Your points are valid and I cannot really say anything against them. The problem with moving all global functions into the Window object is that this adds a lot of syntactic baggage that isn't needed in 90% of the cases. We really prefer the simplicity of

	write("Hello World!")
	press(CTRL + 's')
	write("test.txt", into="File name")
	press(ALT + F4)


	notepad = start("Notepad")
	notepad.write("Hello World!") + 's')
	notepad.write("test.txt", into="File name")"Save") + F4).

Also, there's a problem here: The "Save" dialogue that opens in the above script is technically a different window so in theory you would have to introduce a new object to distinguish between the original window that lets you edit your text document from the "Save" window. This is very tedious and error-prone. You are right, though, that we have to do some logic in the background to remember the last window.

In light of this, could you live with something along the lines of design #4?

        notepad_1 = start("Notepad") 
        notepad_2 = start("Notepad") 
        write("Hello World!") 
        press(CTRL + 'a', CTRL + 'c') 
        press(CTRL + 'v') 


More information about the Python-list mailing list