#编程
Rob Pike's 5 Rules of Programming
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.
规则 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.
规则 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.)
规则 3:当 n 很小时,花哨的算法会很慢,而且 n 通常很小。奇特的算法有很大的常数。在您知道 n 通常会很大之前,不要幻想。 (即使 n 确实变大,也首先使用规则 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.
规则 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.
规则 5:数据占主导地位。如果您选择了正确的数据结构并很好地组织了事物,那么算法几乎总是不言而喻的。编程的核心是数据结构,而不是算法。
Post #483
3.24K
- 👍 21
- ❤ 4