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.

Libraries: tools & testing

The toolchain around the code: building and packaging, testing, formatting and linting, debugging and profiling, and documentation.

Toolchain: node/npm/tsc, the go command, cargo, compilers + CMake

C++

C++ has no single official tool. A compiler (g++, clang++ or MSVC's cl) turns sources into binaries; -std selects the language version and -Wall -Wextra turn on warnings. Projects with more than one file use CMake, which generates build files and drives the compiler. Dependencies come from vcpkg, Conan, the system package manager or CMake's FetchContent, and clang-format and clang-tidy handle formatting and linting.

Fragment

Terminal commands, run from the project folder.

terminal
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
# Compile one file directly
clang++ -std=c++23 -Wall -Wextra -O2 main.cpp -o app
./app

# Projects: CMake generates the build, then drives the compiler
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
ctest --test-dir build              # run registered tests

clang-format -i main.cpp            # format
clang-tidy main.cpp -- -std=c++23   # lint

Most used: clang++/g++ -std=c++23 -Wall -Wextra, cmake -S . -B build, cmake --build build, ctest, clang-format -i, clang-tidy.

C++20 modules replace headers with import; C++23 adds import std; for the whole standard library. Support depends on the compiler and build system together: CMake 4.5 (a release candidate as of November 2026) makes import std a supported feature with the Ninja generators for Clang 18.1.2+ (libc++ or libstdc++), MSVC 14.36+ and GCC 15+ (16+ on macOS); CMake 3.30 to 4.4 offer it only behind the CMAKE_EXPERIMENTAL_CXX_IMPORT_STD gate. Most code still uses #include.

Code generators such as protoc run as CMake custom commands (add_custom_command) whose outputs are listed as target sources, so the build regenerates them when their inputs change.

Testing: node:test, testing, #[test], GoogleTest

C++

The C++ standard has no test framework. GoogleTest is the most widely used: TEST macros define cases, EXPECT_* records a failure and continues, ASSERT_* stops the test, and linking gtest_main supplies main(). Catch2 and doctest are lighter alternatives, and CMake's CTest runs the resulting test executables.

Complete file

A test file.

Before you use this

Not in the standard library: GoogleTest from vcpkg, Conan or CMake FetchContent, linked to GTest::gtest_main.

total_test.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
// total_test.cpp, built with CMake and linked to GTest::gtest_main
#include <gtest/gtest.h>
#include <numeric>
#include <vector>

int total(const std::vector<int>& prices) {
    return std::accumulate(prices.begin(), prices.end(), 0);
}

TEST(TotalTest, AddsPrices) {
    EXPECT_EQ(total({40, 15}), 55);
}

TEST(TotalTest, EmptyIsZero) {
    EXPECT_EQ(total({}), 0);
}

Most used: TEST, TEST_F with fixtures, EXPECT_EQ, EXPECT_TRUE, ASSERT_EQ, EXPECT_THROW, gtest_discover_tests in CMake, ctest.

Formatting & linting: Prettier/ESLint, gofmt/vet, rustfmt/Clippy, clang-format/tidy

C++

C++ formatting is usually clang-format with a checked-in .clang-format file based on a style such as LLVM or Google. clang-tidy runs lint checks (bugprone-*, modernize-*, performance-*) with the exact compiler flags from compile_commands.json, which CMake writes when CMAKE_EXPORT_COMPILE_COMMANDS is on. Compiler warnings (-Wall -Wextra -Werror) and cppcheck add further checks.

Fragment

Terminal commands, run from the project folder.

terminal
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
clang-format -i src/*.cpp                    # format using .clang-format
clang-format --dry-run --Werror src/*.cpp    # fail if anything would change (CI)
cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON   # writes compile_commands.json
clang-tidy -p build src/main.cpp             # lint with the real compiler flags
cppcheck --enable=warning,performance src/   # a second, independent analyzer

Most used: clang-format -i, .clang-format, clang-tidy -p build, .clang-tidy, CMAKE_EXPORT_COMPILE_COMMANDS, -Wall -Wextra -Werror, cppcheck.

Debugging & profiling tools: inspector, Delve + pprof, LLDB + flamegraph, sanitizers

C++

C++ debugging uses GDB or LLDB, directly or through an IDE, on a build compiled with -g. The sanitizers built into Clang and GCC are the most effective bug finders: AddressSanitizer (memory errors), UndefinedBehaviorSanitizer and ThreadSanitizer (data races). Valgrind checks memory on Linux. For performance, perf (Linux), Instruments (macOS) and VTune profile CPU time, and Google Benchmark measures small pieces of code.

Fragment

Terminal commands, run from the project folder.

terminal
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
clang++ -std=c++23 -g -O0 main.cpp -o app                     # debug symbols, no optimization
lldb ./app                                                    # or gdb ./app: break, run, bt, print
clang++ -std=c++23 -g -fsanitize=address,undefined main.cpp -o app   # memory errors and UB
clang++ -std=c++23 -g -fsanitize=thread main.cpp -o app       # data races
valgrind --leak-check=full ./app                              # Linux: leaks and invalid reads
perf record -g ./app && perf report                           # Linux: CPU profile

Most used: -g, gdb or lldb (break, run, bt, print, frame), -fsanitize=address,undefined, -fsanitize=thread, valgrind, perf record, Instruments, Google Benchmark.

Documentation tools: TSDoc/TypeDoc, go doc, rustdoc, Doxygen

C++

C++ has no built-in documentation tool. Doxygen is the long-standing standard: it reads /** ... */ or /// comments with commands such as @brief, @param and @return and generates HTML (and diagrams) using a Doxyfile. Sphinx with Breathe or Exhale turns Doxygen's XML into Sphinx documentation, and clangd shows the same comments on hover in editors.

Complete program

Complete program. Standard library: ships with your compiler, no install.

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

/**
 * @brief Adds tax to a price in cents.
 *
 * @param cents Price before tax, in cents.
 * @param rate  Tax rate as a fraction, for example 0.2 for 20%.
 * @return The price including tax, rounded to whole cents.
 */
long with_tax(long cents, double rate) {
    return std::lround(cents * (1.0 + rate));
}

int main() {
    std::println("{}", with_tax(1000, 0.2));
}

Most used: /** ... */, ///, @brief, @param, @return, @throws, @code ... @endcode, doxygen -g Doxyfile, doxygen Doxyfile.