The following style guidelines will be strictly enforced!
(see also Appendix F of your textbook.)
| Header | Programs will begin with a comment block which includes the program name, description, author, date and an edit history. | |||||||||
| Comments | Whenever the function of a block of code is not immediately obvious, include a comment that explains it. In general, comments should be obtained from and therefore match the algorithm done during the design phase. | |||||||||
| Blank Lines | Blank lines should be used between methods and elsewhere to help clarify the structure of the program and to make it easier to read. | |||||||||
| Spaces | Use additional space characters to help make
your code easier to read.
Put a space before and after operators, eg. =, +, -, *, /, %, ... See examples below. Put space after the opening parentheses of a method call &
before the parameters, and put space after the closing parentheses of a method call Put a space after each semi-colon in the for loop |
|||||||||
| Meaningful names | All variables, methods and classes will be meaningfully named! | |||||||||
| Naming conventions | Constants: are all uppercase (eg.
SPEEDOFLIGHT ) You may use the underscore character
to separate out words if you wish (eg. SPEED_OF_LIGHT) Variables: lowercase but with the first letter of each embedded word except the first, capitalised (eg. sumSoFar) Classes: lowercase, but first letter of every word capitalised (eg. BigNumbers ) Packages & Interfaces: follow the same rules as class names. |
|||||||||
| Indentation | Programs (and algorithms) must be correctly
laid out & indented as follows:
Tip: Most modern integrated development environments, such as DrJava, JCreator, BlueJ, NetBeans and JBuilder, can arrange the indentation for you almost automatically as you type the code. Learning how to do this properly will save you a lot of time! Beginners frequently type the code first without any indentation, then indent it once it is debugged and working. This is a complete waste of time and defeats part of the reason for indentation in the first place. |