Questions to Ask & Habits to Have (when programming in java)

Good Questions to Ask

  • Input What information does the program need to know to perform its task? How can the program get this information -- from command line arguments? ...from standard input? ...via a dialog box? ...via mouse movements? ...from a file? etc...

  • Output What output needs to be created? What form should this output take? Should something be communicated to the user? Should information be sent back to the console? Should a file be created? ...a graphic? ...other media?

  • Variables & Declarations What information needs to be remembered, and what data type is the most appropriate to use? What type of information is it -- something numerical? ...text? ...a single character? ...a condition? object? In the case of numerical values, what range of values will be dealt with? Are there a bunch of similar values that must be remembered that could be consolidated into an array? Should this array be 1D, 2D, or some other dimension? Should the information be public? ...private? ...something in between? Is the information tied to a particular instance of an object? ...or should it be static?

  • Initializing and Updating What should the value of each of my variables be initially? How should each variable's value be updated throughout the program?

  • Calculation Does a value need to be calculated? Is the calculation clear and efficiently executed?

  • Conversions Does this value (or information) need to be in a different form for the next thing the program must do? Can this be accomplished by promotion? casting? an existing method? a custom method of my own design?

  • Conditionals Will the program need to do one thing if some condition applies, and something else if another condition applies? What conditions must be considered? What actions must be taken? What's the most appropriate conditional to use in light of these answers? ("if", "if-else", "?", "switch")

  • Loops Does something need to be done multiple times in a row? ...a fixed number of times? ...will it have to be done at least once? ...until some condition holds? what condition? What's the most appropriate looping structure to use in light of these answers? ("for-loop", "while-loop", "do-loop")

  • Methods Does something need to be done multiple times in different places in the code? Would it help to consolidate code all related to some overall task into a method? Should the method produce output? If so, what type of output should it create? What inputs will it need to do it's job?

  • Using Arrays Does something need to be done to every element of an array? What type of looping is required (for 1D arrays, a single for-loop might do, for 2D arrays, nested loops are probably necessary)? Can what needs to be done be modeled after one of the standard simple tasks for which arrays are helpful? (finding the position of an element, counting occurrences of an element, summing elements, finding a maximum or minimum, etc...)

  • Designing Classes What instance variables should be associated with objects of this class - what information describes the state of the objects in this class? What should happen during the construction of objects in this class? What instance methods are required - what should the objects of this class be able to do? What should the visibility of each instance variable or method be -- public, protected, default, private? What methods of this class should be static? What public static constants should be made available to users of this class?

Good Habits to Have

  • For variables that reference objects -- were they declared and constructed before being assigned values or otherwise modified?

  • Did I avoid the use of "magic numbers"?

  • Did I use good style?

  • Are my calculations and their order of application clear?

  • Have I found a good balance between clarity and efficiency?

  • Have I avoided coding essentially the same routine more than once?

  • Have I named objects with nouns and methods with verbs?