Naming Rules and Conventions

Rules

  • Names can contain letters, digits and underscores, but cannot start with a digit.
  • Names are case-sensitive: total and Total are different.
  • Hard keywords (val, fun, if, class, when...) cannot be used as names.

Conventions

WhatStyleExample
Variables and functionscamelCasecartTotal, getUserName()
ClassesPascalCaseOrderSummary
ConstantsUPPER_SNAKE_CASEMAX_RETRY
Packageslowercasecom.careeroza.app

Example

Good names make code read like a sentence.

fun main() {
    val deliveryPartnerName = "Ramesh"
    val etaMinutes = 12
    val isOrderPicked = true
    println("$deliveryPartnerName picked the order: $isOrderPicked, ETA $etaMinutes min")
}

Output

Ramesh picked the order: true, ETA 12 min