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:
- Naming Conventions - How to name classes, methods, and variables
- Code Organization - Structuring your project and files
- Comments and Documentation - When and how to document your code
- Team Collaboration - Git, code reviews, and working together
Quick Tips
Do:
- Use descriptive names (
frontLeftMotornotm1) - 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.