Naming Conventions
Hello and welcome to the GDScript fundamental tutorial series.
In this episode, I go over naming conventions in Godot GDScript.
What are naming conventions?
Naming conventions are a set of rules for choosing the character sequence to be used for identifiers
which denote variables, functions, classes, and other entities in source code.
Beginner problems when naming variables
- Don’t spend enough time on naming conventions
- Using single character variables in a real project
- Afraid to use long names for variables
Examples of bad variable names
# variable name is a single character
var x = 100
# unsearchable name, the name has no meaning
var x1 = 100
# never include data types inside a name
var intHealth = 100
Improving variable names
# variable name is a single character
var x = 100
# better variable name
var playerHealth = 100
# even better variable name, explains intent
var playerHealth: int = 100
Consider a standard for variable names
Consider using the following:
- camelCase for variables:
var camelCase
.
- SNAKE_UPPERCASE for constants:
const SNAKE_UPPERCASE
- camelCase for functions:
func camelCase:
- PascalCase for classes:
class_name MainPlayer
Godot has an official naming convention-style guideline that you can follow as well: