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

C++

Types precede names. auto deduces a type; it does not imply const. const prevents modification through this object.

Fragment

Fragment inside a function.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const int limit = 8;
auto count = 2;
count += 1;

Distinguish shadowing from assignment

C++

A declaration in a nested block can hide an outer local name. Assignment uses the name visible at that point. Leaving the nested block makes the outer binding visible again; an ordinary local cannot be redeclared in the same scope.

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+
int count = 2;
int inner = 0;

{
    int count = 5;
    inner = count;
}

const int outer = count; // 2

Initialize values and defaults

C++

Local scalar declarations without initialization can leave unusable values. Empty braces value-initialize simple scalar objects; class initialization follows its constructors/member defaults. Prefer explicit initialization.

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+
int count{};       // 0
bool active{};     // false
double ratio{1.5};

// int uninitialized; // do not read before assigning

Compare values and object identity

C++

Standard containers and strings compare contents. Raw pointers compare addresses, including pointers to string literals. A custom record can define or default operator== (defaulted comparison is C++20).

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;
    bool operator==(const Point&) const = default;
};

bool same = Point{2} == Point{2};

Recognize copying and shared storage

C++

Copying vector/string values normally duplicates their owned elements. Copying pointers or shared_ptr shares access/ownership instead. std::move permits move overload selection; it is a cast and does not itself transfer storage.

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 <vector>
#include <utility>

std::vector<int> original{2, 5};
auto separate = original;
auto moved = std::move(original);

// Do not assume original retains its old contents.