Zero Bugs Notes

Zero Bugs and Program Faster

By Kate Thompson

Notes:

Chapter 2: Code that Doesn’t Leak

“If the design is so complicated that there are no obvious deficiencies, the deficiencies are hidden”

Ch 7: Know What Each Function Call Does

“API’s are one of the most common sources of programming bugs”

Chapter 8: Reusable Code

If you want people to build on your code, it needs three things:

  1. An obvious way to extend it
  2. An easy way to extend it
  3. A fast way to extend it

Chapter 9: Cyclomatic Complexity

'Cyclomatic complexity’ … means ‘number of paths through code’
When code is as simple as the problem you’re trying to solve, then you’ve succeeded. … Code can never be simpler thatn the problem it is trying to solve: that’s when you’ve done enough.

Chapter 10: One Small Piece at a Time

Bob Martin developed three rules for unit tests…

  1. You are not allowed to write any code unless it is to make a failing unit test pass.
  2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
  3. You are not allowed to write any more code than is sufficient to pass the one failing unit test.

Chapter 12: Each Line Changed is a Chance for a Bug

If you want to be sure, you will need to test in multiple layers: code review, black-box testing, fuzz testing, white-box testing, unit-tests, functional tests, manual tests, formal verification, design verification, etc. The more layers of testing, the fewer bugs.

  • Fuzz testing: providing invalid/unexpected/random inputs to a program
  • White box testing: intern structure of a program is known to the tester
A simpler way to introduce unit tests to an old project is to only write them for code you need to change anyway…

Chapter 13: The Team and Literate Programming

“The term Literate Programming means writing your program for a human to read”
“... for a deep taste of literate programming, download cweb and play.”

Chapter 19: Structural vs Real Code

Real code is code that actually does things: open a file, draw on the screen… Structural code connects things together. … minimize structural code as much as possible.

Chapter 21: Use Data to Optimize and Win Arguments

When an argument goes on for a long time, it is usually because of a lack of data, or because neither side is right.
If you haven’t timed your code before the change and after the change, you don’t know whether you’ve improved things or slowed them down.

Chapter 22: Be Your Own Worst Enemy

A way to help examine your own ideas (and other people’s) is to recognize when you are proposing a hypothesis… If someone presents an idea without any evidence to back it up, it’s a hypothesis.

Chapter 26: Points of Flexibility

Sometimes programmers create bugs by trying to fit every piece of code into a design pattern. Instead of increasing flexibility, they decrease flexibility because the problem isn’t well defined, and isn’t a good match for the chosen design pattern.

Chapter 27: Do it Later

Writing code before it needs to be written is poor management.
Clean the things that have serious potential to cause problems, like poor interfaces, or doce that you are working on right now

Chapter 29: Bad APIs Cause Bugs

Fixing mistakes, instead of starting over from scratch, is the way to learn.
Any time we change a software standard, it’s an act of violence. It’s disruptive. It will cause stuff to fail. It will cause cost and harm people

Chapter 30: Lessons from Lisp

Control side effects

Chapter 31: ACID

  • Atomic- Actions succeed completely or fail completely
  • Consistency- The system has rules and it will always follow those rules
  • Isolation- If the system handles multiple threads, it remains consistent, as if each thread ran in isolation
  • Durability- Once an operation is complete, it stays complete
Protected action- If something goes wrong the action can be reveresed
Real actions cannot be reversed

Chapter 34: Contracts, and When You are too Lazy for Proofs

An invariant is always true. … Invariants define what a class does, although the invariants might not be formally defined

Ch 38: Von Meuman

TODO- Look up John von Neumann
Book Richard Feynmann `QED: The Strange Theory of Light and Matter`

Chapter 39: Gates

Priorities:

  1. Take care of your customers first
  2. Second, take care of your employees
  3. Then take care of your stockholders