Skip to content

Formatting

CamelCase

In object-oriented programming languages like Kotlin, CamelCase is used to help distinguish between types for readability. Everything that you write should follow this format.

class ExampleClass {} // PascalCase for classes
var exampleVariable = ExampleClass() // camelCase for variables
There is one exception to this rule: constants declared with const should use uppercase SCREAMING_SNAKE_CASE.
const val EXAMPLE_CONSTANT = 0.0

Whitespace

val foo = 5 * 3 / 2 + 1 // spaces between operators

class Dude(name: String, age: Int) // whitespace after colons
                // whitespace before and after classes or objects
val joe = Dude("Joe", 54)
val frank = Dude("Frank", 30) // whitespace after commas
val bartholomew = Dude("Bartholomew", 105)
                // whitespace between functions or variables of different types
val thomas = Guy("Thomas", 22)

if (true) // whitespace between conditional operators and opening parenthesis
while (true)
for (i in 0..1)

File Organization

Command-based programming makes it very easy to organize files into folders. This is what the general layout should look like:

src/main/
    deploy/   (this is where autonomous paths and files that the robot references should go)
    java/
        org.chillout1778/   (this can be just 'frc' if you want, but reverse domain names are nice)
            commands/
                TeleopDriveCommand.kt
            subsystems/
                Swerve.kt
                Subsystem.kt
            lib/   (optional, put libraries here that are not a part of vendordeps)
            Robot.kt
            Constants.kt
            Main.kt

Constants

Constants.kt contains all constant variables that may be changed to alter robot functionality. Generally, if a number is not a common mathematical constant (PI, e, 1, 0), this should be the only place where numeric literals exist in code.

object Constants{
    object IDs{ // IDs should be accessible in one spot
        const val EXAMPLE_MOTOR = 1
    }
    object ExampleSubsystem{ // Separate subsystems into their own subclasses of Constants
        const val EXAMPLE_MOTOR_GEAR_REDUCTION = 50.0
    }
}
Subsystems can now access the IDs by using Constants.IDs.EXAMPLE_MOTOR or the gear reduction using Constants.ExampleSubsystem.EXAMPLE_MOTOR_GEAR_REDUCTION.

Units

Rotational Measurements

Rotational measurements should ALWAYS be in radians; never store values in degrees. When creating a rotational variable, you may use Math.toRadians(degrees) to convert from degrees to radians.

Distance Measurements

Distance measurements should ALWAYS be in meters; never store values in inches or feet. When creating a distance variable, you may use Units.inchesToMeters(inches) or Units.feetToMeters(feet) to convert from imperial units to metric.