Python是工程,不是藝術,Python工程,藝術

來源:互聯網
上載者:User

Python是工程,不是藝術,Python工程,藝術

When Python first emerged on the software scene in the early 1990s, it spawned what is now something of a classic conflict between its proponents and those of another popular scripting language, Perl. Personally, I think the debate is tired and unwarranted today—developers are smart enough to draw their own conclusions.                                             Still, this is one of the most common topics I’m asked about on the training road, so it seems fitting to say a few words on the topic here.

當Python九十年代初出現時,曾激起Python的支援者與另一門時髦語言Perl擁護者的之間的經典衝突.如今這場爭論已成為過去.

個人認為: 這場爭論很令人厭煩的,也是毫無根據的。開發人員都很聰明,知道如何選擇。現在為止,這仍然是一場最著名的爭論.

在我培訓的過程中,經常會被問及,因此有必要就這個話題說幾句。

The short story is this: you can do everything in Python that you can in Perl, but you can read your code after you do it. That’s it—their domains largely overlap, but Python is more focused on producing readable code.                                                         For many, the enhanced readability of Python translates to code reuseability and maintainability, making Python a better choice for programs that will not be written once and thrown away. Perl code is easy to write, but difficult to read. Given that most software has a lifespan much longer than its initial creation, many see Python as a more effective tool.

簡而言之:Perl能做到的,Python都能做到,但你必須在寫之後要能讀懂它。顯然,這是他們之間主要的交集。

顯而易見:Python更關注於代碼的可讀性,在大多數情況下,提高代碼的可讀性轉化為:代碼的重用性及可維護性.

這樣一來,使得Python成為了一個很好的選擇: 不會寫了後就丟棄。 Perl代碼很容易寫,但很難讀。

鑒於軟體都有很長的生命週期,遠比初始開發要長,因此很多人視Python為更有效工具。

The somewhat longer story reflects the backgrounds of the designers of the two languages,and underscores some of the main reasons people choose to use Python.Python’s creator is a mathematician by training; as such, he produced a language witha high degree of uniformity—its syntax and toolset are remarkably coherent. Moreover,like math, its design is orthogonal—most of the language follows from a small setof core concepts. For instance, once one grasps Python’s flavor of polymorphism, therest is largely just details.
這很大程度反映了兩門語言設計者的背景,並體現了很多人選擇使用Python的原因。

Python的締造者是個訓練有素的數學家,這就使得其發明的語言具有高度的統一性:

她的文法和工具集都帶有顯著的連貫性。更有甚至,像數學一樣其設計具有正交性:

即語言的大部分都遵循一小組的核心概念。例如,一旦你掌握了多態,其他大部分都是細節,僅此而已。

By contrast, the creator of the Perl language is a linguist, and its design reflects this heritage.There are many ways to accomplish the same tasks in Perl, and languageconstructs interact in context-sensitive and sometimes quite subtle ways—much likenatural language. As the well-known Perl motto states, “There’s more than one way todo it.” Given this design, both the Perl language and its user community have historicallyencouraged freedom of expression when writing code. One person’s Perl code canbe radically different from another’s. In fact, writing unique, tricky code is often asource of pride among Perl users.
相比而言, Perl的創立者是個語言學家,因此其設計反映了這種語言的特性。

在Perl中,做同樣的任務,可以有很多種方法,語言的結構受語境互動影響。

有時是非常敏感的,非常像自然語言。恰如一句著名的Perl座右銘所說:

條條道路通羅馬! 鑒於這種設計,不僅Perl語言本身以及Perl使用者社區,

都鼓勵並提倡在寫代碼時,追求自由的精神。因此一個人寫出來的代碼很可能與他人截然不同! 

事實上,Perl開發人員常以編寫獨特的,很有技巧的代碼為榮!

But as anyone who has done any substantial code maintenance should be able to attest,freedom of expression is great for art, but lousy for engineering. In engineering, weneed a minimal feature set and predictability. In engineering, freedom of expressioncan lead to maintenance nightmares. As more than one Perl user has confided to me,the result of too much freedom is often code that is much easier to rewrite from scratchthan to modify.
但是那些曾經維護過大量代碼的人可以證明:自由表達的精神對藝術而言非常棒。

但對工程而言,就非常令人討厭了。從工程的角度,我們需要最小化功能集及可預測性。

在工程領域,自由表達會導致維護的噩夢。不止一個Perl使用者向我吐露:

太過於自由的結果就是:程式很容易重頭寫起,但修改起來就很難了!

Consider this: when people create a painting or a sculpture, they do so for themselvesfor purely aesthetic purposes. The possibility of someone else having to change thatpainting or sculpture later does not enter into it. This is a critical difference betweenart and engineering. When people write software, they are not writing it for themselves.In fact, they are not even writing primarily for the computer. Rather, goodprogrammers know that code is written for the next human being who has to read it inorder to maintain or reuse it. If that person cannot understand the code, it’s all but uselessin a realistic development scenario.
鑒於此:當人們對雕像塗抹漆畫,出於純粹美學的角度,他們可以隨意塗抹.

至於今後某人不得不改變他的漆畫或者創意,都不在其考慮的範疇。這就是藝術和工程最關鍵的區別。

當人們寫代碼時,他們並不能純粹為自己而寫.事實上,他們甚至不是專門為電腦而寫的。當然啦,優秀的程式員知道:

代碼是為今後維護甚至重寫的人而寫。如果負責維護的人完全不能理解代碼,那麼在現實中,這些代碼幾乎毫無用處。

This is where many people find that Python most clearly differentiates itself from scriptinglanguages like Perl. Because Python’s syntax model almost forces users to writereadable code, Python programs lend themselves more directly to the full softwaredevelopment cycle. And because Python emphasizes ideas such as limited interactions,uniformity, regularity, and consistency, it more directly fosters code that can be usedlong after it is first written.
這就是很多人發現Python區別於另一門指令碼語言Perl最顯著的地方。

因為Python的文法模式強迫了使用者去寫可讀的代碼,Python語言會引導他們朝完整的軟體開發流程前進。因為Python更強調:

有限互動性、一致性、規則性以及統一連貫性,會更進一步導致:Python自首次編寫後,可以運行很長一段時間。

In the long run, Python’s focus on code quality in itself boosts programmer productivity,as well as programmer satisfaction. Python programmers can be creative, too, andas we’ll see, the language does offer multiple solutions for some tasks. At its core,though, Python encourages good engineering in ways that other scripting languagesoften do not.
長期以來,Python專註於代碼的品質也提升了程式員的生產力,和開發人員的滿意度。

Python的程式員會變得更富有創造性,並且我們以後會明白,對某些項目而言:

這門語言的確提供了多種解決方案。就核心而言,Python提倡工程的開發方式是其他指令碼語言所不具備的。

At least, that’s the common consensus among many people who have adopted Python.You should always judge such claims for yourself, of course, by learning what Pythonhas to offer. 
這是很多採用Python者之間的共識。當然你自己也能判斷:Python到底為你提供了什麼。


NOTE:英文文章摘自《Learning Python》Python is engineer,not art部分.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.