constructors (Re: [Bf-python] More Proposed API changes.)

Campbell Barton cbarton at metavr.com
Tue Mar 13 12:33:31 CET 2007


Toni Alatalo wrote:
> just talked a bit with Campbell on IRC and I thought a nice idea came up:
> 
> < ideasman_42> antont, thinking about what your saying - "we'll use this 
> for the next 5 years"
> < ideasman_42> How about we put a big disclaimer "Wont stabilize until 
> 2.5!!"
> < antont> ideasman_42: that might be a good idea. 'new experimental
>                module under design - usage feedback and ideas welcome'
> 
> there was a nice talk recently about API design by a Google fellow, the 
> video is available via e.g. 
> http://www.bestechvideos.com/2007/02/26/how-to-design-a-good-api-and-why-it-matters/ 
> and similar older slides by the same fellow at e.g. 
> lcsd05.cs.tamu.edu/slides/keynote.pdf (html version 
> http://209.85.135.104/search?q=cache:MmIXuflmcvcJ:lcsd05.cs.tamu.edu/slides/keynote.pdf+why+api+design+matters&hl=fi&ct=clnk&cd=1&gl=fi&client=firefox-a) 
> 
> 
> IIRC one point he brings up is getting feedback from users, testing new 
> api againts actual use cases etc - so I think that would align nicely 
> with the idea of labeling bpy 'experimental' so far.

Antonts comparisons are with python libraries, whereas blender uses 
python as an extension language so were not comparing exactly the same 
things.

My intention in the new API is that it reflects blenders own data structure.

I believe this is important, from looking at many scripts, even some in 
Blender's bundle, the scripters are often not aware of how the data is 
connected.
There were some cases where scripts would operate objects from ALL 
SCENES! - this is totally evil because you dont realize your data's 
hosed until you switch scenes, after saving etc... not nice.

so allowing the user to do..
   ob = bpy.Object()

lets them add objects without realizing that the object is being added 
to a scene's objects, or that a scene stores an object at all.

after that they might make the mistake of doing somthing like...

obsel = []
for ob in bpy.objects:
	if ob.sel:
		obsel.append(ob)

which wont raise any errors if you only have one scene.
since the selection state depends on the active scene.


Id rather force them to add an object through the scene...

Another example is the sequencer,

	seq = bpy.Sequence()

IMHO the following is better
	scn = bpy.scenes.active
	scnseq = scn.sequence
	seq = scnseq.new(...)

This is also more flexible since you can add sequences to a metastrip...

of course with antonts proposal we could pass the container as an argument,
	seq = bpy.Sequence(some_metastrip)

Id rather enforce the location data is being created be explicit ratehr 
then automatic, makes for easier reading others scripts too. and users 
who dont understand the API so well arnt going to thrash blender by 
switching scenes when they dont need to.



More information about the Bf-python mailing list