Hello,
first of all, I've been reading many discussions about when to use what. 
Here is a recap of what I've reasearch:
.Don't use getters/setters in python, because those are from other idioms. 
getters and setters are meant are use to access private attributes, but 
since in python there is no real encapsulation (it is a naming convention), 
there is no need.
.Properties are cleaner. E.g: *myNodeA.getx() + myNodeB.getx()* is not as 
clear as *myNodeA.x + myNodeB.x* 
.Use properties only for real only attributes (but doesn't that contradict 
the example above? we can do *myNodeA.x = 5*
.If someone decide to convert an attribute into a property (e.g, instead of 
*self.myName*, me want a funcion *def myName()*, using @property will not 
break the code.

Will all that info, I still had doubts. So I decided to look at OpenMaya 
2.0 which is meant to be pythonic. So here are some examples
*MBoundingBox *has the following as properties --> *center, depth, height, 
max, min, width*. That make sense because those are only readable I guess. 
You can't set them as you want, si it doesn't make sense to do *getCenter(), 
getDepth()*....
*MDagPath *has no properties at all. It has* .child(), childCount(), 
apiType()*.... but aren't those readable only too?! so why not just *child, 
childCount, apiType.*
*MObject* has as property *apiTypeStr*, but a method called* apiType() *!! 
what the hell XD? why don't do both as properties?

So yea..looking at OpenMaya 2.0 did not make things more clear.
Here is how I use properties:
. I don't like *node.getName()* and *node.setName("foo")*, I prefer* 
node.name* and *node.name = "foo"*. I find it cleaner.
. If I have different option of getting something, I need an argument, so I 
don't use property. E.g: *node.getMatrix(world=True), 
node.getMatrix(world=False*).
. in scientif libraries: I do *vector.magnitude, **vector.magnitude = 10*, 
instead of* vector.getMagnitude(), vector.setMagnitude(10)*

What is your take on that? Cheers,
R

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/c34f5e0c-2b7a-42a5-856d-84b38ad5f5c3o%40googlegroups.com.

Reply via email to