Skip to content

Your first program

A Brass file is a program. Statements at the top level run from top to bottom, so the smallest program is one line:

print("Hello, Brass")
Hello, Brass

Save it as hello.brass and run it:

Terminal window
brass run hello.brass # compile and run
brass build hello.brass -o hello --release # a native executable
brass check hello.brass # only check for errors
brass fmt hello.brass # format the file in place

Brass compiles to C, and the C compiler makes the executable. There is no runtime to install next to it and no garbage collector.

Brass has no comments. When code needs an explanation, write why in a because line right above it. The compiler keeps these lines, the documentation shows them, and they cannot drift away from the code they belong to the way a stray comment can.

let prices = [120, 80, 150]
let mut total = 0
for p in prices {
total += p
}
because shipping is free from 400 on
let shipping = if total >= 400 { 0 } else { 25 }
print(f"total {total + shipping}")
total 375

Unfinished work gets a date: todo(2027-01-31) handle refunds. After that day the compiler warns, and brass check --strict turns it into an error.

The next pages go through the language in order: values, control flow, functions, your own types, ownership, errors, collections, modules and tests, concurrency, and permissions. Each page is short and every example on it is compiled and run as part of Brass’s test suite.