• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-60  評論-98  文章-0  trackbacks-0

            Rob Pike, 是AT&T Bell Lab前Member of Technical Staff ,現在google研究操作系統,Unix先驅,UTF-8的設計人,The Unix Programming Environment 和 The Practice of Programming 的作者之一。 在《 Notes on C Programming 》中從另一個稍微不同的角度表述了 Unix 的哲學(或者說是程序局部優化6原則):

            1. 你無法斷定程序會在什么地方耗費運行時間。瓶頸經常出現在想不到的地方,所以別急于胡亂找個地方改代碼,除非你已經證實那兒就是瓶頸所在。
            2. 估量。在你沒對代碼進行估量,特別是沒找到最耗時的那部分之前,別去優化速度。
            3. 花哨的算法在 n 很小時通常很慢,而 n 通常很小。花哨算法的常數復雜度很大。除非你確定 n 總是很大,否則不要用花哨算法(即使 n 很大,也優先考慮原則 2 )。比如,解決常見問題時,最簡單的樹——二叉樹(binary tree),總是比那些復雜的樹(AVL樹,伸展樹(splay tree)和紅黑樹、B-樹(B-tree),多叉樹(trie))來的高校。
            4. 花哨的算法比簡單算法更容易出 bug 、更難實現。盡量使用簡單的算法配合簡單的數據結構。
            只要掌握了數據結構中的四大法寶,就可以包打天下,他們是:array 、linked list 、hash table、binary tree 。這四大法寶可不是各自為戰的,靈活結合才能游刃有余。比如,一個用hash table組織的symbol table,其中是一個個由字符型array構成的linked list。
            5. 以數據為中心。如果已經選擇了正確的數據結構并且把一切都組織得井井有條,正確的算法也就不言自明。編程的核心是數據結構,而不是算法。
            6. 沒有原則 6 。

            Ken Thompson —— Unix 最初版本的設計者和實現者,禪宗偈語般地對 Pike 的原則4 作了強調:
            拿不準就窮舉

            附:E文原文(節選自《Notes on C Programming 》Rob Pike, February 21, 1989 )
            E文全文地址:http://www.lysator.liu.se/c/pikestyle.html
                  Most programs are too complicated - that is, more complex than they need to be to solve their problems efficiently.  Why? Mostly it's because of bad design, but I will skip that issue here because it's a big one.  But programs are often complicated at the microscopic level, and that is something I can address here.
                  Rule 1.  You can't tell where a program is going to spend its time.  Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you've proven that's where the bottleneck is.

                  Rule 2.  Measure.  Don't tune for speed until you've measured, and even then don't, unless one part of the code overwhelms the rest.

                  Rule 3.  Fancy algorithms are slow when n is small, and n is usually small.  Fancy algorithms have big constants. Until you know that n is frequently going to be big, don't get fancy.  (Even if n does get big, use Rule 2 first.)   For example, binary trees are always faster than splay trees for workaday problems.

                  Rule 4.  Fancy algorithms are buggier than simple ones, and they're much harder to implement.  Use simple algorithms as well as simple data structures.

                  The following data structures are a complete list for almost all practical programs:

            array
            linked list
            hash table
            binary tree
            Of course, you must also be prepared to collect these into compound data structures.  For instance, a symbol table might be implemented as a hash table containing linked lists of arrays of characters.
                  Rule 5.  Data dominates.  If you've chosen the right data structures and organized things well, the algorithms will almost always be self­evident.  Data structures, not algorithms, are central to programming.  (See Brooks p. 102.)

                  Rule 6.  There is no Rule 6.

            posted on 2008-02-29 08:39 創建更好的解決方案 閱讀(4484) 評論(4)  編輯 收藏 引用 所屬分類: E文全翻心路歷程C++專欄軟件設計

            評論:
            # re: 我是笨人——讀Rob Pike的《Notes on C Programming 》(附全文鏈接)[未登錄] 2008-02-29 09:41 | cppexplore
            非常不錯!這6個原則概括的還真是精辟!  回復  更多評論
              
            # re: 我是笨人——讀Rob Pike的《Notes on C Programming 》(附全文鏈接)[未登錄] 2008-02-29 09:42 | cppexplore
            非常不錯!這6個原則概括的還真是精辟!  回復  更多評論
              
            # re: 我是笨人——讀Rob Pike的《Notes on C Programming 》(附全文鏈接) 2008-02-29 18:32 | comiunknown
            5. 以數據為中心。如果已經選擇了正確的數據結構并且把一切都組織得井井有條,正確的算法也就不言自明。編程的核心是數據結構,而不是算法。

            這條雙手雙腳贊一個^_^  回復  更多評論
              
            # re: 我是笨人——讀Rob Pike的《Notes on C Programming 》(附全文鏈接) 2008-02-29 21:01 | 嘯天豬
            UTF-8的設計者是Ken Thompson,Rob Pike大概是第一時間見證了Ken Thompson設計UTF-8的過程  回復  更多評論
              
            久久精品亚洲一区二区三区浴池| 精品久久久久久国产| 久久久久免费视频| 欧美午夜A∨大片久久| 一级A毛片免费观看久久精品| 中文字幕精品无码久久久久久3D日动漫| 久久久久亚洲av成人网人人软件 | 亚洲人成无码久久电影网站| 久久99精品久久久久久野外| 国产精品成人久久久| 精品久久久久久久| 伊人久久大香线蕉AV色婷婷色| 国内精品久久久久| 久久无码国产专区精品| 久久综合综合久久狠狠狠97色88 | 久久一区二区三区99| 久久久久av无码免费网| 精品国产热久久久福利| 久久国产高潮流白浆免费观看| 欧美国产成人久久精品| 久久精品国产99国产精品澳门| 久久AV无码精品人妻糸列| 欧美久久久久久精选9999| 久久精品国产精品亚洲毛片 | 久久精品国产久精国产果冻传媒| 国产福利电影一区二区三区久久久久成人精品综合 | 久久亚洲AV无码精品色午夜| 91精品国产综合久久四虎久久无码一级| 思思久久精品在热线热| 久久午夜福利电影| 99久久国产综合精品五月天喷水| 久久影院综合精品| 久久综合88熟人妻| 91精品国产高清91久久久久久| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 91精品婷婷国产综合久久| 久久se精品一区精品二区| 国产精品久久午夜夜伦鲁鲁| 色欲综合久久中文字幕网| 亚洲AV日韩精品久久久久久| 亚洲va中文字幕无码久久不卡|