插播一條語錄: Bad programmers worry about the code. Good programmers worry about data structures and their relationships. - by Linus Torvarlds. (通常的程序員只關心代碼,而優秀的軟件工程師更關心數據結構以及他們之間的關係。)
啓示
Linus本人寫C語言比較多,我的認爲這裏的data structures and their relationships 若是脫離C語言 的特定背景,能夠泛指技術對場景或業務邏輯的抽象, 好比: 面向對象建模,領域驅動, 甚至更宏觀的架構設計或微服務怎樣劃分。
voidremove_list_entry(entry){
prev = NULL;
walk = head;
// Walk the listwhile (walk != entry){
prev = walk;
walk = walk->next;
}
//Remove the entry by updating the//head or the previous entryif(!prev)
head = entry->next;
else
prev->next = entry->next;
}
複製代碼
好的代碼, 換一種寫法,使正常處理邏輯能夠兼容邊界值:
voidremove_list_entry(entry){
//The "indirect" pointer points to the// *address* of the thing we'll update
indirect = &head;
//Walk the list,looking for the thing that//points to the entry we want to removewhile ((*indirect) != entry)
indirect = &(*indirect)->next;
// .. and just remove it
*indirect = entry->next
}
複製代碼
"In fact, I am a very cynical and untrusting person. I think most of you are completely incompetent". In front of a large group of Google developers. 翻譯:在一羣谷歌軟件工程師面前說: 各位不要誤會, 我不是針對你, 我是說在座的各位寫代碼的水平徹底都是垃圾。
"Because nobody actually creates perfect code at first time around except me, but there's only one of me. " 翻譯:實際上沒人能一次就寫出完美的代碼,除了我。可是世界上只有一個我。ps: 這句話也是在一羣谷歌軟件工程師面前說的。