2007-05-08

Linus said st in Linux kernel coding style

開宗明義說

10 First off, I'd suggest printing out a copy of the GNU coding standards,
11 and NOT read it. Burn them, it's a great symbolic gesture.

怎麼會這樣啦~

這變成 Humorous Quotes Seen on UseNet 的收藏。

這個東西酷斃了,排版好漂亮!


整篇 Linux Kernel coding style 都是很搞笑,而且文筆寫的很直接,帥氣!! XDDDDD


131 Heretic people all over the world have claimed that this inconsistency
132 is ... well ... inconsistent, but all right-thinking people know that
133 (a) K&R are _right_ and (b) K&R are right. Besides, functions are
134 special anyway (you can't nest them in C).



182 When declaring pointer data or a function that returns a pointer type, the
183 preferred use of '*' is adjacent to the data name or function name and not
184 adjacent to the type name. Examples:
185
186 char *linux_banner;
187 unsigned long long memparse(char *ptr, char **retptr);
188 char *match_strdup(substring_t *s);

很好,因為我這次的 Ch5-1 就是寫在 type name。 :P 因為我覺得滿美觀的呀,尤其是要同時宣告很多這種變數的時候,就一個 * 套用到宣告出來的多個變數。


What is unary
Meaning one; a single entity or operation, or an expression that requires only one operand.



209 C is a Spartan language

我以為看到 三百兄貴


209 C is a Spartan language, and so should your naming be. Unlike Modula-2
210 and Pascal programmers, C programmers do not use cute names like
211 ThisVariableIsATemporaryCounter.


XDDDDDDDD



224 Encoding the type of a function into the name (so-called Hungarian
225 notation) is brain damaged - the compiler knows the types anyway and can
226 check those, and it only confuses the programmer. No wonder MicroSoft
227 makes buggy programs.

brain damaged 翻譯成「頭殼壞掉」是最適合不過了!!整段寫的超搞笑,笑死我了啦~~~~~
我之前學過 Hungarian notation in VB,覺得 btn 代表 Button 這個元件很合適,也很容易閱讀,可是他為甚麼說只要 compiler 知道類型就好了,不考慮人的問題呢?強記?還是看宣告就行了!?



235 If you are afraid to mix up your local variable names, you have another
236 problem, which is called the function-growth-hormone-imbalance syndrome.
237 See chapter 6 (Functions).

看到 function-growth-hormone-imbalance syndrome 還以為什麼專業的單字,害我猛起勁來查 stardict,結果得到 「生長功能荷爾蒙失調併發症」!!幹~~~~ 寫這篇的人到底在寫什麼啦?這篇根本是笑話集!



244 It's a _mistake_ to use typedef for structures and pointers.

我承認 Ch5-1 裡面有用到

typedef struct {...} student;
student* stu;

這種他說的錯誤。而且還犯了兩種錯誤。



397 Comments are good, but there is also a danger of over-commenting. NEVER
398 try to explain HOW your code works in a comment: it's much better to
399 write the code so that the _working_ is obvious, and it's a waste of
400 time to explain badly written code.

所以寫 comment 是為了解釋「工作內容」,而非「如何工作」。



402 Generally, you want your comments to tell WHAT your code does, not HOW.
403 Also, try to avoid putting comments inside a function body: if the
404 function is so complex that you need to separately comment parts of it,
405 you should probably go back to chapter 6 for a while. You can make
406 small comments to note or warn about something particularly clever (or
407 ugly), but try to avoid excess. Instead, put the comments at the head
408 of the function, telling people what it does, and possibly WHY it does
409 it.

盡量避免一個 function or class 做太多功能,這樣才能節省 comment 的長度,和讀者了解的「墾掘深度」。



420 /*
421 * This is the preferred style for multi-line
422 * comments in the Linux kernel source code.
423 * Please use it consistently.
424 *
425 * Description: A column of asterisks on the left side,
426 * with beginning and ending almost-blank lines.
427 */
428
429 It's also important to comment data, whether they are basic types or derived
430 types. To this end, use just one data declaration per line (no commas for
431 multiple data declarations). This leaves you room for a small comment on each
432 item, explaining its use.

一個資料描述一行,逗號後面換行。




437 That's OK, we all do. You've probably been told by your long-time Unix
438 user helper that "GNU emacs" automatically formats the C sources for
439 you, and you've noticed that yes, it does do that, but the defaults it
440 uses are less than desirable (in fact, they are worse than random
441 typing - an infinite number of monkeys typing into GNU emacs would never
442 make a good program).

這未免也太人身攻擊了吧,p 老師就是 emacs 愛用者,該不會 emacs 的使用者都跑去 non-Linux dist 吧!? :P 難怪 Linux kernel loading balancing 沒有比某個 BSD 來的好!



473 recognize the authority of K&R (the GNU people aren't evil, they are
474 just severely misguided in this matter),

哈!我看到這裡,實在是... 想要知道當初是什麼條件讓 Linus Torvalds 願意將 Linux Kernel 以 GPL 釋出!?出櫃? XDDDD

@_@!? 出櫃不是 screw-up... : 出櫃(英文“come out of the closet”的直譯,指暴露同志身份)



RTL : http://www.answers.com/topic/rtl
Register Transfer Level


GNU Manuals Online
JTC1/SC22/WG14 - C
WG14 is the international standardization working group for the programming language C

2 則留言:

Arrakeen 提到...

最近在 hacking linux kernel?
果然 survey 的方向整個不一樣...

Alan Lu (盧利雄) 提到...

上班時段寫程式,亂翻文件花個一個小時看這篇,笑一笑也滿爽的。 :D :D