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:

Reduce invariants

Disallow multiple sources of truth (don’t cache, minimize mutable state)

Avoid backwards links

Simplify control flow

Don’t optimize your program until it’s complete and correct.

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