不太讲究的个人开发很少说到编码风格的问题,“我觉得还行,方便我理解”,“我习惯了,舒服“,”我不太了解这些东西“,这似乎没什么问题。
但在团队合作中,就需要统一的编码风格,这对后期的代码维护相当重要,想想不断给上家的代码添加注释的痛苦过程。统一编码风格的目的就是为了降低交流成本。
我们应该在理解工具设计哲学的基础上,于实践中遵循官方的建议。
python官方文档:PEP 8 – Style Guide for Python Code Google Python Style Guide:styleguide
The Zen of Python:
>>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!