2008-08-26 48 views

回答

6

這取決於你的興趣,但我曾與Quake III codebase,這是寫得很好,很好的合作。它寫在C.

17

我會推薦Scott Hanselman的weekly source code articles,他確實提出了你的建議,即閱讀更多的源代碼以獲得更好的效果。這是值得的閱讀。

3

你會發現很多例子。但吉姆巴克說,這取決於你的興趣。我從SharpDevelop的來源獲悉了一系列的「東西」。

2

如果有人擁有Code Reading by Diomidis Spinellis的副本,他在那裏寫了哪些開源項目?


@Avinash:如果您想了解一般更多的節目,我將建議代碼閱讀和代碼質量的Spinellis。我相信,他們有來自不同項目的代碼樣本,所有FOSS,所以你不僅可以閱讀它們,而且可以閱讀本書和最新版本中討論的版本,從中閱讀更多代碼並學習。


5

Linux kernel是一個很好的學習方式。

我知道,由於多架構結構和大量的代碼可能很難深入研究,但有一些很好的文章可以慢慢進入,如this one from Tim Jones

我通過查看特定主題(如FAT驅動程序實現和文件系統抽象)瞭解了很多。

12

我可以推薦Simon Tatham's puzzle collection。這是一系列可用於Windows,OS X和Linux(以及Java小程序)的益智遊戲(掃雷,數獨,十五)。這個架構非常簡單:有三個實現(每個平臺一個)的前端接口,每個遊戲實現一個實現的後端接口(我給出了三個示例)和一個讓他們一起談話的中端,做序列化和其他整潔的東西。

基本上,這是很好的面向對象。用C寫。很容易做出貢獻(我實現了灌裝和範圍遊戲),因爲它有很好的文檔記錄,並且很容易閱讀。

3

相對較小,但有足夠的複雜性,以便能夠從中吸取教訓,我的投票去:

Apache的Log4Net日誌框架。

它的源代碼非常易讀,並且可以在跨平臺的C#開發課程中學到很有價值的「跨平臺」[可編譯爲.NET 1.0,1.1,2.0,CF,MONO ...]。 ...

5

我發現的最清晰簡潔的源代碼之一是jQuery源代碼。無論您是否喜歡Javascript,對於「代碼作爲文檔」的支持者來說,這都是一個很好的例子。

有很多評論,但它不是ascii藝術品,你可以看到明確的推理 - 評論讓你知道到底是什麼試圖實現。

一個例子(full source):

(function(){ 

var 
    // Will speed up references to window, and allows munging its name. 
    window = this, 
    // Will speed up references to undefined, and allows munging its name. 
    undefined, 
    // Map over jQuery in case of overwrite 
    _jQuery = window.jQuery, 
    // Map over the $ in case of overwrite 
    _$ = window.$, 

    jQuery = window.jQuery = window.$ = function(selector, context) { 
     // The jQuery object is actually just the init constructor 'enhanced' 
     return new jQuery.fn.init(selector, context); 
    }, 

    // A simple way to check for HTML strings or ID strings 
    // (both of which we optimize for) 
    quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/, 
    // Is it a simple selector 
    isSimple = /^.[^:#\[\.,]*$/; 

jQuery.fn = jQuery.prototype = { 
    init: function(selector, context) { 
     // Make sure that a selection was provided 
     selector = selector || document; 

     // Handle $(DOMElement) 
     if (selector.nodeType) { 
      this[0] = selector; 
      this.length = 1; 
      this.context = selector; 
      return this; 
     } 
     // Handle HTML strings 
     if (typeof selector === "string") { 
      // Are we dealing with HTML string or an ID? 
      var match = quickExpr.exec(selector); 

      // Verify a match, and that no context was specified for #id 
      if (match && (match[1] || !context)) { 

       // HANDLE: $(html) -> $(array) 
       if (match[1]) 
        selector = jQuery.clean([ match[1] ], context); 

       // HANDLE: $("#id") 
       else { 
        var elem = document.getElementById(match[3]); 

        // Handle the case where IE and Opera return items 
        // by name instead of ID 
        if (elem && elem.id != match[3]) 
         return jQuery().find(selector); 

... 
+1

大部分意見都可以避免。 「代碼是文檔」不是亂七八糟的代碼,真的。當我讀到評論是代碼味道的時候,馬丁福勒啓發了我。 – rpattabi 2010-05-21 22:17:33