120 likes | 243 Vues
Appendix A. Coding Conventions. Comments. Single line - //Here is a comment Multi-line - /* This is a multi-line comment */ Documentation comment - /** This is a documentation comment used by Javadoc */. Naming Conventions. Class – mixed case with words capitalized CyberPet TextField
E N D
Appendix A Coding Conventions William H. Bowers – whb108@psu.edu
Comments • Single line - //Here is a comment • Multi-line - /* This is a multi-linecomment */ • Documentation comment - /** This is a documentation comment used by Javadoc */ William H. Bowers – whb108@psu.edu
Naming Conventions • Class – mixed case with words capitalized • CyberPet • TextField • Interfaces – same as class, many interface names end with ‘able’ • Drawable • ActionListener William H. Bowers – whb108@psu.edu
Naming Conventions • Method – verbs in mixed case with first letter lowercase • actionPerformed() • sleep() • insertAtFront() William H. Bowers – whb108@psu.edu
Naming Conventions • Instance Variables – same as method names, should be descriptive and indicate data type • iMaxWidth • bIsVisible • fArea William H. Bowers – whb108@psu.edu
Naming Conventions • Constants – uppercase with internal words separated by underscore, prefix with data type • iMAX_LENGTH • dTAX_RATE William H. Bowers – whb108@psu.edu
Naming Conventions • Loop or temporary variables – may be single letter, preferred to name as Instance Variables • x, y, z • iRow • iColumn William H. Bowers – whb108@psu.edu
Braces • Begin and end of block • Ending brace should have comment • Indent and align Public void sayHello() { System.out.println(“Hello”); } // end of method sayHello William H. Bowers – whb108@psu.edu
Code Structure • Program header • Program/file name • Author • Date • Description • Modification log William H. Bowers – whb108@psu.edu
Code Structure • Import statements • Class header • Constants • Variables William H. Bowers – whb108@psu.edu
Code Structure • Methods • Method headers • Inputs • Outputs • Description • Notes William H. Bowers – whb108@psu.edu
Questions & Discussion William H. Bowers – whb108@psu.edu