插播一條語錄: 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: 這句話也是在一群谷歌軟體工程師面前說的。