Skip to content
Kavachकवच

Syntax: Names

● Beginner3 min

Names are made of letters, digits and _, in snake_case for values and PascalCase for types.

type OrderStatus = Pending | Paid

fn main() {
    const total_price = 499
    const नाम = "Asha"
    const status = OrderStatus.Paid
    print("{नाम} owes {total_price}: {status}")
}

The program ran and printed:

kavach run names.kav

Asha owes 499: Paid
names.kav: Kavach code, then what running it prints
  • snake_case for variables, functions and modules: total_price.
  • PascalCase for types and their variants: OrderStatus, Paid.
  • Letters from any script work: नाम is a fine name. A name can't start with a digit.

The compiler enforces the style, and says exactly what to write:

fn main() {
    const totalPrice = 499
    print(totalPrice)
}

The compiler refused the program:

kavach run names-style.kav

error: variables use snake_case: write `total_price`
names-style.kav: Kavach code, then what running it prints

You rarely see this error: kavach fmt renames the name and every use of it for you.

What Kavach does for you

  • One naming style, fixed by the formatter

    kavach fmt renames a badly styled name and every use of it, so every codebase reads the same.

    spec 1.5

  • Look-alike names are flagged

    A name mixing letters from two scripts (a Latin a and a Cyrillic а) gets a warning, so hidden look-alikes can't sneak in.

    spec 1.5