不太讲究的个人开发很少说到编码风格的问题,“我觉得还行,方便我理解”,“我习惯了,舒服“,”我不太了解这些东西“,这似乎没什么问题。
但在团队合作中,就需要统一的编码风格,这对后期的代码维护相当重要,想想不断给上家的代码添加注释的痛苦过程。统一编码风格的目的就是为了降低交流成本。
我们应该在理解工具设计哲学的基础上,于实践中遵循官方的建议。
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!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/98124.html