programming

Feb
20

Functional Programming: Lisp

My first flux

What Made Lisp Different. The 9 original and new ideas embodied by Lisp, a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax, are:

  1. Conditionals.
  2. A function type.
  3. Recursion.
  4. Dynamic typing.
  5. Garbage-collection.
  6. Programs composed of expressions.
  7. A symbol type.
  8. A notation for code using trees of symbols and constants.
  9. The whole language there all the time.
Source:Hackers & Painters

在看 Hackers & Painters 過程中,稍為了解 C -> C++ -> Java -> Perl -> Python -> Ruby 的演化,一種“趨向 Lisp 的進步方式“。根據 Paul Graham 書中的陳述,這些語言一個一個發展下去,從最早的“執行起來快“的 C/C++,慢慢往“語言本身能力比較厲害“的方向走,然後最厲害的,就是 1958 年由 John McCarthy 發明的 Lisp 了。(正確來說,是他的學生 Steve Russell 實現了第一個 Lisp interpreter,有趣的是,這位 Russell 同時是歷史上,寫出第一個 video game, Spacewar!, 的作者!)

根據 The Pragmatic Programming 的說法,一位積極進取的 programmer 應該做的事情之一,就是每一陣子去學習一個新的程式語言,另一種有別於你已經會的程式語言。透過從骨子裏學習新的語言,除了可以喚醒你「初學程式語言的新鮮感」,同時可以讓你學到以不同的觀點看待“寫程式“。為此,我打算隔一陣子,來去學學大一之後就沒有再接觸的 Lisp 家族。

Jan
27

TIFF file handling in PIL

# TIFF is a flexible, if somewhat aged, image file format originally
# defined by Aldus. Although TIFF supports a wide variety of pixel
# layouts and compression methods, the name doesn't really stand for
# "thousands of incompatible file formats," it just feels that way.

thousands of incompatible file formats, 這個的確有挖苦到 TIFF 這個格式 XD

Feb
8

Maya Scripting: MEL V.S. Python

day fourty: the endless fight by petite corneille @ flickr

Maya scripting 現在有了 MEL 與 Python 可供選擇,對於大部分的 Maya 使用者來說,這是件微不足道的事,但對於天天使用與撰寫 Maya scripting 的人來說(ex, TD?!)(或保守一點的說,很有機會被要求寫點程式的人),這重要極了。

個人淺見,Python 與之後由 Luma Pictures 的 Chad Dombrova 所推出的 pymel (0.7.8),是 Autodesk 買下 Maya 後,在 8.5 所做的 features 裏頭,最最重要的一點了。好吧,我是以 RD/TD/SD 人員的角度來看事的,請先暫時原諒我這有點狹隘的說詞,然後接著繼續看文章。

Maya 8.5 發表以前,在 Maya 上頭工作的技術人員,除了和大家一樣要去了解與使用 Maya 以外(說真的,Maya 的學習曲線有點長,進入門檻有點兒高,以致於很多資訊系所的電腦圖學實驗室,都不容易利用這個工具來做點什麼,實在很可惜),可能還需要去了解一下 Maya ascii file format, Maya nodes, Hierarchy in a Maya scene file, Mel, Maya C++ API, 技術名詞, …好不容易似懂非懂一些東西後,就是寫些程式來試試看。

舉些個例子。如果你想寫個可以自動幫你架好骨架的 joints 與一些 IK/FK 的設定的東西,你可以利用 Mel 來做到;如果你希望有一個特別的材質球,它會在你的模型有互相穿刺時,用紅色這種非常鮮豔且帶警告意味的顏色來提醒人,你可以用 C++ API 寫個 plugin 來提供一個特製化的 material node;如果你想用透過一個放在 Maya shelf 上頭的按鈕,讓 lighter 可以很快的下算圖指令的話,那你可以使用 Mel 外加 RMS/MtoR 提供的指令來做到;如果你想利用 locator 來實作 instance(一些 Maya instance 無法做到的情況下),同時要讓這個 locator 秀出原 reference model 的各種動態的話,你得用 Maya API 外加對於 Maya node 的了解(當然,你也可以使用 billboard(sprite) 做到);…

事情就是這麼複雜,以致於要訓練出一位可以依靠的 3D/CG TD,實在很花時間。如果很不幸地又沒辦法好好留住他,或是他個人不夠積極與拼命學習的話,可能浪費了兩三年,然後拍拍屁股走人,什麼都沒有留下來!!

這邊我們也許應該換個觀點,先來想想:「為什麼 Maya 把事情搞得這麼麻煩?」

Jan
20

Python Puzzle

Interesting subsequent comparison:

>>> a = 1
>>> b = 10
>>> c = 100
>>> a < b < c
True
>>> (a < b) < c
True

The following 2 code snippets are equal, which can explain why the above code works in that way.

if a < b < c:
    doSomething()

if (a < b) and (b < c):
    doSomething()

How about booleans? Is True bigger than False?

>>> True < c
True
>>> True > c
False
>>> False < True
True
>>> False > True
False

And I just noticed that True / False are 1 / 0 in one implementation of CPython 2.5?! According to official document, the True & False are special type called "bool" which should not be used to compare against other type.

>>> False == 0
True
>>> True == 1
True
>>> True == 2
False
>>> False == 2
False

How about is?

>>> None is None is None
True
>>> (None is None) is None
False
>>> None is (None is None)
False

Because is is also a comparison (not a binary operator)!!! It might be not that intuitive to figure out this situation especially when you are programming some logical expression with if.

Let's do play again True and False and I believe this time you can get it through.

>>> True is True is True
True
>>> False is False
True
>>> (False is False) is False
False

Check this if you wanna get more idea about Python's expression.

Oct
2

Cancellation Error

今天聽莊永裕教授的 Digital Image Synthesis 課時,聽到一個 Cancellation Error 的東西,是個與 IEEE floating point 有關的「數值計算問題」。

投影片上如是說:

Cancellation error: devastating loss of precision when small numbers are computed from large numbers by addition or subtraction.

寫了個簡單的 c 程式親身試驗一下。


void main(){
        double x1 = 10.000000000000004;
        double x2 = 10.000000000000000;
        double y1 = 10.00000000000004;
        double y2 = 10.00000000000000;

        double z = (y1-y2)/(x1-x2);
        printf("%f\n", z);
}
// output:
// # 11.500000

接著我在想,Python 會不會有這個問題呢? 結果試了一下…一樣!! 看來 CPython 的 number 這個 type 真的是用 double 實作的 :o

Jul
27

qing 的「程式碼共有下的團隊開發」

這是一篇文章聊到「怎麼讓程式碼與程式員之間的關係,從原來的一對一擴展成為多對多的樣貌,進而從中獲得好處」的文章,撰文者 qing 是一位非常認真汲汲於 programming methodology 與 java programming 的 guru,同時也是我非常敬愛的新竹中學軟體研究社學長。

文章中提到的 XP,也算是發表好幾年的方法論了,而且我猜,說不定太極影音的 MIS 系統開發組就採用了不少裏頭提到的方法。我在大五參加遊戲設計比賽時,也採用過 pair programming 來試驗成效,大抵來說,的確是減少了一些不必要的邏輯錯誤或 typo,同時 debug 的成效也比一個人埋頭苦幹在十多萬行的 c++ 程式碼裏頭來得快多,但我想 pair programming 最直接的助益,就在於有另一個人和你一樣,對一個系統或一大段程式碼的夠了解,足夠到可以和你討論一些細節或延伸的想法與設計,這大大地讓 programmer 擺脫了「I am programming alone without anyone figuring out what I was/am/will be doing...」,非常有趣的經驗。

最後一段的「讓每個成員寫出一致風格的程式碼」,讓我忍不住想到印度的斯巴達式資訊教育~

Nov
30

Drupal: 許每篇文章一張圖

Daily Pickup | DRAKE因為某些原因,遇見了 Cool Hunting 的某個頁面,它讓每一篇文章都成了一小張圖,然後整整齊齊地擺出來,整個就是好看。於是乎,逛 Cool Hunting 時,不再是依照每一篇文章的標題或是文章摘要(teaser)來決定要不要點進去看,而是這篇文章的小圖有沒有引起你的注意。

圖像化文章列表(photolized list of articles) -- 給它一個命名。

隨後想說,既然 Drupal 這麼強大,應該有辦法弄一個類似的功能出來的吧。著手研究了一下當時(寫出這個功能時,應該是 2007 年的夏天)的模組,並沒有找到類似功能的,有點接近的,可能就屬 Teaser Images@drupaltaiwan)了吧。但是 Teaser Images 只能處理放在本機上的圖片,並無法處理外連的圖片,而且如果圖片是出現在全文裏頭,而不是文章摘要的話,就沒用了…

更新:嘗試寫了一個模組,所以作法變得簡單一些些了:我的第一個 Drupal 模組:Thumbview Field。不過如果你想知道我一開始是怎麼想的,那請繼續閱讀下去,不然,就直接跳到吧。

Syndicate content