Naming conventions for code elements
The naming conventions discussed earlier in the Style standards for code section in Chapter 6, Code Style and Related Standards cover, for lack of a better description, what various code elements’ names should look like. They do not really describe what the content of those names should be, though. There are several best practices that apply to that facet of code-element naming, which boil down to the following two very basic rules:
- Make the names of all code elements — classes, functions, methods, arguments, and variables — meaningful within the scope that they live in.
- Be aware of where the boundaries between those scopes exist.
Consider, as an example, this function:
def colss(c_id):
c = gc(c_id)
ods = gc_o(c)
ss = {}
for o in ods:
if o.shipper == 'USPS':
ss[o.oid] = check_usps(o)
elif o.shipper == 'UPS':
ss[o.oid] ...