Live data from Hacker News

Rob Pike’s Rules of Programming (1989)

users.ece.utexas.edu

201–210 of 332 posts

Re: Rob Pike’s Rules of Programming (1989)

#201
post #7

Am I wrong to avoid writing O(n^2) code if at all possible when it is fairly easy to use hash tables for a better time complexity? Sure when n is small the O(n^2) one will be faster but when n is small /anything/ you do is fast in absolute terms so I'm trying to not leave traps in my code just waiting for n to get bigger than initially expected.

What about when n is small but you do it m times and m is large.

Re: Rob Pike’s Rules of Programming (1989)

#202
post #29

Earlier quoted context omitted.

Using array based data structures also get you more cache hits. For smaller data sets, this may well be faster than a fancy algorithm.

This is true only if you are iterating over the entire array often. If you only rarely need to access one data member the array will not be in cache and so you have less to load from memory. Depending on how your data is structured the array may or may not save time even in small sizes.

Prefetching still may make it way faster.

Re: Rob Pike’s Rules of Programming (1989)

#203

Earlier quoted context omitted.

An early mentor put it as “learn the data, which won’t change, before learning the fancy stuff on top, which will” That carried me very well.

Plenty of professional developers would benefit greatly if they read Domain-Driven Design.

Interesting. What’s the best resource beyond the Wikipedia page?

Re: Rob Pike’s Rules of Programming (1989)

#204
post #136

Earlier quoted context omitted.

And it is usually quoted out of its context. "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%."

It's also often interpreted literally. Premature complex optimization is a bad idea, but simple (read, cheap to code) optimization for common bottleneck patterns is a perfectly reasonable thing to do.

It's also often (ab)used far too often to justify performing no optimisation at all.

Re: Rob Pike’s Rules of Programming (1989)

#205

Earlier quoted context omitted.

I think maybe you are misreading the rule, it doesn't say don't optimize, it says when optimizing, don't guess from the code where the bottleneck is, go measure it.

Yeah but some things like how you structure your data(which then drives CPU cache misses) aren't something you can easily adjust/tune. Usually when you encounter one of those it's a rewrite/rearchitecture of a whole module/subsystem before you see any gains. Been there done that, not excited to repeat it again.

sure, sometimes your approach is at fault, but as the rule says, sometimes it's just a surprising bottleneck. Having done a lot of embedded work, I've found that many of those can often be fixed in a straightforward manner. Sometimes, you have to change your approach though.

Re: Rob Pike’s Rules of Programming (1989)

#206

Earlier quoted context omitted.

That case you've seen speaks of the guy's inexperience and lack of understanding. I have a problem with this rule because what I see happening is people taking it to heart and no longer thinking about what they're doing performance-wise. And then the program is working 1000x slower than it should, at no extra gain (and often a loss) of readability or safety, just because someone decided to use O(n) data structure whe…

Architecture is not optimization. This gets fuzzy with the decision to use caching, static generation, etc. Ideally, redis or memcached can be added when needed. It will require some changing of the app but hopefully in limited places. This rule a la Pike is about doing things like writing assembly or manually unrolling loops in noncritical parts of code. However, in some code, almost everything is on the critical pa…

That’s not obviously absurd. If Amdahl’s law permits then Little’s law tells you whether or not it’s possible.

Re: Rob Pike’s Rules of Programming (1989)

#207

A quote from one of our founders that I've always liked: If you make an optimization that was not at a bottleneck, you did not make an optimization.

Read The Goal by Eliyahu Goldratt. While it's possible your founder came upon the idea independently, this is one of many that are repeated in that book. It's relatively short and entertaining to read and has definitely survived the 36 years since first publishing quite well.

This is what instantly came to mind for me. Making a station faster generally only matters when it's a bottleneck.

It doesn't matter how optimized your computations are if you're spending the whole time waiting in IO. And don't forget that the program is generally just a piece of a larger process.

Re: Rob Pike’s Rules of Programming (1989)

#208
post #126

> 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. I wish people would follow this rule and just let stuff work. I recently encountered the most extreme version of this I've ever seen in my career: a design review where a guy proposed a Redis caching layer…

It seems that a subset of developers are somehow convinced that adding complexity is a good thing for performance and should be done first, when it should really be a last resort. Their usual rebuttal is "it's scalable" and other buzzword-laden phrases. I wonder if it's a form of "big data envy" or just regular "architecture astronautism".

Re: Rob Pike’s Rules of Programming (1989)

#209
post #206

Earlier quoted context omitted.

Architecture is not optimization. This gets fuzzy with the decision to use caching, static generation, etc. Ideally, redis or memcached can be added when needed. It will require some changing of the app but hopefully in limited places. This rule a la Pike is about doing things like writing assembly or manually unrolling loops in noncritical parts of code. However, in some code, almost everything is on the critical pa…

That’s not obviously absurd. If Amdahl’s law permits then Little’s law tells you whether or not it’s possible.

Yep. As I said I’m not smart.

Re: Rob Pike’s Rules of Programming (1989)

#210
post #133
post #126

> 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. I wish people would follow this rule and just let stuff work. I recently encountered the most extreme version of this I've ever seen in my career: a design review where a guy proposed a Redis caching layer…

This is particularly exasperating for me. I can't tell you how many times in my professional career I've ended up speeding up systems by removing two or three layers of improperly-implemented "caching" and using good ol' MySQL and a basic understanding of algorithmic time complexity to simplify things.

My tech lead once speed up our system by just turning off Memcached. :-)
Post reply on HN