Edward Wang

How to write better programs

I’ve learned a lot about programming in the past couple years and I thought I’d make a list of things to think about + avoid.

Good programs are simple and correct. Note how I didn’t include performant. Here’s a funny joke:

A reporter interviews a man who claims to be the world’s fastest mathematician.
“What is 5 times 5?” the reporter asks.
“25!” the man shouts immediately.
“What is 142 times 3,891?”
“552,522!”
“That’s completely wrong!” the reporter says.
“Maybe,” the man replies, “but I was fast!”

Here are some ways to make your programs better:

Struct design

Reduce invariants

Disallow multiple sources of truth

Avoid backwards links

Things to avoid in implementation

Simplify control flow

Use linear search instead of binary search

If you have any more please email me, I’m definitely missing some.