Skip to content

Latest commit

 

History

History
680 lines (497 loc) · 20 KB

CONTRIBUTING.md

File metadata and controls

680 lines (497 loc) · 20 KB

Octillect Style Guide


1. Git & GitHub Guidelines

1.1. Commit

  • Commits shouldn't contain multiple unrelated changes; try and make piecemeal changes if you can, to make it easier to review and merge. In particular, don't commit style/whitespace changes and functionality changes in a single commit.
  • Modify one file per commit. This will make merging and pulling easier for everyone.
  • Make sure that the App still runs before making a commit.
  • Make sure that the App passes all the tests before making a commit.

1.2. Commit Message

  • Separate message from body with a blank line.
  • Do not end the message line with a period.
  • Capitalize the message line and each paragraph.
  • Use the imperative mood in the message line.
  • Limit the message line to 50 characters.
  • Wrap lines of the body at 72 characters.
  • Asterisks are used for the bullets in message's body.
  • Punctuate your commit message's body.
  • Add two blank lines followed by Co-authors, if found, at the end of your commit message.
  • Example:
Add comments and other XAML code edits

 * Add x:Name attribute to all fields and buttons.
 * Use Pascal Case in naming instead of Camel Case.
 * Add Comments to make it easier to read the code.
 * Add whitespaces between code blocks.


Co-authored-by: Michael Safwat <michaelsafwat.hanna@gmail.com>
Co-authored-by: Micheline Medhat <MichelineMedhat@gmail.com>
Co-authored-by: Monica Adel <monicatanios@gmail.com>
Co-authored-by: Monica Atef <monicaatef46@gmail.com>
Co-authored-by: Youssef Raafat <YoussefRaafatNasry@gmail.com>

Pro tip: Use Code Spell Checker to avoid typos.

1.3. Submitting Pull Requests

  1. Fork and clone the repository.

  2. Create a new branch based on master: git checkout -b my-branch-name

  3. Make your changes, and make sure the app still runs and passes all the tests.

  4. Push to your fork and submit a pull request from your branch to master

    Here are a few things you have to do:

    • Write a good commit message.
    • Follow the style guide where possible.
    • Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
  5. After your pull request is merged:

    1. Delete the branch you created from your GitHub fork by navigating near the bottom of your pull request and clicking Delete branch:

      delete-branch-github

    2. Delete the branch you created from your local fork.

      git checkout master
      git branch -d my-branch-name
    3. Make your fork's master branch even with MonicaTanios:master

      git remote add upstream https://github.com/MonicaTanios/octillect.git
      git pull upstream master
      git push origin master
    4. Prepare for your next pull request.


2. Java Programming Guidelines

2.1. Naming Conventions

Identifier Case & Naming Example
Package lowercase deepspace
Class UpperCamelCase Character
Method lowerCamelCase sendMessage
Variable lowerCamelCase computedValues
Parameter lowerCamelCase name
Constant CONSTANT_CASE MIN_WIDTH

2.2. Declarations

2.2.1. Class and Interface declaration

2.2.1.1. Modifiers

Class and member modifiers, when present, appear in the order recommended by the Java Language Specification:

public protected private abstract default static final transient volatile synchronized native strictfp

Example:

final volatile private String value; // bad
private final volatile String value; // good
2.2.1.2. Order

Class and Interface declarations should be organized in the following manner:

  1. Class or Interface documentation, set inside the comment delimiters /**...*/.
  2. Class or Interface statement.
  3. Static variables in the order public, protected, package (no access modifier), private.
  4. Instance variables in the order public, protected, package (no access modifier), private.
  5. Constructors.
  6. Getter and setters.
  7. Methods (no specific order) but separated by a blank line.
/** Model Object for Example. */
public class Example {

    public static int foo;
    protected int id;
    private String name;

    public Example(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void updateData(int newId, String newName) {
        setId(newId);
        setName(newName);
    }

}

2.2.2. Variable declaration

Every variable declaration (field or local) declares only one variable.

int a;    // good
int b;
int c, d; // bad

2.2.3. Array declaration

The square brackets form a part of the type, not the variable

String[] args; // good
String args[]; // bad

2.3. Statements

2.3.1. Import statements

2.3.1.1 No wildcard/unused imports
  • Wildcard imports, static or otherwise, are not used.
  • Unused imports should be removed.
import java.util.ArrayList; // good
import java.util.Date;

import java.util.*;         // bad
2.3.1.2 Ordering and spacing
  • Imports should be grouped in blocks by top-level package.
  • Each block should be wrapped by a new line.
  • Blocks should be ordered in ASCII order.
  • Within each block, imports should be ordered in ASCII order.
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;

2.3.2. Simple Statements

Each line should contain at most one statement.

argv++;         // good
argc--;

argv++; argc--; // bad

2.3.3. return Statements

A return statement with a value should not use parentheses unless they make the return value more obvious in some way.

return;
return myDisk.size();
return (size ? size : defaultSize);

2.3.4. if, if-else, if else-if else Statements

The if-else class of statements should have the following form:

if (condition) {
    statements;
} else if (condition) {
    statements;
} else {
    statements;
}

Note: if statements always use braces.

if (condition) // bad
    statement;

2.3.5. try-catch Statements

A try-catch statement should have the following format:

try {
    statements;
} catch (ExceptionClass e) {
    statements;
} finally {
    statements;
}

2.4. Programming Practices

2.4.1. Consider setters and getters for field access

Within the same class consider using getters and setter to access fields values to ensure lazy initialization and other intended logic implemented in getters and setters is always applied.

public void changeName(String name) {
    setName(name); // good
}

public void changeName(String name) {
    this.name = name; // bad
}

2.4.2. @Override: always used

A method is marked with the @Override annotation whenever it is legal.
Exception: @Override may be omitted when the parent method is @Deprecated.

2.4.3. Static members: qualified using class

When a reference to a static class member must be qualified, it is qualified with that class's name, not with a reference or expression of that class's type.

Foo aFoo = ...;
Foo.aStaticMethod();  // good
aFoo.aStaticMethod(); // bad

2.5. Formatting

Use the following shortcuts in IntelliJ to help you optimize your code.

  • Optimize Imports: Ctrl + Alt + O
  • Reformat Code: Ctrl + Alt + L

2.5.1. Nonempty blocks

Braces follow the Kernighan and Ritchie style ("Egyptian brackets") for nonempty blocks and block-like constructs:

  • No line break before the opening brace.
  • Line break after the opening brace.
  • Line break before the closing brace.
  • Line break after the closing brace.
void myFunction() {
    System.out.println("I'm written in Egyptian brackets");
}

2.5.2. Empty blocks

An empty block or block-like construct may be in K & R style. Alternatively, it may be closed immediately after it is opened, with no characters or line break in between ({}).

  // This is acceptable
  void doNothing() {}

  // This is equally acceptable
  void doNothingElse() {
  }

2.5.3. Column limit

Java code has a column limit of 100 characters.

2.5.4. Blank Spaces

  • Blank space should not be used between a method name and its opening parenthesis. This helps to distinguish keywords from method calls.

    void doSomething(int x) {}  // good
    void doSomething (int x) {} // bad
  • Blank spaces should be used in the following circumstances:

  1. A keyword followed by a parenthesis should be separated by a space. Example:

       while (true) {
           statements;
       }
  2. A blank space should appear before the opening parenthesis ({) of a method or a class.

    void doSomething() throw Exception {}
    class Bar extends Foo {}
  3. A blank space should appear after commas in argument lists.

    void doSomething(int x, int y) {}
  4. All binary operators except . should be separated from their operands by spaces. Blank spaces should never separate unary operators such as unary minus, increment ("++"), and decrement ("--") from their operands. Example:

    a += c + d;
    a = (a + b) / (c * d);
    a++;
  5. The expressions in a for statement should be separated by blank spaces. Example:

    for (expr1; expr2; expr3)
  6. Casts should be followed by a blank space. Examples:

    myMethod((byte) aNum, (Object) x);
    myMethod((int) (cp + 5), ((int) (i + 3)) + 1);

2.6. References

  1. Google Java Style Guide
  2. Oracle Code Conventions for the Java Programming Language
  3. Java Programming Style Guidelines
  4. Twitter Java Style Guide
  5. 47deg Java Style Guide

3. JavaFX Guidelines

3.1. Controls Naming Conventions

Use lowerCamelCase names with a type indication Suffix.

<TextField fx:id="emailTextField" />

3.2. Event Handlers Naming Conventions

Use handle + Element Name + Event Name.

@FXML
protected void handleSubmitButtonAction(ActionEvent event) {
    .
    .
}

3.3. @FXML: always used

Variables and event handlers in the controller should always be annotated with @FXML especially if they are private or protected.

public class RegistrationFormController {

    @FXML private Button submitButton;

    @FXML
    protected void handleSubmitButtonAction(ActionEvent event) {
        .
        .
    }

}

3.4. Spacing

  • If the tag is self closing tag (/>), leave a whitespace before closing it.
  • Else, just close it (without any whitespace).
<GridPane>
    <TextField fx:id="passwordTextField" />
</GridPane>

3.5. Code readability

  • If the element has two or less attributes, put them in one line.
<Label text="name" textFill="black" />
  • If the element has more than two attributes, put one attribute per line.
  • Put the first attribute on the element line.
<Button fx:id="submitButton"
        text="Submit"
        onAction="handleSubmitButtonAction" />
1. Name
   - fx:id

2. Containers' attached properties
   - GridPane.rowIndex
   - GridPane.columnIndex
   - GridPane.rowSpan
   - GridPane.columnSpan
   - GridPane.halignment
   - GridPane.valignment
   - AnchorPane.topAnchor
   - AnchorPane.rightAnchor
   - AnchorPane.bottomAnchor
   - AnchorPane.leftAnchor
   - HBox.hgrow
   - VBox.vgrow
   - HBox.margin
   - VBox.margin
   - FlowPane.margin
   - GridPane.margin

3. Box Model
   - hgap
   - vgap
   - alignment
   - padding

4. Size
   - width
   - height
   - minWidth
   - minHeight
   - prefWidth
   - prefHeight
   - maxWidth
   - maxHeight

5. Position & Transform
   - layoutX
   - layoutY
   - rotate
   - scaleX
   - scaleY
   - scaleZ

6. Typography
   - text
   - promptText
   - textFill
   - font

7. Visual & Styling
   - background
   - opacity
   - visible
   - styleSheets
   - style

8. Event handlers (Alphabetically)
   - onAction
   - onDragDetected

* Note the following:

  • Width comes before Height
  • Rows comes before Columns
  • Horizontal comes before Vertical
  • X-axis comes before Y-axis
  • Use top, right, bottom, left rule.

3.6. References

  1. AwesomeJavaFX
  2. XAML Coding Guidelines
  3. Introduction to FXML
  4. JavaFX CSS Reference Guide
  5. caspian.css
  6. modena.css

4. UI Guidelines

4.1. Structure

Material Design layouts are visually balanced. Most measurements align to an 8dp grid applied, which aligns both spacing and the overall layout. Smaller components, such as iconography and typography, can align to a 4dp grid.

8dp and 4dp units

4.2. Responsive layout grid

The Material Design layout grid is made up of three elements:

  1. Columns
  2. Gutters
  3. Margins

Responsive layout grid

4.3. Window Sizes

Regardless of form-factor, most popular screen sizes are divisible by 8 on at least one axis - usually both. Additionally, some platforms’ style guides (like Material Design) call specifically for a grid of 4 or 8 points, making this system a natural fit.

most-used-screen-resolutions

4.4. Cards

Cards should have 16dp padding.

card-padding

4.5. Color Palette

Use the following colors:

Primary [light] Primary Primary [Dark] Success Info Warning Danger
#428feb #1473e6 #0f64d2 #28a745 #17a2b8 #ffc107 #dc3545
#428feb #1473e6 #0f64d2 #28a745 #17a2b8 #ffc107 #dc3545
Dark 100 Dark 200 Dark 300 Dark 400 Dark 500 Dark 600 Dark 700 Dark 800 Dark 900
#f5f5f5 #eeeeee #cdcdcd #9e9e9e #979797 #616161 #424242 #212121 #1b1b1b
#f5f5f5 #eeeeee #cdcdcd #9e9e9e #979797 #616161 #424242 #212121 #1b1b1b

4.6. References

  1. Google Material Design
  2. The 8-Point Grid

5. External Libraries

  1. JFoenix
  2. Java API for GitHub
  3. Ikonli
  4. Firebase Admin SDK
  5. gson

6. Design Patterns

  1. Singleton Design Pattern
  2. Composite Design Pattern
  3. Repository Design Pattern
  4. Builder Design Pattern
  5. Advanced Builder Design Pattern
  6. Observer Design Pattern
  7. Factory Design Pattern