I am running on schedule as per the coding but for the book reading, I'm a bit late. In the above video, you can see the library for creating a controller which will be aligned properly to a joint whose x-axis is following the joint hierarchy. I used this because most of the times I will be creating joints like this only. So, setting up the joint controls are pretty fast now along with a group as the parent of the control. Also, based on the prefix, the color of the control is set automatically now, for example - L_arm_ctrl will be Red, R_arm_ctrl will be Blue and Spine_ctrl will be yellow.
I used the control creation class in another class "Module" where I am just creating a group hierarchy for organization, along with creating the root controls. Next step will be to properly align the root controls and finish creating the library and properly commenting the code of this library.
Some points I learned from the book- Practical Maya Programming with Python-
- Use append() instead of concatenating because it is easier to test, is fast, efficient and clean and is more pythonic.
- Method resolution order (MRO) - The order python visits different types so it can figure out what to actually call. Example-
>>>import pymel.core as pmc
>>>j = pmc.joint()
>>>type(j).__mro__
# Result: (<class 'pymel.core.nodetypes.Joint'>,
<class 'pymel.core.nodetypes.Transform'>,
<class 'pymel.core.nodetypes.DagNode'>,
<class 'pymel.core.nodetypes.Entity'>,
<class 'pymel.core.nodetypes.ContainerBase'>,
<class 'pymel.core.nodetypes.DependNode'>,
<class 'pymel.core.general.PyNode'>,
<class 'pymel.util.utilitytypes.ProxyUnicode'>,
<type 'object'>) #
Above code snippet shows the type hierarchy and in the end, everything is an object in python.
- Liskov Substitution Principle:- If S is a subclass of T, then a program can use an instance of S instead of T without a change in behavior.
- Test Driven Development (TDD)- Practice it while creating a project by creating a function for a task and a test function with assertion statements for test conditions. The clearer the test conditions are, the better your code will be.
- Design with EAFP (Easier Asking Forgiveness than Permission) rather than LBYL (Look Before You Leap) methodology. You will fail quick and that's a win, since you can iterate fast.
Writing Composable Code
- Avoid the use of multiple boolean flags (might cause CODE SMELL)
- Never have arguments that are mutually exclusive or interfere with each other
- Better to be verbose and pass in what is needed than it is to perform calculations and controlled by flags
There is more learning and I'm loving this book since it is helping me to write clean and clear code. Will update you next week on more ways of writing composable code.
Peace.
Comments