Style Guide - TecnicasdeProgramacao2016/EuVou GitHub Wiki
-
Name's Declaration
1.1. Variable: Use the camelCase standard.
1.2. Classes: Use the camelCase standard with the first letter in uppercase.
1.3. Methods: Use the camelCase standard. Don't use spaces between variables or types and the braces.
1.4. Abbreviations: Use it just in variables, and, when declared, and should have and comentary explaining it -
Identation 2.1. Curly brackets
2.2. Parentheses
2.3. Collum Limit -
Headers
-
Comentaries
-
Markers
-
Operands and Atribution Signs
-
Javadoc
-
References
##1. Name's Declaration
Ex1:
private JSONObject eventDATA;
Ex2:
private SearchView searchView;
Ex1.:
There is a table of variables format:
To spaces on names of variables:
Ex1:
private int itemId; //this is fine
private Color color; //this too
private int itemId; //permitted, but future edits
Ex1:
public class EventConsultation extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener
{
}
Ex2:
public class LoginActivity extends AppCompatActivity implements View.OnClickListener
{
}
1.3 Methods: Use the camelCase standard. Don't use spaces between variables or types and the braces.
Ex1:
protected void onCreate(Bundle savedInstanceState)
{
}
Ex2:
private void initViews()
{
}
1.4 Abbreviations: Use it just in variables, and, when declared, and should have and comentary explaining it.
Ex1:
app //Aplication
Ex2:
int id = item.getItemId(); //id is a identifier
When using curly brackets "{" and "}", use it one line below. Use a tab size four after every scope change.
Ex1:
if(isPasswordValid == false)
{
passwordField.requestFocus();
passwordField.setError(loginValidation.getInvalidPasswordMessage());
}
else
{
}
Note: always use else if have some if on code.
Ex2:
switch(number)
{
case 1:
{
//Use curly brackets just if the case have more than one line.
break;
}
case 2:
break;
case 3:
break;
default:
break;
}
Note: The default case is allways present if have a switch on code.
Exception: In try-catch, the "catch" parte should be on the same line.
try
{
json = new JSONObject(str);
}catch (JSONException exceptionJSON)
{
exceptionJSON.printStackTrace();
}
With parentheses, don't use space after or before it.
Ex1:
function(int variable)
Whith brackets, don't use space after or before it.
Ex1:
full_name[1] = "Name"
Colluns should have a limit of 100 caracteres, and if it's surpassed we use one linebreak. In the line below the identation, starts lined up with its statement.
Ex1:
getDataTime (int month, int year, int day, int hour,
int minute, int second)
{
//function
}
Ex2:
variablesAverage = (variable1 + variable2 + variable 3 +
variable 4)/4;
Every class should have an Header with the file's name and purpose.
Ex1:
/*
* File name: arquiveName.
* File pourpose: This file have de pourpose to be an example.
*/
All comments must be in english, starting with uppercase. For one line comment use "#", and more lines use "/**/"
Ex1:
//Inflate the menu
Ex2:
/*
*Validates and set user alteration
*to user
*/
The markers will only be included in the code in upercase and with the restritions bellow.
When a part of the code need future rewrite, a marker “//BAD CODE” needs to be included.
Ex1:
int r = a + b //BAD CODE
If your already start to rewrite a code and not finished yet, a marker “//NOT FINISHED” needs to be included.
Ex2:
int result;
result = firstNumber + b; //NOT FINISHED
Ex3:
default:
//NOTHING TO DO
break;
When a conditional code have a default that don’t do nothing to do, a marker “NOTHING TO DO” needs to be included.
Ex:
switch (checkedButton)
{
case id.radio_events:
//CODE
default:
//NOTHING TO DO
break;
}
Both of them use the same standard: space between words or numbers.
Ex1:
for(int i = 0; i < idCategories.size(); i++)
{
}
Ex2:
b = c + a;
Ps: In example one, notice that for increment operation is not use space between the number and the operand.
The basic formatting of Javadoc blocks is as seen in this example below. This tool should be used in classes and methods; Ex1:
/**
* Javadoc Example
*/
Ex2:
/** Comment of one line in Javadoc */
To make this wiki some techniques were used according Google Java Style Guide