Style Sheet Java - DesenhoMaster2017/SpaceShooter GitHub Wiki

Style Sheet Java

  1. Names - attributes, variables, methods, class and constants Every variable must have their names in english; Every branch, commit and issue must be written in english; The attribute, variable names must be written on CamelCase rule, with significant names:
  • Example: float thisIsAVariable; The method names must be written on CamelCase rule, with significant names:
  • Example: void methodOne; The class names must follow the CamelCase rule:
  • Example: class MyClass; The constant names must be written with capital letters, separating the words with ‘_’:
  • Example: const int NUMBER_PEOPLE;
  1. Notation to strings: It must be used double quotation mark ("") instead of single quotation mark ('') in all possible cases:
  • Example: askClientName = "Escreva o nome do cliente: ";
  1. Use of parentheses: It must be used on the following cases: Conditionals: if ( valueTotal == valueMonth && valueMonth == valueDay ) Functions: void rankingEnade ( int value )
  2. Use of braces: It must open the braces with one blank space on the same line: Conditionals: Example: if (valueTotal == valueMonth and valueMonth == valueDay) { // Do Something } In Functions: Example: float calculatesProfit(int days) { // Do Something Else } In Classes: Example: class SchoolEnade { // To Do }
  3. Line​ ​Length and Identation Avoid lines longer than 80 characters. When a statement won't fill in a single line, it may be necessary to break it; Indent with 4 spaces — pick one and stick with it. Be consistent. Do not indent with the TAB key — your indents will generally be way too wide. Example: if ( personAge < 18 && // There is more than 80 characters here personVip == NULL )
  4. Spacing : It must be put a blank (' ') on the following cases: Conditionals (after if and between the variables): Example: if (schoolBase > schoolCompare)

Functions (between the parameters): Example: cleanFields(allFields, personEnterprise) When you use the character ‘&’ to indicate parameter passing by reference, it must be put ‘&’ along with the variable name: Example: void schoolDepartmentRanking(int &referenceVariable) Math Operations: Example: (valueMonth * amountMonth) / (quantityEmployees) (“The month value is” + valueMonth); It must not exist a blank character after parenthesis or double quotation mark: Example: strWarning = (“Type Again:”); 7) Line break There should not be an extra line break between a function declaration and the begining of the code: Example: if ( quantityProduct == quantityStorage ) { // ToDo } There should be an extra line break between programming blocks: Example: for(estado = 0; estado < numeroEstadosPais; estado = estado + 1) { // ToDo } There should be a line break between the parameters of the builders: Example: public Client(String name, String cpf, String telephone, String age, Address address) { // Constructor } There should be a line break after the header of a class Example: /********************************************************** File: GestaoEmpresa.java Purpose: Main menu of the program. *********************************************************/ public class GestaoEmpresa { // Class declaration } 8) Comments: Comments begin with capital letter Use only // in comments to one line Example: // This is a simple comment. Comments with more than one line should start with / * and close with * / following the structure of the following example: Example: / This function calculates the profit

  • of the month in the sales department */
  1. Header: Every file must have a header containing one line with the name of the file and another with the purpose of the file:
  • Example: /************************************************
  • File: JuridicalClient.java
  • Purpose: JuridicalClient class implementation. *************************************************/
  1. Exception handling The exception handling follows the same pattern already presented here for conditional if:. The catch will begin after a simple space in the same line to which the try key closes. Example: Try { newPhrase = phrase.toUpperCase(); } catch(NullPointerException e) // CATCH OF THE POSSIBLE EXCEPTION. { // Exception handling System.out.println("The initial phrase is null, so as to solve the problem, it was assigned a default value. "); phrase = "empty phrase"; newPhrase = phrase.toUpperCase(); }