Syntax Basics, Comments and Formatting
as asm assert atomic break const continue defer else enum false fn for go goto if implements import in interface is isreftype lock match module mut none or pub return rlock select shared sizeof spawn static struct true type typeof union unsafe volatile __gl…
3.1 Program Structure
Statements end at a newline (no semicolons needed). Braces {} define blocks.
Tabs for indentation (enforced by v fmt). Identifiers are snake_case, types are PascalCase.
module main // optional for the main module
import os
import math { sqrt, pi } // selective import
const greeting = 'Hi'
fn main() {
println('${greeting}, ${sqrt(16)}')
}3.2 Comments
// single-line comment
/*
multi-line comment
/* nesting is supported */
*/
// Documentation comments go directly above the declaration:
// add returns the sum of a and b.
fn add(a int, b int) int {
return a + b
}3.3 Keywords
as asm assert atomic break const continue defer else enum false fn for go goto if implements import in interface is isreftype lock match module mut none or pub return rlock select shared sizeof spawn static struct true type typeof union unsafe volatile __global __offsetof
3.4 Naming Rules
Use snake_case for functions, variables, modules, and fields. Use PascalCase for types (structs, enums, interfaces, sum types).
No consecutive or leading underscores in public names. Keywords can't be used as identifiers (prefix with @: @type for C interop).
Unused variables produce warnings (errors with -prod). Unused imports also produce errors or warnings.
3.5 Formatting
v fmt -w . produces the canonical style (like gofmt). There are no options, which ends style debates.
v fmt -verify in CI fails if any code isn't formatted.