python styles: why Use spaces around arithmetic operators?
J.B. Brown
jbbrown at sunflower.kuicr.kyoto-u.ac.jp
Wed Jul 28 03:41:38 EDT 2010
I personally prefer to be slightly excessive in the amount of spacing
I used, especially when parentheses are involved.
In no way do I assert that my code style is right for all situations,
but here are a few examples of my personal style.
---
myTuple = ( 1, 2, 3, 4, 5 ) # Comment about what this tuple will
conceptually represent or store.
myTuple2 = ( 1, 2, 3*myFunc(4), 4*myFunc2( "text arg" ), ) # Yes, I
leave the tailing comma for spacing and to remind myself it is a
tuple/list.
textFieldWidth = 80 / numFields # Balance width of fields
fileObject.write( "My text goes here. Value of some function = " +
str( someFunc( argList ) ) ) # Write out results.
---
Combining my code style with the parenthesis/brace/bracket
highlighting feature of Vi/Vim makes it easy for me to figure out if I
have closed all braces, and additionally what is the context in which
I am nesting functions or arguments.
Again, this is just my preference, but it emerged over time after many
hours of development and debugging on remote machines where only a
terminal environment and a text-based editor are available.
Even in my comments, in which I _strongly_ believe in a minimum of 1
comment line per 3 code lines (1:3) though I often code 1:2 or 1:1, I
use the parenthesis style above.
Example:
# The true positive rate of an experiment is calculated as: TPR = [ TP
/ ( TP + FN ) ] .
Just food for thought.
J.B. Brown
Kyoto University
More information about the Python-list
mailing list