CrocoDocs
CrocoDocs

Introduction

What is CrocoDocs?Season Breakdown

Getting Started

Programming in FTCJavaBlocksAndroid Studio

Control Systems

IntroductionJoystick MappingPID ControlMotion ProfilingKalman FilterLow-Pass Filter

Autonomous

IntroductionTime vs Encoder-Based MovementOdometryMotion PlanningPure PursuitSensor Fusion

Codebase Etiquette and Good Practices

IntroductionNaming ConventionsCode OrganizationComments and DocumentationTeam Collaboration

Libraries

LibrariesNextFTCPedro PathingFTC DashboardMercurialPanelsSloth

Sensors and Vision

Vision OverviewVision Basics

Introduction

Keep your code clean and collaborative

What is Code Etiquette?

Code etiquette refers to the conventions, patterns, and practices that make your robot code readable, maintainable, and team-friendly. Good code isn't just code that works—it's code that your teammates can understand, modify, and build upon.

In FTC, you're working on a team where multiple programmers may touch the same codebase throughout the season. Clean code practices ensure everyone can contribute effectively without confusion or conflicts.

Why It Matters

Poor code practices lead to:

  • Teammates unable to understand your code
  • Bugs introduced when modifying existing features
  • Wasted time debugging unclear logic
  • Merge conflicts and lost work
  • Difficulty onboarding new programmers

Good code practices enable:

  • Quick understanding of what code does
  • Safe modifications and feature additions
  • Efficient debugging and testing
  • Smooth collaboration across team members
  • Knowledge transfer to next season's team

Core Principles

1. Readability Over Cleverness

Write code that's easy to read, not code that shows off how smart you are.

Bad:

// What does this do?
double v = (e < 0 ? -1 : 1) * Math.min(Math.abs(e * 0.05), 1);

Good:

// Calculate motor power with proportional control
double error = targetPosition - currentPosition;
double power = error * KP;
power = Math.max(-1.0, Math.min(1.0, power)); // Clamp to [-1, 1]

2. Consistency Across Codebase

Pick conventions and stick to them throughout your entire project.

Bad (mixed styles):

public class robot_code {
    private DcMotor Left_Motor;
    private dcmotor rightmotor;
    private DcMotor ArmMotor;
}

Good (consistent):

public class RobotHardware {
    private DcMotor leftDrive;
    private DcMotor rightDrive;
    private DcMotor armMotor;
}

3. Clear Intent Through Names

Variable and function names should explain what they represent or do.

Bad:

double x = s.getDistance(DistanceUnit.INCH);
if (x < 10) m.setPower(0);

Good:

double distanceToWall = frontSensor.getDistance(DistanceUnit.INCH);
if (distanceToWall < 10) {
    driveMotor.setPower(0); // Stop before hitting wall
}

4. Modularity and Abstraction

Break complex operations into smaller, reusable functions.

Bad:

// 50 lines of drivetrain control in one method
public void teleopLoop() {
    double y = -gamepad1.left_stick_y;
    double x = gamepad1.left_stick_x;
    double rx = gamepad1.right_stick_x;
    // ... 40 more lines
}

Good:

public void teleopLoop() {
    updateDrivetrain();
    updateArm();
    updateIntake();
}

private void updateDrivetrain() {
    // Clean, focused logic for just drivetrain
}

What You'll Learn

This section covers practical guidelines for writing clean FTC code:

  1. Naming Conventions - How to name classes, methods, and variables
  2. Code Organization - Structuring your project and files
  3. Comments and Documentation - When and how to document your code
  4. Team Collaboration - Git, code reviews, and working together

Quick Tips

Do:

  • Use descriptive names (frontLeftMotor not m1)
  • Comment WHY, not WHAT
  • Keep functions short and focused
  • Test your code before committing
  • Ask for code reviews

Don't:

  • Copy-paste code without understanding it
  • Leave debug statements in production code
  • Use magic numbers (use named constants instead)
  • Commit broken code to main branch
  • Ignore compiler warnings

Next Steps

Start with Naming Conventions to learn how to choose clear, consistent names throughout your codebase.

Sensor Fusion

Combine multiple sensors for more accurate robot localization

Naming Conventions

Choose clear, consistent names for your code

On this page

What is Code Etiquette?Why It MattersCore Principles1. Readability Over Cleverness2. Consistency Across Codebase3. Clear Intent Through Names4. Modularity and AbstractionWhat You'll LearnQuick TipsNext Steps