-
-
Notifications
You must be signed in to change notification settings - Fork 0
Code Standards
Greg edited this page Dec 30, 2023
·
3 revisions
All methods, classes, records, enums, etc must contain comments in the following ways:
- Classes will have a top level JavaDoc style comments that defines the author, version and what the purpose of the class is.
- Methods will all have JavaDoc style comments using the proper @annotation
- This project will use K&R style for braces meaning there will be a new line between definition and opening brace
- All if else, for, while statements that have one line bodies will omit the braces.
/* K&R style as branch has more than one statement in the body*/
if(1 != 0)
{
x = 3;
y = 5;
}
/* branch with only one statement in body omits braces */
if(!valid(4))
return false;
while(run())
play_game();
public void args()
{
out.print("BYE");
}- always import System.out in classes so print statements will look as so
import static java.lang.System.out;
out.printf("My name is %s", name);- make use of the printf() method or .formatted() to print formatted strings.
out.printf();
"%d".formatted(5);- Print statements will not make use of the + operator to concat strings nor will we use System. as a qualifer for print statements
/* unacceptable print statements */
System.out.println("My name is " + name);
System.out.print();
System.out.println();
/* acceptable print statements */
out.printf("My name is %s\n" , name);
"My name is %s".formatted(name);- all function variables will be declared at the top of the function
- function names will use snake_case and not CamelCase
/* snake_case names */
private void print_note()
{
out.printf("Note Subject: %s", this.get_subject());
}
/* variables declared at start of method */
private boolean valid()
{
boolean is_valid = false;
return is_valid;
}