Code Style

Jitzu has a small set of naming rules. Following them keeps your code consistent with the standard library, built-in types, and .NET interop.

Naming Rules

ElementConventionCorrectWrong
Keywordslowercaselet, fun, typeLet, Fun
TypesPascalCasePerson, HttpClientperson, http_client
Union variantsPascalCaseOk(value), Circle(r)ok(value), circle(r)
TraitsPascalCaseGreet, Serializablegreet, serializable
Functionssnake_caseload_config()LoadConfig(), loadConfig()
Methods (impl)snake_caseget_name(self)GetName(self), getName(self)
.NET methodsPascalCasestr.ToUpper()str.to_upper()
Built-in functionslowercaseprint(), rand()Print(), Rand()
Variablessnake_casefirst_name, is_validFirstName, firstName
Parameterssnake_casemax_retries, user_idMaxRetries, userId
Fieldssnake_casepub name: Stringpub Name: String

Types, Traits, and Unions

All type-level declarations use PascalCase. This includes type, trait, union, and their variants.

Jitzu
type Person {
  pub name: String,
  pub age: Int,
  pub is_active: Bool,
}

trait Greet {
  fun greeting(self): String
}

union Shape {
  Circle(Double),
  Square(Double),
}

Functions and Methods

Both standalone functions and impl methods use snake_case.

Jitzu
// ✓ Functions are snake_case
fun factorial(n: Int): Int {
  if n <= 1 { 1 } else { n * factorial(n - 1) }
}

fun load_config(path: String): Result<Config, String> {
  let file = try read_file(path)
  Ok(try parse_json(file))
}
Jitzu
// ✓ Methods (with self) are also snake_case
impl Greet for Person {
  fun greeting(self): String {
      `Hello, {self.name}!`
  }
}

impl Drop for Connection {
  fun drop(self) {
      print("closed")
  }
}
Jitzu
// ✗ Don't do this
fun LoadConfig(): Config { }        // PascalCase function
fun loadConfig(): Config { }        // camelCase function

impl Greet for Person {
  fun Greeting(self): String { }   // PascalCase method
  fun getGreeting(self): String { } // camelCase method
}

.NET Methods

Since Jitzu runs on .NET, calling methods on .NET types uses their original PascalCase names. These are not Jitzu methods — they are CLR method calls.

Jitzu
// .NET string methods — PascalCase
let upper = name.ToUpper()
let trimmed = input.Trim()
let parts = line.Split(",")

// .NET static methods — PascalCase
let n = Int.Parse("42")
let exists = File.Exists("config.json")

Built-in Functions

The runtime provides a small set of lowercase global functions.

Jitzu
print("Hello, world!")
let n = rand(1, 100)
let head = first(items)
let tail = last(items)

Single-word builtins like print and rand are lowercase without underscores. Your own functions should use underscores for multi-word names (e.g. load_config).

Variables, Parameters, and Fields

All value-level names use snake_case. Boolean values typically use an is_, has_, or can_ prefix.

Jitzu
// ✓ Variables — snake_case
let first_name = "Alice"
let is_valid = true
let max_retries = 3
let mut request_count = 0

// ✓ Fields — snake_case
type UserProfile {
  pub display_name: String,
  pub email_address: String,
  pub is_verified: Bool,
  mut login_count: Int,
}

// ✓ Parameters — snake_case
fun send_email(to_address: String, subject: String): Result<Bool, String> {
  // ...
}
Jitzu
// ✗ Don't do this
let FirstName = "Alice"    // PascalCase variable
let firstName = "Alice"    // camelCase variable
let IsValid = true         // PascalCase variable

Formatting

Jitzu uses 4-space indentation. Opening braces go on the same line. Single-expression bodies can stay on one line.

Jitzu
// ✓ Braces on same line, 4-space indent
fun fibonacci(n: Int): Int {
  if n <= 1 {
      n
  } else {
      fibonacci(n - 1) + fibonacci(n - 2)
  }
}

// ✓ Short expressions can be one line
fun square(n: Int): Int { n * n }

// ✓ Match arms indented once
let label = match status {
  Ok(value) => `Success: {value}`,
  Err(e) => `Error: {e}`,
}

Quick Reference

When in doubt:

  • Defining a type? PascalCase: type HttpResponse { }
  • Defining a function? snake_case: fun parse_json()
  • Defining a method with self? snake_case: fun get_name(self)
  • Calling a .NET method? PascalCase: .ToUpper(), .Split()
  • Naming a variable? snake_case: let response_body = ...
  • Using a builtin? lowercase: print(), rand()