
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.
稀疏好于密集
(Python代码之间应该是有间隔的,每个功能块、每个函数、每个参数、每个类之间应当有适当的间距)
Readability counts.
代码可读性很重要
(Python代码具有很好的可读性,注释、变量名、函数名、类名、模块名、代码块功能等的作用和意义都是一目了然的)
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
**虽然实用性很重要,但任何特殊情况都不足以特殊到违背上述规则
(不要为了处理某一个特殊情况,而破坏了上述任何一个规则)
Errors should never pass silently.
Unless explicitly silenced.
不要忽视任何错误,除非有意为之(任何时候都要对异常和错误进行处理,不要写 except:pass 风格的代码)
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.
虽然起初这很难做到,除非你是荷兰人(荷兰人暗指 Python之父:Guido van Rossum(龟叔) )
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!
命名空间是一个很棒的注意,应当多加利用
Hello World!
你好,世界!
The Zen of Programming
One
Programs are but dreams
Born in formless, shapeless Zen.
We are but dreamers.
Two
I programmed three days
And heard no human voices.
But the hard disk sang.
不知道的还以为在看纪伯伦的诗
Three
The compiler runs
Like a swift-flowing river.
I wait in silence.
Four
Why do you use LISP?
I understand COBOL not.
Therefore I use LISP.
四
为何要用LISP?
COBOL语言我不懂,
所以我用LISP。
?
Five
I programmed all night.
Through the window, on my screen,
The rising sun shined.
Six
Hardware and software,
We are your slaves and masters,
Our lives are programs.
6 ,有点意思
Seven
Can you hear the sound
Of a program on the desk?
The answer is NUL.
Eight
I read my E-Mail.
The project has been cancelled.
Purging files, I weep.
Nine
The computer center is empty,
Silent except for the whine of the cooling fans.
I walk the rows of CPUs,
My skin prickling with magnetic flux.
I open a door, cold and hard,
And watch the lights dancing on the panels.
A machine without soul, men call it,
But its soul is the sweat of my comrades,
Within it lie the years of our lives,
Disappointment, friendship, sadness, joy,
The algorithmic exaltations,
The long nights filled with thankless toil,
I hear the echoes of sighs and laughter,
And in the darkened offices
The terminals shine like stars.
九
计算中心空空荡荡,
静静的只有风扇在嗡鸣。
我走过一排排的CPU,
磁通量刺痛了我的皮肤。
我打开一扇门,又冷又硬,
看见指示灯在控制板上跳动。
一台没有灵魂的机器,人们说,
但它的灵魂是同事们的汗水,
在它里面有我们多年的生命,
失望,友谊,悲伤,欢乐,
算法成功时的狂喜,
和无数个徒劳无获的长夜。
我听见了叹息和欢笑的回声,
在这间黑洞洞的办公室里,
终端机闪耀着光芒,就像星星一样