Help me pick an API design (OO vs functional)
steve+comp.lang.python at pearwood.info
Tue Mar 26 13:59:58 CET 2013
On Tue, 26 Mar 2013 05:04:43 -0700, Michael Herrmann wrote:
> On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote:
>> Seems to me that the official interface should all be methods.
>> However, you could have a new object which always represents the
>> "focus" window.
>> Then the USER could define trivial functions:
>> def write(*args):
> It's an interesting idea. But why not give this write(...) to them in
> the first place? Am I the only one who appreciates 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!")
> notepad.press(CTRL + 's')
> notepad.write("test.txt", into="File name")
> notepad.press(ALT + F4)?
You are not the only one.
I suggest that you have a set of functions that work on "the current
window", whatever that is. Preferably there should always be a current
window, but if not, ensure that you give a clear error message.
Then you have syntax for operating on any named(?) window. So a user can
implicitly operate on the current window:
write("goodbye cruel world")
or explicitly on any window they like:
I suggest you dig up an old book on "Hypercard", for Apple Macs in the
1980s and 90s. Back in the day, Macs could only run a single application
at a time, and Hypercard was limited to a single window at a time (called
a "stack"). But that stack (think: window) could have multiple
"cards" (think: window tabs), one of which was always current.
Hypercard's built-in programming language Hypertalk let you do things
go to stack "Notepad"
type "goodbye cruel world" in field "main" of card 7
click button "Save"
click button "Quit" of card "Main" of stack "Excel"
(more or less... it's been a few years since I've had a classic Mac
capable of running Hypercard.)
More information about the Python-list