Remix.run Logo
r3trohack3r 4 hours ago

Rob Pikes 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.

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.

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.)

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.

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.

https://web.archive.org/web/20260314210910/https://users.ece...

eviks 3 hours ago | parent | next [-]

> Data structures, not algorithms, are central to programming

So you agree that they should've designed the system to use the appropriate data structure from the beginning?

ecnahc515 3 hours ago | parent | next [-]

Notice rules are ordered. You don't optimize until you know you need it. They started with a data structure they though would be fine. Clearly it was fine since it worked and they decided it was later worth optimizing.

3 hours ago | parent | prev | next [-]
[deleted]
win311fwg 3 hours ago | parent | prev [-]

The existence of 1.1.1.1 speaks to a much larger design problem. If you want to talk about what should have been done, you need to step much, much further back.

eviks 3 hours ago | parent [-]

I don't want to step back and go off topic

win311fwg 2 hours ago | parent [-]

"Should" cannot be evaluated in a vacuum. The only thing that would be off-topic is pretending that it can be.

perching_aix an hour ago | parent | prev [-]

> Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest.

Genuine question, is software performance really linear like that, that one can and should only fight the tightest bottleneck, one workload at a time? Never really sounded right.

It also sounds like the typical sleight of hand where the difficult bit is simply laundered a layer up, in this case the choice of what workload one investigates.