Reference

Programming languages

Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.

Scope and conventions

TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.

Control flow

Branch and exit early

Rust

Conditions must be bool. && evaluates its right side only when the left is true; || only when the left is false. Both return bool. There is no ternary operator; if/else is an expression. match arms use =>; patterns can bind values.

Fragment

Function; static string literals outlive the call.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
fn sign(n: i32) -> &'static str {
    if n == 0 {
        "zero"
    } else if n > 0 {
        "positive"
    } else {
        "negative"
    }
}

Loop over values

Rust

for…in consumes an iterable; 0..2 excludes 2. loop repeats until an exit. chars() visits Unicode scalar values; a byte slice visits bytes.

Fragment

Fragment inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
for name in ["north", "west"] {
    println!("{name}");
}

for i in 0..2 {
    let _ = i;
}

Select a case or match a pattern

Rust

match is an exhaustive expression with patterns and optional guards. _ is a catch-all pattern. if let handles one interesting pattern; it does not require all alternatives to be listed.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let mode = "read";
let label = match mode {
    "read" => "reader",
    "write" => "writer",
    _ => "other",
};

Repeat while a condition holds

Rust

while checks a bool condition; loop repeats indefinitely and can return a value with break expression. Labeled breaks can exit an outer loop. for/while do not provide the same arbitrary break-value facility.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let mut n = 3;

while n > 0 {
    n -= 1;
}

let answer = loop {
    break 24;
};