iT邦幫忙

2018 iT 邦幫忙鐵人賽
1

我在兩個月前的鐵人賽中寫了Django與Rails的比較,現在看來有些許幼稚之處。轉念一想,也是因為寫出來才有辦法痛改前非,算是逼自己成長的方法之一。

討論到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!
-- by Tim Peters

網路上解釋這首充滿「禪意」的詩很多,我今天想特別提出來討論的是「Explicit is better than implicit」,如果翻為中文可以理解為「明示勝於暗示」。這同時也在Django官方文件中,專門解釋設計哲學的地方特別提到:

This is a core Python principle listed in PEP 20, and it means Django shouldn’t do too much “magic.” Magic shouldn’t happen unless there’s a really good reason for it. Magic is worth using only if it creates a huge convenience unattainable in other ways, and it isn’t implemented in a way that confuses developers who are trying to learn how to use the feature.

從這點去理解,就知道為什麼Python不喜歡像是Rails裡常用的「黑魔法」,即使相當便捷誘人。有鑑於此,批評Python或是Django不如Ruby on Rails一般「有如神助」,我覺得是對他們的語言精神的不夠尊重,在這點上只能說精神立意不同,端看工程師如何取捨。

至於核心精神的好壞,這可能需要更多年的廝殺才會有結論的,我也不敢妄下定論了。


上一篇
比較的意義,工具有真正的優劣嗎?
系列文
新時代的網頁框架比較-- 淺談Rails、Django、Phoenix、Laravel31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 則留言

0
Bater
iT邦新手 4 級 ‧ 2018-08-14 22:23:28

這篇明明沒講什麼,怎麼這麼多人看,真奇怪?

因為是最後一篇吧QQ

我要留言

立即登入留言