CMSC 201

Lab 10: Program Design

Program Design

Designing your program is very important! For each assignment so far this semester you have probably just sat down and started coding, until now. As the assignments get longer and longer you're going to want to try and put a little thought into the design of your program. Taking a little time at the beginning of a project to write (or even draw) out the design can save you a lot of time down the road!

Some tips for program design:

  • Functions! When you start a program take a moment to think of any "tasks" that you may do more than once or twice (print something very long, get input, do a certain calculation, etc). Instead of writing the same chunks of code over and over again in your program, you can write it all once in a function. Now you can just call the function you've written each time you need to execute whatever it is that function does. This will save you a lot of time down the road

  • Variables! Come up with a list of any variables you might need, and think about where to "store them". If you initialize them in the wrong place they may go out of scope and your program will crash.

  • Flowcharts! If you're a visual person, or you just need to get a grasp on what your program should accomplish, try drawing a flowchart. Read the problem, and draw out the steps your program should undertake in order to correctly solve it.

  • Most of all: don't just write, think! Before diving into writing code, give this problem some thought. The same goes for future homework assignments and project; you should always read through the instructions, unerstan the problem at hand, and plan out your solution first.