Principles catalog

Principles are general ideas. They explain why you do things a certain way, that is, they explain patterns. Take the sewing and woodworking pattern "measure twice, cut once." Why do that? Because of the principle "materials are expensive, and shouldn't be wasted." (OK, that's a pretty obvious principle.)

Here are principles on this website.

Title Summary Tags Where referenced
Ask users

If you're not sure what a program should do in special cases, ask the people who are going to use it.

Record subsets
Decomposition

Programs are too complex to think about all at one time. You need to break them into pieces, and work on one piece at a time. Of course, the pieces must work together.

Cleaning
Don't repeat yourself (DRY)

Write code only once, and call it as many times as you need.

Nested ifs
Don't trust user data

Validate and sanitize user data.

Validation
Get requirements right

Make sure you know what a program is supposed to do, before you write it.

Good variable names
  • Make all variable names lowercase.
  • Don't use Python keywords are variable names.
  • Use underscores (_) to separate parts of variable names.
  • Use meaningful variable names.
How the program works
Incremental testing

Test code as you write it. Write a bit, test a bit, write a bit, test a bit.

It's more efficient than writing an entire program at once, and then testing it.

Ray codes, Mars or bust!
Intention error

Computers don't know what you intend to do, only what you tell them to do.

How the program works
Organize files

Life is easier when you organize files into subfolders.

Spyder
Plan then zoom

Write a program as a broad plan first, leaving the deets for later. Then work on each deet separately.