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.

Names & values

Declare, infer, reassign

Rust

let is immutable by default; mut allows assignment. A later let may shadow a name. const also requires a type and a constant expression.

Fragment

Fragment inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let label: &str = "north";
let mut count = 2;
count += 1;

Distinguish shadowing from assignment

Rust

let introduces a binding and can shadow a name in an inner block or the same scope, even with a different type. Reassigning an initialized binding requires mut and keeps its type. After an inner block, the outer binding is visible again.

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 count = 2;
let inner;

{
    let count = 5;
    inner = count;
}

let outer = count; // 2
let count = count.to_string(); // same-scope shadowing

Initialize values and defaults

Rust

Rust requires initialization before a value is read. Default is a trait convention, not an automatic zeroing rule for every type. derive(Default) works when every field supports it.

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+
#[derive(Default)]
struct Settings {
    retries: u32,
    active: bool,
}

let settings = Settings::default();

Compare values and object identity

Rust

== uses PartialEq, often derived for custom records. Collections can compare element values. Pointer identity is a separate question; == on references ordinarily compares the referred-to values.

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+
#[derive(PartialEq)]
struct Point {
    x: i32,
}

let same = Point { x: 2 } == Point { x: 2 };

Recognize copying and shared storage

Rust

Copy types duplicate implicitly. Assigning a non-Copy owned value usually moves it, making the old binding unusable. clone explicitly requests duplication according to the type’s Clone implementation; shared handles may still share data.

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 original = String::from("north");
let separate = original.clone();
let moved = original;

// original cannot be used after this move.