logoalt Hacker News

Rob Pike’s Rules of Programming (1989)

946 pointsby vismit2000yesterday at 9:59 AM439 commentsview on HN

Comments

sayYayToLifeyesterday at 2:28 PM

I suppose this makes me feel a little bit better about a multi-month process that ended up requiring the eight Queens problem.

That said management did not quite understand. They thought that I should have known about the bottleneck (Actually I did but I was told not to prematurely optimize)

I end up writing the program three times, the final solution was honestly beautiful.

Management was not happy. The customer was happy.

elcapitanyesterday at 11:44 AM

Meta: Love the simplicity of the page, no bullshit.

Funny handwritten html artifact though:

    <title> <h1>Rob Pike's 5 Rules of Programming</h1> </title>
show 1 reply
jancsikayesterday at 8:14 PM

Can you actually follow rule #1 for things like realtime audio programming?

Devastayesterday at 11:51 AM

> "Premature optimization is the root of all evil."

This Axiom has caused far and away more damage to software development than the premature optimization ever will.

show 1 reply
netbioserroryesterday at 2:58 PM

This resonates as true, as long as the fundamentals of your tools are there. Picking interpreted languages or browsers as targets shoots you in the foot and sets you magnitudes behind when performance starts to matter. But if you're using a native-compiled language with value- and move-semantics, immutable data, and a composable type system, it's shocking how easy it can be to write obvious, maintainable, fast programs that perform under pressure, even when you're not being clever.

Thankfully newer languages like Nim, Odin, and Swift lean hard into value semantics. They drastically reduce the cost of focusing on data structures and writing obvious algorithms. Then, when bottlenecks appear, you can choose to opt into fine-tuning.

igtztorreroyesterday at 12:29 PM

Rule 4, I have always practiced and demanded of junior programmers, to make algorithms and structures that are simple to understand, for our main user: the one who will modify this code in the future.

I believe that's why Golang is a very simple but powerful language.

nsnzjznzbxtoday at 4:29 AM

Electron.js took this concept a bit too far.

TimLelandyesterday at 2:52 PM

Take a look at the page title. I guess he didn't follow his own rules for this 100-line HTML file

<title> <h1>Rob Pike's 5 Rules of Programming</h1> </title>

show 1 reply
okamiueruyesterday at 4:43 PM

Rule 1 seems similar to Donald Knuths "premature optimization" from 1974.

> Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

Rule 2 follows rule 1.

Rule 3 & 4 is a variation of Keep it Simple, Stupid (KISS) from the 1960s.

... and... now I feel stupid, because I read the last part, which is summarizing it in the same way.

treetalkeryesterday at 1:25 PM

I'm not a skilled programmer (but would like to be someday). Would someone kindly resolve what appears to me to be a contradiction between the following?

1(a) Torvalds: "Bad programmers worry about the code. Good programmers worry about data structures and their relationships."

1(b) Pike 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."

— versus —

2. Perlis 2: "Functions delay binding; data structures induce binding. Moral: Structure data late in the programming process."

---

Ignorant as I am, I read these to advise that I ought to put data structures centrally, first, foremost — but not until the end of the programming process.

show 3 replies
piskovyesterday at 11:01 PM

> Pike's rules 1 and 2 restate Tony Hoare's famous maxim "Premature optimization is the root of all evil."

This thing never resonated with me.

I often hear it as an excuse to ignore “optimization” at all.

It’s like “broken windows” theory. This allows slop, rot, and technical debt in. And it spreads fast.

Also if everything is unoptimized, this is not what could be easily fixed.

Death of thousand cuts, if you will.

yandrypozoyesterday at 2:51 PM

does _a speed hack_ mean adding time.Sleep() for testing? or it's something else?

Mercuriusdreamyesterday at 11:14 AM

never expected it to be a single HTML file so kind of surprised, but straight to the point, to be honest.

show 1 reply
HardCodedBiasyesterday at 2:36 PM

Heretical opinion:

I think that Rob Pike was far more of a wordcel than a shape rotator for a famous computer scientist (which historically were very much on the shape rotator side).

mnkyprskbdtoday at 1:12 AM

Rob Pike is programming God of retardmaxxing. Go programming language is a good example of this, where it was the dumbest language for a longgg time.

up2isomorphismyesterday at 10:50 PM

Even agree with most of the stuff he said, however in real life, you won't be able to win a fight using these arguments. You can only create a environment to execute these strategies first to get a good product and them use them as a propaganda afterwards.

doe88yesterday at 11:47 AM

Great rules, but Rule 3.: WOW, so true, so well enunciated, masterful.

show 1 reply
awesome_dudeyesterday at 7:33 PM

I received some 'interesting' feedback when I spoke about commenting that I was using an O(n) search instead of an O(log n) algorithm because of the normally small size of n [0]

What I should have done was point to Rob's third rule (either in my comment or in the resulting threads)

[0] https://news.ycombinator.com/threads?id=awesome_dude&next=47...

fogzenyesterday at 3:01 PM

Rule 5 should be rule 1.

anthkyesterday at 11:21 AM

9front it's distilled Unix. I corrected Russ Cox' 'xword' to work in 9front and I am just a newbie. No LLM's, that's Idiocratic, like the movie; just '9intro.us.pdf' and man pages.

LLM's work will never be reproducible by design.

OpenDQVyesterday at 2:48 PM

Golden rules for sure!

ekjhgkejhgkyesterday at 2:29 PM

Uuuh doesn't look good that you claim something is important enough to be in your top 5, but then misattribute it.

ajpaulsonyesterday at 1:44 PM

I think I’m going to copy and paste this directly into my AGENTS.md file!

sunnyosyesterday at 7:01 PM

Seem logical

jcmartinezdevyesterday at 12:28 PM

Rule 6: Never disagree with AI slop

publicdebatesyesterday at 2:37 PM

"Rule 6: Don't waste time on syntax highlighting unless you're incompetent."

riclibyesterday at 8:37 PM

[dead]

maxothexyesterday at 9:42 PM

[dead]

seedpiyesterday at 5:38 PM

[flagged]

wei03288yesterday at 9:16 PM

[dead]

openclaw01yesterday at 11:45 AM

[dead]

devcraft41yesterday at 8:43 PM

[dead]

unit149today at 2:31 AM

[dead]

Iamkkdasari74yesterday at 12:01 PM

[flagged]

catchcatchcatchyesterday at 11:04 AM

[dead]

neonsunsetyesterday at 11:22 PM

[dead]

SomaticPirateyesterday at 3:06 PM

How quaint. I hope Claude/Codex reads this since from what I've heard here I'm not likely to need this rules anymore /s I am curious if anyone has attempted to use codex/claude with something like this in the prompt

Shawn19s83yesterday at 12:39 PM

[dead]

wsesamemr81yesterday at 3:19 PM

[dead]

shashank-100yesterday at 4:13 PM

[dead]

andxoryesterday at 2:33 PM

Great gonna add these to my CLAUDE.md /s

andrewmcwattersyesterday at 4:34 PM

[dead]

seedpiyesterday at 11:38 AM

[flagged]

_philipalanyesterday at 1:36 PM

CS Unc remains un-chopped.

bsenftneryesterday at 10:56 AM

Obvious. Why the elevation of the obvious?

show 7 replies