Skip to content

Coding Standards

Andrew Hernandez edited this page Jun 29, 2026 · 41 revisions

Naming Conventions

No numbers in names except for image files!
Variable and function names should be descriptive of their purpose. NEVER USE abbreviations or acronyms.

  • It’s alright to use basic variable names (“k”, “num”, etc) when they’re being used to iterate through in a for loop.
  • Foreach loops referring to objects should still be descriptive of their purpose/nature.
  • When strictly typing variables, format like the following: 'var myCoolvar : int = 5'

Variables:

  • Name: camelCase
var exampleVariable

Constants:

  • Name: ALL_CAPS
const EXAMPLE_CONSTANT

Enums:

  • Name: PascalCase
  • Members: ALL_CAPS
enum ExampleEnum {
    WALKING,
    IDLE,
    JUMPING
}

Functions (Includes Lambdas):

  • Name: snake_case
  • Parameters: camelCase
func example_function_name(var importantNumber):

Classes:

  • Name: PascalCase
class BaseEnemyClass

Files/Scenes/Scripts/Nodes:

  • Name: PascalCase
res://LevelFolder
TutorialLevel.tscn
PlayerScript.gd

Commenting

Always include a single space between the start of a comment and the first word, additionally always capitalize the first letter!
When writing particularly complex code that might be hard to follow, provide adequate description.

Variables:

  • 1 Hashtag
  • Appears above declaration
  • Related variables/comments grouped together for clarity, groups separated by spacing
# My cool variables
var myVariable: int
var myOtherVariable: bool = true

# My monetary variables
var dollars: int
var cents: int

# My unrelated variable
const MY_UNRELATED_VARIABLE = 42

Functions:

  • 2 Hashtags
  • Appears above function
  • Summary of the functions
  • Descriptions of the fields
  • Return value
  • Comments in code blocks where necessary describing complex sections
  • Include any references/resources used
## Adds two numbers together
## x: First number 
## y: Second number 
## Returns the sum of both numbers
## https://stackoverflow.com/questions
func add_numbers(x: int, y: int) -> int:
	# Adds both numbers together
	return x + y

Tags:

  • 1 Hashtag
  • Appears above related section
  • ALL CAPS no spaces
  • Use tags throughout code for actionable/notable items
# BUG: [Description of bug]
# TODO: [Description of work that still needs to be done]
# STRETCH: [Short description of stretch goal that would go here]
# WARNING: [Short description of potential problem]

Styling

  • ALWAYS USE SEMICOLONS TO END LINES;
  • Maintain proper indentation
  • Use double ampersand && and double vertical bars || for logic
  • Utilize white-space to help divide distinctive sections of code into blocks for increased readability. (Follow to best of ability, but wiggle room)
    • functions are separated by one line of whitespace below
    • loops, if/switch statements and code functionality of that nature is separated by an one line of whitespace above and below
    • One space before and after operators in equations/functions
    • One space after colon and before equals when typing variables
var myVariable : int = 3 + 5 * 10; 

func my_function() -> void:
    var myFloat: float = false;
    
    for number in range(myVariable):
        myFloat += 0.1;

    print(str(myFloat));

func my_other_function():
    # code continues below

Principles

  • DRY (Don’t Repeat Yourself)
    • If the same process is being repeated in several areas, turn it into a helper function.
  • Strict typing (ALWAYS)
  • Keep functions on the shorter side, if possible break them up when they get too long (> 40 lines as a rough number)
  • Composition > Inheritance
  • Focus on modularity
  • Any function that encounters an error condition should return 0 for debugging.
  • NEVER use “$NodeName” to get a reference to a node.
  • ALWAYS use @export to reference nodes in predictable places.
  • AVOID navigating the tree in code if not absolutely necessary.
  • NEVER optimize prematurely. BUT DON’T THROW CAUTION TO THE WIND.
  • Use scenes like prefabs wherever possible.

Clone this wiki locally