2016年10月12日 星期三

九陰真經與The Zen of Python

先說金庸小說射鵰英雄傳裡一段故事,黃蓉使詐,騙歐陽鋒逆練九陰真經走火入魔的情節,有一段黃蓉故意胡謅一通,直令西毒先生抓破頭,仍是不知所云。

這可跟The Zen of Python對比:

  • 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!

工程師可以做出晦澀、難解、糾結的ugly design or implementation,或是像Assembly code,甚而不留comment,弄到後來只有他自己才能看懂。

這樣一來,老闆大概就是西毒了,恐怕沒死也剩半條命。