Software Development Pointers

  1. Always have code that compiles.
    1. Start by writing core class and function declarations, and stubs for all functions (including main). Write all of your file, class and function headers now (you can change them later if necessary). Write the makefile and make sure the project compiles before beginning the real coding.
    2. As you develop your code, compile VERY frequently, on the order of every 3-10 lines. You don't necessarily have to test your code each time, just make sure there are no compiler errors. (Having an extra terminal open makes this easy.)
  2. Practice incremental development.
    1. Always have code that mostly works and does not crash or hang.
      1. This makes it possible to test each new addition simply by running the program (or call the function).
      2. If you can't finish the project, you can still potentially get full credit for each component of the project that you did complete.
      3. Before making major changes, make a backup of the current file or the entire project folder (depending on the scope of the change).
    2. Don't try to solve complicated problems all at once. Get some of the framework in place (initial steps, outer loops, etc) and make sure those steps are working before continuing.
      1. If you do this, you can be fairly certain that any bugs that come up are in the code you just wrote. Tracking down bugs is one of the biggest time sinks in programming.
      2. If you realize that you are doing something the wrong way, there will be much less code to rewrite.
    3. Document your code as you go.
      1. Tell what you're going to do before you do it, for everything except very trivial code. Verbalizing your plans will force you to check that what you're doing makes sense.
    1. Do the majority of your testing as you go.
      1. Again, this helps you avoid searching for a bug in some code you wrote long ago.
      2. Also, you're more likely to remember the relevant tests for errors.
  3. Test every possibility.
    1. Make sure every logic path (if-else, switch-case, loop conditions, mid-loop breaks) works as intended.
    2. Make sure your program works for a variety of input, not just a couple cases.
      1. This time, you're not thinking about your code's structure, but trying to find any input that might not work as expected.
    3. Check for input errors (e.g., bad input that doesn't necessarily have a correct output). Even if your documentation states that some input will have undefined output, you at least need to make sure your program won't crash.

Last updated 12/29/12