Skip to main content

Overview

This guide outlines the coding standards and conventions used in Minecraft Community Edition. Consistency is important for maintainability and collaboration.

General Principles

  • Readability: Code should be clear and self-documenting
  • Consistency: Follow existing patterns in the codebase
  • Maintainability: Write code that others can understand and modify
  • Performance: Consider performance implications, especially in hot paths

Naming Conventions

Classes and Structs

Class names use PascalCase:

Member Variables

Member variables use camelCase:

Static Members

Static members follow the same camelCase convention:

Constants

Constants use UPPER_SNAKE_CASE:

Methods and Functions

Method names use camelCase:

Namespaces

The project uses Java-style namespace organization through header file naming:

File Organization

Header Files

Header files follow this structure:

Source Files

Source files follow this structure:
Always include stdafx.h first in .cpp files for precompiled header support.

Code Formatting

Indentation

  • Use tabs (not spaces)
  • Tab width: 4 characters
  • Indent each level consistently

Braces

Use K&R style bracing (opening brace on same line):

Spacing

  • Space after keywords: if (condition), for (int i = 0; ...)
  • No space between function name and parentheses: doSomething()
  • Space around operators: a + b, x = y, i < count

Line Length

  • No strict limit, but prefer keeping lines reasonably short
  • Break long lines logically for readability

Comments and Documentation

Code Comments

Use comments to explain why, not what:

Team Comments

The codebase includes developer/team tags:
When making significant changes, consider adding your own tags to track modifications.

TODO Comments

Use TODO comments for future work:

C++ Standards

Pointers and References

  • Use pointers (*) for optional/nullable values
  • Use references (&) for required parameters
  • Prefer smart pointers where appropriate

Memory Management

  • Be explicit about ownership
  • Clean up resources properly
  • Use RAII patterns where appropriate
  • Be careful with manual new/delete

Type Usage

  • Use int for general integers
  • Use unsigned int for bit flags and sizes
  • Use float for game coordinates and math
  • Use wstring for text (wide strings)
  • Use bool for boolean values

Platform-Specific Code

When adding platform-specific code:

Best Practices

Avoid Magic Numbers

Use named constants:

Prefer Early Returns

Initialization

Initialize variables when declaring them:

Code Review Checklist

Before submitting code:
  • Follows naming conventions
  • Properly formatted (tabs, bracing, spacing)
  • Comments explain complex logic
  • No compiler warnings
  • Builds without errors
  • Consistent with surrounding code

Learning from the Codebase

The best way to understand the code style is to read existing code:
  • Minecraft.World/Tile.cpp - Good example of static initialization
  • Minecraft.World/Entity.cpp - Complex entity management patterns
  • Header files in net.minecraft.world.*.h - Project organization
When in doubt, look at how similar code is written elsewhere in the project and follow that pattern.