[Tutor] Python Best Practice/Style Guide question
Scott SA
pydev at rscorp.ab.ca
Tue Apr 29 18:22:08 CEST 2008
Per the interesting read at <http://www.python.org/dev/peps/pep-0008/>
Can anyone explain the rationale behind this:
- More than one space around an assignment (or other) operator to
align it with another.
Yes:
x = 1
y = 2
long_variable = 3
No:
x = 1
y = 2
long_variable = 3
The example is rather simplistic and I find the latter form much easier to read when there is more than three or four assignments. Furthermore, I don't like the use of 'x' and 'y' style variables for anything but classical references and concise loops favoring 'chart_x' and 'chart_y' (I have a crappy memory, more descriptive names help me, and those reading my code, keep track of what I'm doing).
I _do_ see that in this example, it could be hard to follow which value is assigned to its respective name, but considering this _slightly_ less simplistic (though flawed) example:
string_item = some_method(with_argument)
y = 2
long_variable = antoher_method(with, multiple, arguments)
another_string_item = some_method(with, more, arguments)
Is easier to read (for me) as follows:
string_item = some_method(with_argument)
y = 2
long_variable = antoher_method(with, multiple, arguments)
another_assignment = some_method(with, more, arguments)
_Yes_ the order can be changed, but there are reasons why it might be inapropriate to reorder i.e. dependencies.
TIA,
Scott
PS. There is a good best-practice link here too:
<http://www.fantascienza.net/leonardo/ar/python_best_practices.html>
More information about the Tutor
mailing list