diff options
author | Christian Heimes <christian@cheimes.de> | 2008-01-07 17:19:16 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-01-07 17:19:16 (GMT) |
commit | 043d6f67c7b79a6d268c6ad31d8ff7710ac3e5ee (patch) | |
tree | 0ea113cd3a06b4ecbb27a82154174e1846ce1804 /Doc/tutorial/controlflow.rst | |
parent | 13a7a21258f0cd241c2cf1367a954d6742daa2a6 (diff) | |
download | cpython-043d6f67c7b79a6d268c6ad31d8ff7710ac3e5ee.zip cpython-043d6f67c7b79a6d268c6ad31d8ff7710ac3e5ee.tar.gz cpython-043d6f67c7b79a6d268c6ad31d8ff7710ac3e5ee.tar.bz2 |
Copied doc for reload() from trunk's function.rst to imp.rst
Diffstat (limited to 'Doc/tutorial/controlflow.rst')
-rw-r--r-- | Doc/tutorial/controlflow.rst | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 5b05aed..3fedb56 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -595,10 +595,57 @@ Here is an example of a multi-line docstring:: No, really, it doesn't do anything. +.. _tut-codingstyle: + +Intermezzo: Coding Style +======================== + +.. sectionauthor:: Georg Brandl <georg@python.org> +.. index:: pair: coding; style + +Now that you are about to write longer, more complex pieces of Python, it is a +good time to talk about *coding style*. Most languages can be written (or more +concise, *formatted*) in different styles; some are more readable than others. +Making it easy for others to read your code is always a good idea, and adopting +a nice coding style helps tremendously for that. + +For Python, :pep:`8` has emerged as the style guide that most projects adher to; +it promotes a very readable and eye-pleasing coding style. Every Python +developer should read it at some point; here are the most important points +extracted for you: + +* Use 4-space indentation, and no tabs. + + 4 spaces are a good compromise between small indentation (allows greater + nesting depth) and large indentation (easier to read). Tabs introduce + confusion, and are best left out. + +* Wrap lines so that they don't exceed 79 characters. + + This helps users with small displays and makes it possible to have several + code files side-by-side on larger displays. + +* Use blank lines to separate functions and classes, and larger blocks of + code inside functions. + +* When possible, put comments on a line of their own. + +* Use docstrings. + +* Use spaces around operators and after commas, but not directly inside + bracketing constructs: ``a = f(1, 2) + g(3, 4)``. + +* Name your classes and functions consistently; the convention is to use + ``CamelCase`` for classes and ``lower_case_with_underscores`` for functions + and methods. Always use ``self`` as the name for the first method argument. + +* Don't use fancy encodings if your code is meant to be used in international + environments. Plain ASCII works best in any case. + .. rubric:: Footnotes -.. [#] Actually, *call by object reference* would be a better description, since if a - mutable object is passed, the caller will see any changes the callee makes to it - (items inserted into a list). +.. [#] Actually, *call by object reference* would be a better description, + since if a mutable object is passed, the caller will see any changes the + callee makes to it (items inserted into a list). |