Tuesday, August 9, 2011

declarative programming

隨便抓一位打扮時髦的路人來問:「使用過宣告式編程法?」~潮人~很可能不是一位專業的程式設計師,也有很大的可能性得到的是一個白眼,或者疑惑困擾的表情。

換個問題:「曾經使用過試算表,如 excel..」~很可能得到正面的答覆,如果運氣不錯,人家還很樂於分享建立複雜試算表的經驗談。

1979,兩位 MIT 的學生在古早的 Apple II 上面,開發出現在所有試算表的祖先 ~ Visicalc。在每一個小格子設定數值、定義公式、、

在此之前,很多計算工作必須僱用專業程設師來撰寫程式,使用者還必須不厭其煩地解釋運算如何進行。 Visical 出現後,一般的非程設專業人員都可以自由輕鬆地進行大量複雜的運算。 Visical 也是第一個造成個人電腦熱賣的 Killer App

試算表~就是宣告式編程 Declarative Programming

相對 imperative programming 每個步驟清楚地描述控制流程的 how ,declarative programming 更偏重在 expressive 的 what。

傳統教科書中,最喜歡舉的例子是 SQL。

目前正夯的 jQuery 也是 declarative programming 的一個例子。把 css 描述 DOM 元件的字串丟進 $() 緊接著給定想要完成的工作。 以簡潔的敘述替代掉繁瑣的 DOM API。

難怪 jQuery 可以標榜 write less do more

see also: Why the Relational Database Management System? An alternative style of programming is "declarative". We tell the computer what we want, ~~~ specify the desired characteristics of the report and it is the job of the RDBMS to prepare it.

「宣告式」與「指令式」

No comments:

Post a Comment