Rob Pike's 5 Rules of Programminghtml
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 1: 你沒法說出程序運行所花費的時間。 意外之處出現瓶頸,所以不要去嘗試猜想和加快速度直到你已證實這就是瓶頸所在。編程
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 2: 測量。 不要調整速度直到你已進行測量,即便這樣也不能,除非代碼的一部分可以覆蓋其他部分。less
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.)dom
Rule 3: 當n小時,花哨的算法很慢,n一般很小。花哨的算法有很大的常量。不要幻想除非你確切知道n在頻繁的變的很大。(即便n確實變大,首先使用Rule 2)編程語言
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.ide
Rule 4: 花式算法比簡單算法笨拙,而且他們實現更加困難。 使用簡單的算法以及簡單的數據結構。ui
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.this
Rule 5: 數據占主導地位。 若是你已選擇正確的數據結構且正確組織他們,那麼算法幾乎老是不言而喻的。數據結構而非算法,是編程的核心。
Brief Notes
Pike's rules 1 and 2 restate Tony Hoare's famous maxim "Premature optimization is the root of all evil."
Ken Thompson rephrased Pike's rules 3 and 4 as "When in doubt, use brute force.". Rules 3 and 4 are instances of the design philosophy KISS.
Rule 5 was previously stated by Fred Brooks in The Mythical Man-Month. Rule 5 is often shortened to "write stupid code that uses smart objects".
Who is Rob Pike?
Rob Pike, is now a Distinguished Engineer at Google co-authoring Go programming language, apart from other things. Prior to this stint, he worked at Bell Labs as a core member of the Unix Team.
Author of popular books like The Practice of Programming and Unix Programming Environment
Rob Pike,一個卓越的工程師,除其餘工做外,在Google合做開發Go編程語言。在此以前,在貝爾實驗室做爲Unix團隊核心成員。
The Practice of Programming and Unix Programming Environment等暢銷書做者。
References
Content is shamelessly copy-pasted from http://users.ece.utexas.edu/~adnan/pike.html
Posted by Karthik Sirasanagandla at Sunday, September 17, 2017
Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest
Labels: clean code, Performance, programming, ProTips
http://blog.codonomics.com/2017/09/rob-pikes-5-rules-of-programming.html
---恢復內容結束---
Rob Pike's 5 Rules of ProgrammingRule 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 1: 你沒法說出程序運行所花費的時間。 意外之處出現瓶頸,所以不要去嘗試猜想和加快速度直到你已證實這就是瓶頸所在。
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 2: 測量。 不要調整速度直到你已進行測量,即便這樣也不能,除非代碼的一部分可以覆蓋其他部分。
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.)
Rule 3: 當n小時,花哨的算法很慢,n一般很小。花哨的算法有很大的常量。不要幻想除非你確切知道n在頻繁的變的很大。(即便n確實變大,首先使用Rule 2)
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.
Rule 4: 花式算法比簡單算法笨拙,而且他們實現更加困難。 使用簡單的算法以及簡單的數據結構。
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.
Rule 5: 數據占主導地位。 若是你已選擇正確的數據結構且正確組織他們,那麼算法幾乎老是不言而喻的。數據結構而非算法,是編程的核心。
Brief Notes
Pike's rules 1 and 2 restate Tony Hoare's famous maxim "Premature optimization is the root of all evil."
Ken Thompson rephrased Pike's rules 3 and 4 as "When in doubt, use brute force.". Rules 3 and 4 are instances of the design philosophy KISS.
Rule 5 was previously stated by Fred Brooks in The Mythical Man-Month. Rule 5 is often shortened to "write stupid code that uses smart objects".
Who is Rob Pike?
Rob Pike, is now a Distinguished Engineer at Google co-authoring Go programming language, apart from other things. Prior to this stint, he worked at Bell Labs as a core member of the Unix Team.
Author of popular books like The Practice of Programming and Unix Programming Environment
Rob Pike,一個卓越的工程師,除其餘工做外,在Google合做開發Go編程語言。在此以前,在貝爾實驗室做爲Unix團隊核心成員。
The Practice of Programming and Unix Programming Environment等暢銷書做者。
References
Content is shamelessly copy-pasted from http://users.ece.utexas.edu/~adnan/pike.html
Posted by Karthik Sirasanagandla at Sunday, September 17, 2017
Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest
Labels: clean code, Performance, programming, ProTips
http://blog.codonomics.com/2017/09/rob-pikes-5-rules-of-programming.html