- 1. Git & GitHub Guidelines
- 2. Java Programming Guidelines
- 3. JavaFX Guidelines
- 4. UI Guidelines
- 5. External Libraries
- 6. Design Patterns
- 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.
- 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.
-
Fork and clone the repository.
-
Create a new branch based on
master
:git checkout -b my-branch-name
-
Make your changes, and make sure the app still runs and passes all the tests.
-
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.
-
After your pull request is merged:
-
Delete the branch you created from your GitHub fork by navigating near the bottom of your pull request and clicking
Delete branch
: -
Delete the branch you created from your local fork.
git checkout master git branch -d my-branch-name
-
Make your fork's
master
branch even withMonicaTanios:master
git remote add upstream https://github.com/MonicaTanios/octillect.git git pull upstream master git push origin master
-
Prepare for your next pull request.
-
Identifier | Case & Naming | Example |
---|---|---|
Package | lowercase | deepspace |
Class | UpperCamelCase | Character |
Method | lowerCamelCase | sendMessage |
Variable | lowerCamelCase | computedValues |
Parameter | lowerCamelCase | name |
Constant | CONSTANT_CASE | MIN_WIDTH |
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
Class and Interface declarations should be organized in the following manner:
- Class or Interface documentation, set inside the comment delimiters
/**...*/
. - Class or Interface statement.
- Static variables in the order public, protected, package (no access modifier), private.
- Instance variables in the order public, protected, package (no access modifier), private.
- Constructors.
- Getter and setters.
- 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);
}
}
Every variable declaration (field or local) declares only one variable.
int a; // good
int b;
int c, d; // bad
The square brackets form a part of the type, not the variable
String[] args; // good
String args[]; // bad
- 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
- 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;
Each line should contain at most one statement.
argv++; // good
argc--;
argv++; argc--; // bad
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);
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;
A try-catch statement should have the following format:
try {
statements;
} catch (ExceptionClass e) {
statements;
} finally {
statements;
}
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
}
A method is marked with the @Override
annotation whenever it is legal.
Exception: @Override
may be omitted when the parent method is @Deprecated
.
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
Use the following shortcuts in IntelliJ to help you optimize your code.
- Optimize Imports: Ctrl + Alt + O
- Reformat Code: Ctrl + Alt + L
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");
}
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() {
}
Java code has a column limit of 100 characters.
-
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:
-
A keyword followed by a parenthesis should be separated by a space. Example:
while (true) { statements; }
-
A blank space should appear before the opening parenthesis (
{
) of a method or a class.void doSomething() throw Exception {} class Bar extends Foo {}
-
A blank space should appear after commas in argument lists.
void doSomething(int x, int y) {}
-
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++;
-
The expressions in a for statement should be separated by blank spaces. Example:
for (expr1; expr2; expr3)
-
Casts should be followed by a blank space. Examples:
myMethod((byte) aNum, (Object) x); myMethod((int) (cp + 5), ((int) (i + 3)) + 1);
- Google Java Style Guide
- Oracle Code Conventions for the Java Programming Language
- Java Programming Style Guidelines
- Twitter Java Style Guide
- 47deg Java Style Guide
Use lowerCamelCase names with a type indication Suffix.
<TextField fx:id="emailTextField" />
Use handle
+ Element Name
+ Event Name
.
@FXML
protected void handleSubmitButtonAction(ActionEvent event) {
.
.
}
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) {
.
.
}
}
- 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>
- 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" />
- Order Attributes in the following logical order*:
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.
- AwesomeJavaFX
- XAML Coding Guidelines
- Introduction to FXML
- JavaFX CSS Reference Guide
- caspian.css
- modena.css
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.
The Material Design layout grid is made up of three elements:
- Columns
- Gutters
- Margins
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.
Cards should have 16dp padding.
Use the following colors:
Primary [light] | Primary | Primary [Dark] | Success | Info | Warning | Danger |
---|---|---|---|---|---|---|
#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 |