善意的謊言 ?
原來大家用 function call 是因為被騙 ? o_O
今天在看 The Art of Unix Programming 的時候,看到 某一段寫得很有趣:
Dennis Ritchie encouraged modularity by telling all and sundry that function calls were really, really cheap in C. Everybody started writing small functions and modularizing. Years later we found out that function calls were still expensive on the PDP-11, and VAX code was often spending 50% of its time in the CALLS instruction. Dennis had lied to us! But it was too late; we were all hooked…
– Steve Johnson
前後文的大意是說以前人在寫程式的時候,因為 function call 的代價太高,所以大家都不喜歡把 function unit 切開來,每個 function 都寫得落落長;開發 Unix 的人都知道 modulize (模組化) 是正確的選擇,尤其是對像是 OS 這麼複雜的程式而言。所以呢,在設計 C 語言出來以後,Dennis Ritchie 就跟大家說這個 function call 在 C 裡面是不花什麼代價的,大家請儘量;大概因為 Ritchie 是大師的關係,每個人都不疑有他,大家都用得很高興。不過在過了許多年之後,有人去做了一些研究,發現 Dennis 在唬爛 !! PDP-11 上面的 function call 還是很耗資源,VAX 有一半的時間都花在 CALL 這個指令上 !! 不過也來不及走回頭路,大家都已經習慣用 function call 了… XD
Technorati Tags: c, unix, programming
Comments
Comment from Blake
Date: 2005/8/19, 11:16 下午
歷史總是一堆意外 :p

Write a comment