Readable Python
Python code is easily readable. But nothing is perfect and some things can be improved in this field too. When I'm writing code in Python following formating helps me a lot:
"self" or "me"
Python has this special keyword which is reference to object on which current method was invoked. It is not only useful but in most cases necessary to have it!
In most languages this keyword is constant, like in C++ keyword "this". But in Python this keyword can be any arbitrary word, just need to be first on the method parameters list. Despite this freedom in choosing name for it, everybody follows kind of standard using word "self".
def method1( self , x, y ):
I don't think it is bad decision, it is quite similar to "this" word in length and meaning. But in python it has to be typed more times than in C++. So why not to use shorter word? I want to propose new "trend" of using word "me" instead of "self".
def method1( me , x, y ):It works for my projects much better than "self". And usage statistics of variable "me" is quite rare in all code samples.
Spaces around
Lets look at such python expression:
run(objX, param1, x, y)This is typical function call.
Now lets change formatting:
run( objX, param1, x, y )Change is little, but readability is highly improved. No much time need to be spent looking for first parameter.
Now lets look at this:
run( get( objX, x, y ), opt( objX, x, y ), x, y)We can use more spaces to indicate nesting level
run( get( objX, x, y ), opt( objX, x, y ), x, y )
- Log in to post comments