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.

Types & syntax

Read common type names

C++

int has implementation-defined width; double is floating point. std::string owns text; string_view borrows character storage, which must outlive the view. char[N] is a fixed-size array.

Fragment

Headers plus local fragments; name outlives view.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <string>
#include <string_view>

std::string name = "north";
std::string_view view = name;
char buffer[3]{};

Decode punctuation

C++

:: qualifies a name. T& is a reference; &value takes an address. const T& is a read-only access path, not a promise that no one can mutate T. << and >> are stream operators here.

Fragment

Function definition and literal examples.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <string>

void inspect(const std::string& text) {
    (void)text;
}
// Single quotes: 'x' (char)
// Double quotes: "north" (string literal)

Represent a missing value

C++

optional<T> contains a value or no value; an engaged optional holding 0 is still present. nullptr is a null pointer literal, not a general missing-value sentinel. Dereference an optional only when engaged.

Fragment

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

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <optional>

std::optional<int> score = 0;
if (score.has_value()) {
    int value = *score;
}
int fallback = score.value_or(10);

Define a record with named fields

C++

struct members default to public. A simple aggregate can initialize fields in declaration order with braces. const on the object prevents ordinary field mutation through it.

Fragment

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

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
struct Point {
    int x;
    int y;
};

Point point{2, 5};
point.y = 8;

Unpack multiple values

C++

tuple/pair group values; a structured binding introduces names for their elements. auto [a, b] copies here; auto& [a, b] binds to the original tuple’s elements.

Fragment

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

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <tuple>

std::tuple<const char*, int> item{"north", 24};
auto [name, count] = item;
auto& [originalName, originalCount] = item;

Name alternatives and tagged variants

C++

enum class names scoped constants. std::variant holds one alternative type at a time, including payloads; it is a different facility from an enum. Query or visit it before extracting the expected alternative.

Fragment

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

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <variant>
#include <string>

enum class Mode { Read, Write };
std::variant<int, std::string> reply = 24;

if (auto* value = std::get_if<int>(&reply)) {
    int count = *value;
}

Read a type parameter

C++

A template generates definitions for type arguments. Function calls can deduce T; explicit arguments use <T>. C++20 concepts/requires can constrain templates without a shared virtual base class.

Fragment

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

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
template <typename T>
T identity(T value) {
    return value;
}

auto count = identity<int>(24);
auto ratio = identity(1.5);

Recognize a behavioral contract

C++

An abstract base with pure virtual methods is one runtime-polymorphic contract. override verifies that a derived method overrides a base method. A virtual destructor permits safe deletion through this base.

Fragment

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

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
struct Named {
    virtual const char* name() const = 0;
    virtual ~Named() = default;
};

struct Place : Named {
    const char* name() const override {
        return "north";
    }
};

Check a type or request a conversion

C++

static_cast explicitly requests a permitted conversion, not a range check. Brace initialization rejects many narrowing conversions. dynamic_cast performs a checked down/cross-cast in a suitable polymorphic hierarchy.

Fragment

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

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
double ratio = 2.5;
int truncated = static_cast<int>(ratio);

// int rejected{ratio}; // narrowing: compile error