Good Programming Naming Conventions

  • Start with a verb for functions that do not return a boolean, e.g. refresh_cache(), get_address(), insert()
    • for functions that return a boolean, start the name with is if possible, e.g. is_empty()
  • Name parameters using natural language, e.g, insert(at=1)
  • Being consistent when naming similar functionalities, e.g. list.add(), set.add()
  • Use natural language instead of one character variable name (unless it is a math formula), e.g. each = getEnumeration(), instead of e = ...
    • it is common to use i in a for-loop and x,y for coordinates, e for exceptions
  • Limit identifier names to 20 characters
  • Include units in a name, e.g. distanceInCentimeters, elapsedTimeInDdays
  • Class and object names should be a noun, e.g. Customer, WikiPage
  • If a variable name is used multiple times, it should be searchable (avoid using single characters)
  • Functions should only do one thing, thus their names should reflect that (instead of being ambiguous)

For Python:

  • Avoid dashes in any package/module name
  • avoid __double_leading_and_trailing_underscore__ names 

Recommended naming conventions for Python:

module_namepackage_nameClassNamemethod_nameExceptionNamefunction_nameGLOBAL_CONSTANT_NAMEglobal_var_name,instance_var_namefunction_parameter_namelocal_var_name.

Reference:
https://dmitripavlutin.com/coding-like-shakespeare-practical-function-naming-conventions/
http://wiki.c2.com/?GoodVariableNames
https://medium.com/coding-skills/clean-code-101-meaningful-names-and-functions-bf450456d90c

 

Cheng

 

Leave a Reply

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

Bitnami