Tuesday, 21 April 2015

Python coding principles


Write readable code. It is all about choosing right names, putting that extra blank line between functions etc.

Do not make it complex. Simplify.

Beauty is in simplicity

Make less assumptions. Refuse temptation to guess. Suppose you are trying to access a dictionary with a key, don't assume that key value always present in dictionary.

Don't finish it immediately. Take time.

If implementation is hard to explain, it is a bad idea.

If implementation is easy to explain, it may be a good idea.

Don't repeat yourself. Commonly used task, make it as a function.

Premature optimization is root of evil. First make it work. It doesn't mean you should think about optimizing the code initially. Strike a balance.

Be conservative in what you do, be liberal in what you accept. Means your code allow variations in incoming data.


No comments:

Post a Comment