Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state.

— Wikipedia on Functional programming

2010.04.07 Wednesday ACHK

程式時間

多次元宇宙 9

程式員頭腦 7

時間定義 2

你要有寫程式的訓練,因為寫程式的訓練會令你多了很多「思考工具」。例如,我也估不到我在程式書中,閱讀到「時間」的定義。書中所描述的,只是在一個程式內「時間」的定義。但是,把「程式時間」引申開去,令我瞭解了「物理時間」的意思。

有一類 programming languages(程式語言),叫做「functional programming languages(函數程式語言)」。用 functional programming languages 所寫的程式,程式內是沒有「時間」的。

怎樣為之「程式內是沒有『時間』」呢?我們可以先倒轉來想:怎樣為之「程式內是有『時間』」呢?

如果一個程式是有 state(狀態)的,那就為之有「時間」。「有 state」的意思是,同一個 variable(變數),它的數值可以有變化。

例如,一個銀行會計程式有一個變數 x。 x 用來代表我的戶口結餘。所以,x 的數值會有變化。因為那個銀行會計程式儲存了 x,而 x 可以有變化,所以我們說,那個銀行會計程式有「時間」。

不同的 x 數值,就對應於那個程式的不同 state。例如:

程式 state 1, x = HK$ 100

程式 state 2, x = HK$ 200

程式 state 3, x = HK$ 170

程式 state 4, x = HK$ 251

程式 state 5, x = HK$ 350

— Me@2010.04.06

2010.04.06 Tuesday (c) All rights reserved by ACHK

Ninety-ninety rule

The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.

90% of the project accounts for the first 90% of the budget. The remaining 10% of the project accounts for the other 90% of the budget.

— Wikipedia on Ninety-ninety rule

2010.04.06 Tuesday ACHK

Designed for smart programmers

As for Arc, I think you actually get a
better language if you design for smart
programmers. Designed for smart
programmers: C, Smalltalk, Lisp. Designed
for “average” programmers: Cobol, Pascal,
Java. See a pattern here?

Paul Graham
Tuesday, December 18, 2001

2010.04.05 Monday ACHK

Philosophy

.

What philosophy books would you recommend?

I can’t think of any I’d recommend. What I learned from trying to study philosophy is that the place to look is in other fields. If you understand math or history or aeronautical engineering very well, the most abstract of the things you know are what philosophy is supposed to be teaching. Books on philosophy per se are either highly technical stuff that doesn’t matter much, or vague concatenations of abstractions their own authors didn’t fully understand (e.g. Hegel).

— Paul Graham

.

.

.

2010.04.05 Monday ACHK

Pure Maths

Past papers 15

“Past papers” means “past HKCEE/HKAL examination papers”. The topic is for Hong Kong students who are facing HKCEE or HKAL. But the general principles can also be used for tackling other public examinations.

這段改篇自 2010 年 2 月 7 日的對話。

懂不懂讀書方法呀?

(LWT:我都不知道如何讀 …)

如果不是自己先天可以掌握到的科目,你就需要有「讀書方法」。我以前有沒有教過你讀書方法?我應該有教過你。

不如你先試試問我問題。

(LWT:我覺得呢 … Pure Maths(純數學)中,好像每一道題目都有新的做法 …)

無錯 … Pure Maths 就是這樣的 …

(LWT:好像每一道題目都有新的做法。做新的題目時,我不能用我已知的方法技巧,試試可不可以做到。)

其實可以這樣看:Pures Maths 一方面不是好似 Applied Maths(應用數學科)一樣,你大量練習,大量背誦,就會合格;另一方面,它又不是如你所說的那麼極端:「題題都要用新的方法」。

實情是,Pure Maths 的每一課本身可能有十幾個主要的做法技巧。而每次是考你該十幾個技巧的不同組合。你試想想,如果一課有 10 個新的方法,而每題題目也抽其中 5 個來考驗你的話,那就有 252 個組合。因為可能的組合太多,你不察覺該一課所考的,來來去去也是那 10 個方法,導致你以為每題所用的都是新的技巧。

所以,倒轉想一想,你反而要想辦法歸納出每一課背後的那 10 幾個方法技巧。如果你歸納到的話,你在該課就不會有大困難。

(LWT:哪如何歸納呢?是不是讀完一課後,自己就嘗試歸納?)

毋須這樣。你逐題做就可以。你做完每一題就可以立刻歸納。即是這樣,例如,這一題你用了 定理一、定理三、公式五、技巧一 和 技巧四。那你就把它們記錄在你的筆記簿中。第二題又這樣記錄,第三題又這樣記錄,如此類推。每一題做完以後也歸納一些重點。

(LWT:即是記錄自己用過哪幾個技巧?)

無錯。一路記錄下去,到了(例如)第五題時,你會發現有些你要記錄的重點技巧開始重複。到了(例如)第十二題時,你會發現再沒有新的技巧需要記錄。即是話,你已完成了該課的歸納工作。

如果你成功應用這個讀書方法的話,你的 Pure Maths 科就可以起碼達到 C 級的成績。當然,如果你要去到 A 級的層次的話,到你考試做題目時,千萬不可以要很有意識地、慢慢地盤算究竟是用哪幾個技巧。

如果你要去到 A 級的層次的話,你要平時已經歸納好,而且非常純熟到到你考試做題目時,所需要的技巧可以自動彈出來。

— Me@2010.04.04

2010.04.04 Sunday (c) All rights reserved by ACHK

The primordial forces

* Programming in Lisp is like playing with the primordial forces of the universe. It feels like lightning between your fingertips. No other language even feels close.

o Glenn Ehrlich

2010.04.04 Sunday ACHK

Nerd 3

.

As a thirteen-year-old kid, I didn’t have much more experience of the world than what I saw immediately around me. The warped little world we lived in was, I thought, the world. The world seemed cruel and boring, and I’m not sure which was worse.

Because I didn’t fit into this world, I thought that something must be wrong with me. I didn’t realize that the reason we nerds didn’t fit in was that in some ways we were a step ahead. We were already thinking about the kind of things that matter in the real world, instead of spending all our time playing an exacting but mostly pointless game like the others.

— Paul Graham

.

.

.

2010.04.04 Sunday ACHK

Category of small categories

In mathematics, specifically in category theory, the category of small categories, denoted by Cat, is the category whose objects are all small categories and whose morphisms are functors between categories. Cat may actually be regarded as a 2-category with natural transformations serving as 2-morphisms.

The category Cat is itself a large category, and therefore not an object of itself. In order to avoid problems analogous to Russell’s paradox one cannot form the “category of all categories”. But it is possible to form a quasicategory of all categories.

— Wikipedia on Category of small categories

2010.04.03 Saturday ACHK

Product

.

I think the solution is to assume that anything you’ve made is far short of what it could be. Force yourself, as a sort of intellectual exercise, to keep thinking of improvements. Ok, sure, what you have is perfect. But if you had to change something, what would it be?

If your product seems finished, there are two possible explanations: (a) it is finished, or (b) you lack imagination. Experience suggests (b) is a thousand times more likely.

— Paul Graham

.

.

.

2010.04.03 Saturday ACHK

Code refactoring

Code refactoring is the process of changing a computer program’s source code without modifying its external functional behavior in order to improve some of the nonfunctional attributes of the software. Advantages include improved code readability and reduced complexity to improve the maintainability of the source code, as well as a more expressive internal architecture or object model to improve extensibility.

— Wikipedia on Code refactoring

2010.04.02 Friday ACHK

筆墨

.

刀槍能夠殺人,筆墨可以救人,人類的社會因為有了傳媒人類才真正溝通成為一個體系。試想過去人類的歷史社會在未有傳媒的時期,人類的社會是多麼的黑暗,人類的認知是如何單薄。各位傳媒朋友,請繼續你們有建設性的工作,只要你秉承良知,人類的社會就會因傳媒而進步。我懷念你,我會在另一個世界向你揮手。

— 梁幗馨

.

.

.

2010.04.02 Friday ACHK

多次元宇宙 8

色即是空,空即是色」的意思是,雖然「現象」和「本體」是不同的東西,但是,要觀察「本體」,我們只能透過「現象」。正如,雖然「杯的影像」和「杯本身」是不同的東西,但是,要觀察「杯本身」,我們只能透過「杯的影像」。

「色即是空,空即是色」中的「即是」,是指當我們說

我的眼睛接收到,一隻『杯』的『影像』。」時,意思即是

我看到一隻『杯』。」;

而當我們說

我看到一隻『杯』。」時,意思又即是

我的眼睛接收到,一隻『杯』的『影像』。

.

(安:既然是這樣,為什麼我們花,這麼多的時間,去理解「現象」和「本體」的分別呢?)

我們沒有辦法,看到「物自身」。這是一個定義問題——給你「看到」的,就是「現象」,不是「物自身」。

正如我們沒有辦法,直接看到「杯本身」。給你「看到」的,就是「杯的影像」,不是「杯本身」。

既然是這樣,為什麼要去明白,「物自身/本體」的意思呢?為什麼要去明白,「現象」和「本體」的分別呢?

.

知道「物自身」這個概念,可以令我意識到,我所觀察到的「現象」,並不是「物自身」,所引發的唯一「現象」。

正如,知道「杯本身」這個概念,可以令我意識到,我所看到的「杯的投影」,並不是「杯本身」,所引發的唯一「投影」。這是一個圓柱體的杯。我從側面望,會見到一個長方形。但是你從上面望,則會見到一個圓形。

.

「物自身」這個概念,有什麼用處呢?

知道「物自身」這個概念,可以令我意識到,我所觀察到的「現象」,並不是「物自身」,所引發的唯一「現象」。

例如,我們(人類)觀察到的「現象」是,「這杯雪糕是白色的」。這個「現象」的產生,是因為有雪榚的「物自身」,和我們的視覺器官所配合。但是,其他生物可能因為,有不同構造的視覺器官,例如可以接收紅外線,而見到不同於,「這杯雪糕是白色」的「現象」。

又例如,我們見到的「現象」是,「這個世界是彩色的」。但是,同一個世界,因為狗是色盲的,牠們見到的「現象」是,「這個世界是黑白的」。

(那是簡化的講法,因為狗只是「紅綠色盲」,不是「全色盲」。– Me@2023-11-13 12:56:32 PM)

透過「物自身」這個概念,令我們知道還有,我們感受以外的,其他「現象」存在。

(安:這就是「色即是空,空即是色」,最有意思的地方。)

— Me@2010.04.01

.

.

2010.04.01 Thursday (c) All rights reserved by ACHK

Peter Norvig

On practical applications of academic concepts, he mentions that part of the problem is that academics do not see the whole problem and another part is education. If you have a bunch of programmers who don’t understand what a monad is and haven’t taken courses in category theory, there’s a gap.

— Wikipedia on Coders at work

2010.04.01 Thursday ACHK