Summary

OK, so what did we learn?

  • Use good variable names. Let people reading your code understand what it does. That person might be you.
  • Comment your code with useful comments. Tell why, not what.
  • Use literals where appropriate. Make them reusable if that makes sense. I hate having to make the same change in several places.
  • White space is your friend. It can help with understanding what goes with what.
  • Build reusable functions to encapsulate some useful functionality. Just make sure it hasn't already been written.
  • Build a flexible database. They are more extensible and easier to maintain.
  • Always write code as though you have to fix it later, because you will. If you never have to fix something, it's either way too simple, or you aren't using it. No one writes perfect code all the time.
  • Break down your problem into solvable steps. Consider what the point of this code really is.

Reread this after you've written something new. Then fix what you wrote. You probably made a mistake somewhere.

A final set of examples, just for fun.