標籤:

(未完成)2018.04.NO.6(Note)

Why is static typing in programming languages so important for people that they dislike more expressive languages like Python that dont have it?

為什麼在編程語言中靜態類型對人們來說如此重要,以至於他們不喜歡像Python這樣沒有的表達性語言?

Under the discussion , of which the topic is "Why is static typing in programming languages so important for people that they dislike more expressive languages like Python that dont have it?", there is an answer written by Robert Brown . For practicing,i read it and translate the view of Yann LeCun into Chinese . Because of the mindset of the practicing , i will not strictly translate the answer word by word , but just write down my explanation .

這是Quora上關於「為什麼在編程語言中靜態類型對人們來說如此重要,以至於他們不喜歡像Python這樣沒有的表達性語言?」上Robert Brown,回答的翻譯,他是Facebook公司的智能開發人員。

And it is my duty to provide the link of the discussion (in Quora)(問題鏈接如下):

Why is static typing in programming languages so important for people that they dislike more expressive languages like Python that dont have it??

www.quora.com

當我調用一個我能一眼看出輸入參數的函數時,事情的確是如此。如果遇到了動態參量,那麼我就必須去尋找和閱讀說明文件,即使我足夠幸運,這一段代碼我能夠單憑自己看一眼,就能弄清楚他的結構和用法,這樣做仍然會花掉很多不必要的時間。

Really it comes down to this. When I call a function I can tell immediately what the parameters are supposed to look like and do. With a dynamic type I have to go try to find documentation or if I』m lucky and have the code I can go try to read through it and figure out what is expected and how it』s used. Even though knowing what a function does can be helpful, it can also waste a lot of time.

另一件事是,靜態變數出現的錯誤往往會出現在對彙編語言進行編譯的時候。

The other thing that static typing does is that your errors appear at compile time for compiled languages.

這意味著,如果我對一個函數不夠了解並且草草地快速瀏覽了這一代碼,

That means that if I didn』t understand the function I called perfectly and wind up(緊) passing an object/structure that doesn』t implement the foo function which is used in one path through the function, runtime errors can occur(出現) after it hits production.

靜態變數所在的代碼便很少有機會在編譯的時候出錯。

With static typing that kind of error is less likely to appear once it』s compiled.

從我的自身經歷說,當我偶爾發現一個未知變數起著重要的作用,如果這個變數十有八九是動態變數。

Personally, while I do find anonymous types useful occasionally, I find it』s far to easy

to miss something when using dynamic types.

測試那些執行文件,其實相當於直接把buck傳遞給了dev,而事實上,你的確是在修改靜態變數。所以,「小心編寫執行文件你就不會在運行的時候出現error」這一說法基本上就是在說靜態變數是十分重要的,無論靜態變數是不是你自己編寫的。

Note that writing tests( that basically enforce static types) is basically simply passing the buck to the dev and you really are using static types. So saying 「If you write your test correctly you won』t get the runtime errors」 is basically saying that static types are necessary even if you have to implement them yourself.

There are other speed issues where a compiler can do things more efficiently if it doesn』t have to worry about being able to convert things and determine type while running. For example a + b in javascript requires the compiler to test to determine whether a and b are strings or integers or decimal by back tracing every usage, and if the originating value comes from a user input then it can』t make ANY assumptions on the data type and has to test during runtime every time the code is called to determine what to do. That』s far less efficient than if a and b are declared as int and the compiler knows that it can simply produce an integer addition.

There are a bunch of IDE optimizations that can occur too especially when you are talking about objects or structures.


推薦閱讀:

~廣告設計練習~2017.10.01~10.12份

TAG:練習 |