1.1.1 Name Schemes and Formatting - Brickwolves/CodeCampWiki GitHub Wiki
In every programming language, there are specific stylings and paradigms that should be followed. It's tiresome but it makes your code INFINITELY more legible for others. This is especially important when you're working on a team of other coders where you need to share code frequently.
Commenting && JavaDoc
It's imperative that you comment your code properly so others can understand what's going on. You can write single line comments or multiline comments
// I am a single line comment
/*
I am a multi-line
comment!
*/
/**
* I am also a multi-
* line comment!!
*/
Every method we should include a multi-line comment like the third one shown above in order to describe what our method's do and the parameters they require. Otherwise we can use single-line comments to describe basic thought processes inside methods or constructors. Take the two bottom pictures for example (pulled from the Controller
class)
Naming Schemes
There are several naming schemes when it comes to naming Classes, Method, variables, and constants
Camel Case vs Underscores
Camel Case is when you concatenate every word and each word (excluding the first word) begins with an upper case letter. Meanwhile underscore naming is where each word is lowercase and concatenated with an underscore.
String camelCaseVariable = "I am a String stored in a variable that's named using camelCase"
String underscore_variable = "I am a String stored in a variable that's named using underscores"
It doesn't matter what you use as long as you're consistent. Some people use camel case for naming methods and variables, whereas I (Jamie) tend to use camel case for method names and underscores for variable names.
Classes: classes should be named using nouns that describe what the class models. They should be named in UpperCamelCase, meaning the first letter of EVERY word (including the first) is capitalized. This includes Enums and Interfaces
Constants: constants should be named using ALL CAPS where each word is separated by underscores like so: Java MAX_NUMBER_OF_PIZZAS
Indentation
A new block or block-like construct in Java is delineated by curly braces ({}). The code within each new block should be indented by four spaces relative to the previous level. When the block ends, the indent level should return to the previous level. This indent level applies to both code and comments throughout the block. (Brown CS200)