Anda di halaman 1dari 3

Programming Style (example)

 Use names describing functionality


 Capitalize parts

 Begin class names with capital letters


 Begin method, local and instance
variable names with small letters ..

Good choice Poor choice


Professor myClass
teachSections4to8 do
cs1201Professor x
More Programming Style
DO DON’T
int numSectors // in circle int count, size
int sectorSize // in degrees

For Static methods: classMethod();


AClass.classMethod(); anObject.classMethod();
More Convention
 Declarations only at the beginning
 One per line
 No literals (except for -1, 0, and 1 in loops)
 Qualify names fully

 Access static methods by class name


 Use parentheses liberally

 Declare public only if necessary

 Declaration "fields" then "method“, Constructor


first
 Initialize basic type fields at declaration

Anda mungkin juga menyukai