Lecturer: Dr. AJ Bieszczad Chapter 76-1 Software engineering standards Standards for you Standards for others Matching design with implementation
Lecturer: Dr. AJ Bieszczad Chapter 76-2 Algorithms Efficiency may have hidden costs –cost to write the code faster –cost to test the code –cost to understand the code –cost to modify the code
Lecturer: Dr. AJ Bieszczad Chapter 76-3 General guidelines Localize input and output Include pseudocode Revise and rewrite, rather than patch Reuse
Lecturer: Dr. AJ Bieszczad Chapter 76-4 Exception handling try { // code to try } catch (Exception e) { // exception handler } finally { // code executed under any circumstances }
Lecturer: Dr. AJ Bieszczad Chapter 76-5 Assertions In Java code: assert n > 0;// first form assert n > 0 : “n is zero!” // second form int i = k / n; Compiling: javac –source 1.4 Enabling and disabling assertions: java command line parameters -ea[:...|: ] -enableassertions[:...|: ] -da[:...|: ] -disableassertions[:...|: ] -esa | -enablesystemassertions -dsa | -disablesystemassertions Error throws if condition not satisfied: Exception in thread “main” java.lang.AssertionError: n is zero!
Lecturer: Dr. AJ Bieszczad Chapter 76-6 Documentation Internal documentation –header comment block –other program comments –meaningful variable names and statement labels –format to enhance understanding –document data External documentation –describe the problem –describe the algorithm –describe the data
Lecturer: Dr. AJ Bieszczad Chapter 76-7 Class Header /** * * Note that there are two stars starting the comment. This makes the comments * eligible for processing with JavaDoc. * * HTML can be used in here; e.g., * This program... explain whatever it does, under what assumptions, what is the input and what is * the output, etc. * * annually, * monthly, and * daily. * * * is a control statement for JavaDoc * You can generate documentation using JavaDoc * My Name * */ // Here you start your class...
Lecturer: Dr. AJ Bieszczad Chapter 76-8 Method header /** * * Note that there are two stars starting the comment. * This makes the comments eligible for processing * with JavaDoc. * * Describe what the method does. You can use HTML. * parameterName parameter explanantion hour provides an integer representation * of the hour to set * explain what is returned from the method * (only if this is a typed function!) */ // now start your method code...