Python之禅 by Tim Peters

本文深入探讨了Python语言设计哲学的精髓,从简洁性、可读性和错误处理等角度出发,详细解读了‘Pythonic’编程原则。通过引用经典语录,强调了代码的美感、清晰度和效率的重要性,为Python开发者提供了宝贵的指导。

python语言之父对python设计之初提出了规范和风格,名为“Pythonic",它指的是以Python的方式去编写代码、组织逻辑和对象行为。更久以后你才会真正理解它的含义,你可以从PEP中了解,也可以在Python解析器中输入import this回车查看。

>>> 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://my.oschina.net/Barudisshu/blog/380792

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值