“Readability Counts.”
“Explicit is better than Implicit.”
“Beautiful is better than ugly.”
– The Zen of Python🌻
Professional software engineering requires your code to be in a certain format which makes it more readable to others.
PEP (Python Enhancement Proposal) documents define such practices that must be followed.
3 of the best ones:
- Naming conventions: Variables, functions, methods must be lower case and separated with underscores. Ex. def add_after_mul()
Also, the names should be sensible and explain what the variable stands for. Don’t do a = ‘chayan’. Do first_name = ‘chayan’.
- Whitespaces: Always include a whitespace after a comma, after a colon and either sides of assignment operators, comparison operators and booleans (and/or/not).
If a logic has all the above operators, only give whitespace around booleans and not around all of them.
Don’t do if a > 5 and b < 10 :
Do if a>5 and b<10 :
- Line breaking: Don’t go beyond 80 characters per line. Break to new line by putting commas if it’s a function pass.
Otherwise use a backslash character.
Also, don’t chain too many methods which will again reduce readability.
Do you follow these practices while coding?
#python #datascience #machinelearning