Coding Conventions

Unlike many other languages, Python has an official coding convention called the PEP8 standard. A coding convention describes the style rules and format of your code. It is by no coincidence that all the code examples listed so far use underscore_separated variable and function names, four spaces for indentations, and CaptilizedCamelCase for class names. These conventions are all part of the PEP8 standard. You’ll notice however that Maya does not follow the PEP8 standard. The main reason for this is that the Python API is generated procedurally from the C++ API. When writing Python code, I highly encourage you to follow the PEP8 standard even if you prefer or have used a different convention in the past.

Most of the Python world uses the PEP8 standard. Unless you are working in an existing codebase, try to use the official and accepted standard. The only time not to follow PEP8 conventions (as noted in PEP8 itself) is to follow the standard of the existing codebase you are working with. You do not need to follow every single little rule, just be consistent.

You can read more about the PEP8 standard here.

PEP8 Quick Notes

># Class names
class MyClassName(object):  # Yes
class myclassName(object):  # No

# Variable names
skin_joints = ['joint1', 'joint2']  # Yes
skinJoints = ['joint1', 'joint2']  # No

# Function names
def calculate_bounds():  # Yes
def calculateBounds():  # No

# Spacing
[1, 2, 3, 4]  # Yes
[1,2,3,4]  # No

if joint_height > 10.0:  # Yes
if joint_height>10.0:  # No

get_export_nodes(root='skeleton_grp')  # Yes
get_export_nodes( root = 'skeleton_grp' )  # No

Leave A Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

<code> For inline code.
[sourcecode] For multiline code.