I'm designing a Python application yet I'm unable to figure out how to setup the preferred coding interface I want for it. (The first implementation will not have a GUI.)
I want the user to be able to do something like in design 1, but currently have it implemented as in design 2:
#
# Design 1
#
import myApp.core as myApp
myApp.new()
element = myApp.createElement()
element.rename("foo")
print element.name()
path = "C:/foo.txt"
myApp.save(path)
.
#
# Design 2
#
import myApp.core as myApp
scene = myApp.new()
element = scene.createElement()
element.rename("foo")
print element.name()
path = "C:/foo.txt"
scene.save(path)
Based on my experience as an artist working with Autodesk Maya I'm familiar with working in a setup like in design 1 it feels very logical. It doesn't feel like you're running methods on a singleton class that represents the application. Instead it feels like you're always within the application.
With design 1 we could use 'from myApp.core import *' to get all the commands easily accessible. With design two it would be that I either need to have a singleton class that contains the functions as methods or I would need to 'feed' the global application into each function.
To get something working like design 1 I think it's something with global variables or something that tracks the application's state so the functions know on what 'scene' to perform their actions. Yet as I've so far managed to live without using such setups I have no clue on what would be the best way to go about doing this.
If there's a very good reason not to do it like in design 1 let me know and I'll change accordingly. As any interface it should be efficient and very easy to use.