TGViewer
codedump的电报频道 codedump的电报频道 @codedump_notes · 5.5K subscribers
Post #483 3.24K
#编程
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:数据占主导地位。如果您选择了正确的数据结构并很好地组织了事物,那么算法几乎总是不言而喻的。编程的核心是数据结构,而不是算法。
  • 👍 21
  • ❤ 4
More from @codedump_notes
  1. Sep 27, 2026#系统编程 讲解Go语言并发主题的小书:《Go concurrency distilled》
  2. Sep 22, 2026#开源软件 开源本来承载的主要任务之一就是赢得信任,智谱这一把开源不但没有赢取信任,反而让更多人感到了疑问,比如我。
  3. Sep 22, 2026#开源项目 #Rust #数据库 hawdb:Rust编写的嵌入式图数据库,用于Nowledge产品中管理本地图数据。
  4. Sep 21, 2026#Rust #人工智能 最近看了好几个Rust相关的新闻,比如: * Rust在微软内部升级为一级语言:《Guest Post: Rust Is Tier-1 Language a…
  5. Sep 19, 2026#人工智能 这个翻译可以说是 信达雅 了。
  6. Sep 15, 2026#人工智能 《我不得不把才华埋葬在昨天》,Deepseek 核心开发的文章,也许再过一段时间,他就不用亲手写算子了。
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →