HN
Today

Rob Pike's 5 Rules of Programming

Rob Pike's timeless programming maxims provide concise guidance on performance, algorithm choice, and the primacy of data. This post sparked a vigorous Hacker News discussion, where seasoned developers debated the nuances of 'premature optimization' and the enduring wisdom of prioritizing data structures. It's a classic example of HN appreciating fundamental engineering principles and dissecting their modern applicability.

89
Score
37
Comments
#1
Highest Rank
9h
on Front Page
First Seen
Mar 18, 11:00 AM
Last Seen
Mar 18, 7:00 PM
Rank Over Time
111112461

The Lowdown

The article presents Rob Pike's five foundational rules of programming, offering practical wisdom for developers. These rules are presented as core tenets for writing efficient, maintainable, and robust code, often drawing parallels to other famous programming aphorisms.

  • Rule 1: Bottlenecks are Unpredictable. Don't pre-optimize; measure first, as performance issues often arise in unexpected places.
  • Rule 2: Measure Before Tuning. Only optimize for speed after profiling, and even then, only if a single part of the code is overwhelmingly dominant.
  • Rule 3: Simplicity for Small 'n'. Fancy algorithms, with their large constants, are slow for small data sets, which is usually the case. Avoid complexity unless 'n' is proven to be large.
  • Rule 4: Simple is Less Buggy. Complex algorithms are harder to implement and more prone to bugs. Prioritize simple algorithms and data structures.
  • Rule 5: Data Dominates. The choice and organization of data structures are paramount; with good data design, algorithms often become self-evident.

The document notes that Rules 1 and 2 echo Tony Hoare's 'premature optimization' maxim, while Rules 3 and 4 embody the KISS principle, paraphrased by Ken Thompson as 'When in doubt, use brute force.' Rule 5, emphasizing data structures, is linked to Fred Brooks' insights from 'The Mythical Man-Month,' often distilled to 'write stupid code that uses smart objects.'

The Gossip

Optimizing Optimization

Commenters delved into Rules 1 and 2 concerning premature optimization. While acknowledging the general wisdom, some experienced developers argued that, with sufficient domain knowledge, one can often anticipate bottlenecks. The discussion also veered into the historical attribution of the 'premature optimization is the root of all evil' quote, debating whether it originated with Tony Hoare or Donald Knuth.

Data's Dominance Dialogue

Rule 5, the idea that 'data dominates,' sparked significant conversation. Many echoed its importance, quoting figures like Linus Torvalds and Fred Brooks who similarly emphasized data structures over algorithms. The discussion also touched upon modern challenges, with some suggesting that current AI-driven development often produces 'naive' data structures, highlighting the continued relevance of this human-centric design principle.

The 'Obvious' Wisdom

A recurring theme questioned why seemingly 'obvious' rules needed elevation. Defenders argued that while these principles might appear self-evident to seasoned practitioners, they are crucial for beginners. Furthermore, they serve as vital reminders for everyone, as even 'obvious' good practices are often neglected, making their clear articulation by respected figures like Pike valuable.