554e718550190e75821cf585f6123ee55bd3d551 vsmalladi Tue Apr 24 11:42:04 2012 -0700 Added guidlines for length's of modules, functions and methods. Redmine #7162. diff --git python/style.txt python/style.txt index ce89a67..0f138f6 100644 --- python/style.txt +++ python/style.txt @@ -47,30 +47,32 @@ In complex cases you may treat the abbreviation itself as a word, and only the first letter is capitalized: genscanTabSeparatedFile -> genscanTsf Numbers are considered words. You would represent "chromosome 22 annotations" as "chromosome22Annotations" or "chr22Ann." Note the capitalized 'A" after the 22. Packages and Modules In Python, a package is represented as a directory with an __init__.py file in it, and contains some number of modules, which are represented as files with a .py extension. A module may in turn contain any number of related classes and methods. This differs from Java, where one file correlates to one class: in Python it is correct to treat one module similar to a whole namespace in Java. +In general try to keep modules on the order of 100's of lines. + Internal packages and modules should have short names in mixedCase, with no spaces or underscores. A good example of this style is the ucscGenomics package: ucscGenomics/ __init__.py ra.py cv.py ... For more information: http://docs.python.org/tutorial/modules.html Imports The most correct way to import something in Python is by specifying its containing module: @@ -103,35 +105,39 @@ For more information, see the "Imports" section: http://www.python.org/dev/peps/pep-0008/ Classes CapitalCase names. Note the leading capital letter to distinguish between a ClassName and a functionName. Underscores are not used, except for private internal classes, where the name is preceded by double underscores which Python recognizes as private. Methods mixedCase names. The leading character is not capitalized, but all successive words are capitalized. Underscores are not used, except for private internal methods, where the name is preceded by double underscores which Python recognizes as private. +In general try to keep methods around 20 lines. + Functions mixedCase names. The leading character is not capitalized, but all successive words are capitalized. +In general try to keep methods around 20 lines. + Variables mixedCase names. Underscores are not used, except for private internal variables, where the name is preceded by double underscores which Python recognizes as private. COMMENTING Note: Still working out which automation document tool to use. Automated documentation is carried out using the Epydoc tool: http://epydoc.sourceforge.net/ Comments should follow the conventions: 1. Every module should have a paragraph at the beginning. Single class modules may