Code Naming Conventions & Style Guidelines - HealthStart-Monstralia/Monstralia GitHub Wiki
To maintain consistency and good readability, please follow these naming conventions. Microsoft Visual Studio follows many of these so it is recommended that you use it.
There are guidelines listed after the naming conventions. You do not need to follow them, but it would make your code consistent with the rest of the game.
Disclaimer: Please note that older code in Monstralia might not follow the listed conventions.
Definitions
Pascal case: Also known as upper camel case. Capitalize first letter of each word.
- Example: UpperCamelCase
Camel case: Also known as lower camel case. First letter is not capitalized, afterwards capitalize first letter of each word.
- Example: lowerCamelCase
Avoid: To make things clear, avoid in this context means "avoid unless it makes more sense to not do so". It does NOT mean you cannot use it.
Naming Conventions
Variables
- camelCase
- Descriptive names
- No underscores unless prefixed (E.g. _myPrivateVariable)
- Avoid uncommon acronyms and abbreviations
- Avoid alphanumeric characters
Boolean variables
- Same as variables
- Prefix with yes/no question words (e.g. isPlaying, canSpawn, hasBall)
- Please avoid double negatives (e.g. !isNotLosing)
- Avoid contractions (e.g. isntCorrect)
Functions
- PascalCase
- Descriptive names
- No underscores unless prefixed
- Functions used exclusively for returning a value should be prefixed with Get (e.g. GetMoney() )
- Avoid alphanumeric characters
Classes
- PascalCase
- Descriptive name
- If possible, avoid underscores
- If exclusive to a specific game, please prefix with game name (e.g. BrainbowFood, EmotionsCard, BMazeMovement)
Constants
- UPPER_CASE (All letters capitalized with spaces as underscores)
- Descriptive name
- Defined in the Constants class
- Avoid uncommon acronyms and abbreviations if possible
- Avoid alphanumeric characters
Style Guidelines
These are guidelines, meaning while they're nice to follow for the sake of consistency, it's not required.
General guidelines
- Add Spacing with the assignment operator
public float dampTime = 0.1f;
- Avoid Hungarian notation
strMonsterNamemonsterName
intCountcount
Putting the type at the end is fine
monsterNameText (Text Component)
Comments
- // or /* is accepted
- Whenever possible, place comments above code.
/**
* \brief Tell the timer to start counting down
*/
public void StartTimer () {
timing = true;
}
Functions
- Opening curly brace on same line as function
- One-line statements are acceptable
SpawnMonster (DataType.MonsterType monsterType) {
// Code here
}
Spacing in arguments/parameters
- Space after commas
- Separate long arguments on newlines
transform.position = Vector3.SmoothDamp (transform.position, destination, ref velocity, dampTime);
transform.position = new Vector3 (
Mathf.Clamp (transform.position.x, xMinClamp, xMaxClamp),
0f,
-20f
);
IF/ELSE statements
- Opening curly brace on same line as statement
- Insert space between if and the statement
- One-line statements are acceptable
- Else statements can be on closing brace line or newline
// Singleton
if (instance == null) {
instance = this;
} else if (instance != this) {
Destroy (gameObject);
}
if (skipTutorial) GameManager.GetInstance ().CompleteTutorial (DataType.Minigame.Brainbow);
if (GameManager.GetInstance ().GetPendingTutorial(DataType.Minigame.Brainbow))
tutorialManager.StartTutorial ();
else
StartGame ();
Enums
- Organize it like a list
public enum Level {
LevelOne = 1,
LevelTwo = 2,
LevelThree = 3
}