2011年3月23日 星期三

Smell good? [釋疑篇]

Compose Method [Beck, SBPP]

You can't rapidly understand a method's logic.

Transform the logic into a small number of intention-revealing steps at the same level of detail

以下 by [Kerievsky, Refactoring to Patterns]

Motivation:
這個 pattern 看起來很簡單, 好像每個 programmer 都應該這樣寫 code, 但是如果你仔細檢視一下自己寫的 code, 你會發現, 應該大部份的 code 都沒有做到這個 pattern 的要求. Compose Method 簡單來說, 就是 method 裡面 compose 其他的東西, 都必須要在同個 detail 等級之下(Mechanics 第五點).

2011年3月20日 星期日

Smell good?

最近為了國人的生活品質與身體健康, 義無返顧的投入了清潔大隊, 在經歷了尖山火池, 天崩地裂, 毒氣瀰漫, 輻射籠罩的考驗中, 能活著回來真的是菩薩保佑, 祖上積福~ 在身體還未被恐怖的碘, 鈽的放射性同位素給侵蝕殆盡前, 趕快將所見所聞來跟大家分享~

在此先端出德高望重的貝克大師[Beck Kent]的武林秘笈心法:

扛布絲埋圾袋 [Compose Method]

2011年1月18日 星期二

Why Pi?

很高興的發現今年Knuth教授的聖誕節課程居然有網路轉播:
http://stanford-online.stanford.edu/seminars/knuth/101206-knuth-500.asx

與大家分享這篇絕不是炫耀文,因為我完全跟不上上課的內容... 但是,
Knuth的課程講的是數學,去聽的卻大多是computer science的學生,是那種畢業後進Google或Apple的工程師,了解一下這些傢伙都在想什麼還滿有意思的。

今年講的內容,90%用到的數學,居然都是我們在台灣的高中生就學過的:
  • 排列組合:Cnr=n!/r!(n-r)!
  • 機率: 擲兩顆骰子出現12點的機率!?
  • 簡單的幾何: 圓的面積=πR2
  • 二項式係數: (x+y)n展開後的係數
Knuth每年都會在耶誕節前夕講一堂跟樹狀結構(tree)有關的課程,今年講的是:如果給你n個節點,你可以排出幾種不同的tree?假設這個數字為C(n),舉幾個例子:
  • C(1)=1
  • C(2)=2
  • C(3)=5
其中C(3)=5如右圖所示

三百年前就有人解出C(n)是一個與π有關的方程式,但一直到2007年才有人提出合理的解釋,說明為什麼樹狀結構的排列組合數量,會和圓形的π有關。

網路真是神奇的東西,我居然可以聽到史丹佛大學最頂尖的教授的課!

PS: 某人上課的筆記 http://apetresc.wordpress.com/2010/12/28/knuths-why-pi-talk-at-stanford-part-1/

2011年1月9日 星期日

跟著我動動你的右腦(其實也會動到左腦,甚至會死很多腦細胞 XD)


最近左腦用過度,來寫一篇文章來平衡一下。順便灌一下水。
之前在看到iOS跟Android 都有Gesture相關的API就一直很想來分析一下這兩個設計。

2010年8月31日 星期二

Tuning Applications

1. The Instruments Application
The Instruments application lets you gather a variety of application performance metrics, such as memory and network use.

2. The Shark Application
The Shark application lets you view system-level events, such as system calls, thread-scheduling decisions, interrupts, and virtual memory faults.


Note:
When performance problems in your code are more related to the interaction between your code, iOS, and the hardware architecture of the device, you can use Shark to get information about those interactions and find performance bottlenecks.

2010年5月27日 星期四

nil vs Nil vs Null vs NSNull null

nil: A null pointer to an Objective-C object.
(#define nil ((id)0))

Nil: A null pointer to an Objective-C class. 

Null: A null pointer to anything else.
(#define NULL ((void*)0))

NSNull: A class defines a singleton object used to represent null values in collection objects (which don’t allow nil values).

[NSNull null]: The singleton instance of NSNull.

2010年4月12日 星期一

Something about Category and Extention

Category 和 Extention 有著非常相似的使用方式, 然而卻還是有些不同的使用情境. 基本上, Extention 是個
"anonymous" Category.
讓我們來復習一下 Category 的寫法:

@interface MyClassName ( MyCategoryName)
// extra methods' definitions
- (void)superShrimp;
@end

然後再看看 Extention
@interface MyClassName ()
// extra methods' definitions
- (void)superShrimp;
@end