Maintainability over years

A codebase outlives the people who wrote it, so the question is not which language is pleasant today but what happens to this repository in three years: does it still compile, does the dependency still download, does the binary still start on the new machine. The two languages answer with different promises, and both promises are enforced by tools that can be run.

The version a module promises

A go.mod names the language version of the module, and the compiler enforces it: a feature from a later version is an error rather than a silent difference. The module below says 1.21 and uses range over an integer, which arrived in 1.22.

package main import "fmt" func main() { for i := range 3 { fmt.Println(i) } }

cat go.mod
go build -o old .

module example.com/old

go 1.21

# example.com/old
./main.go:6:17: cannot range over 3 (untyped int constant): requires go1.22 or later (-lang was set to go1.21; check go.mod)

The message names the version, the flag and the fix. Replace the loop with a three-clause one and the same module builds with go 1.26.10 without touching go.mod, which is the Go 1 compatibility promise: a program that compiles with one Go 1 release compiles with every later one, and the go directive decides which language rules apply, not which toolchain is installed.

The standard a project compiles with

C++ has the same idea with a flag and no enforcement file: the standard is chosen by -std= on every compile. The program below uses std::expected, which is C++23:

#include <charconv> #include <expected> #include <iostream> std::expected<int, int> parse(const char* text) { int value = 0; auto [ptr, ec] = std::from_chars(text, text + 3, value); if (ec != std::errc{}) { return std::unexpected(1); } return value; } int main() { if (auto result = parse("42")) { std::cout << *result << "\n"; } }

g++ -std=c++17 -O2 expected.cpp -o expected

expected.cpp:5:6: error: 'expected' in namespace 'std' does not name a template type
5 | std::expected<int, int> parse(const char* text)
| ^~~~~~~~
expected.cpp:5:1: note: 'std::expected' is only available from C++23 onwards

With -std=c++23 it builds and prints 42. The difference from Go is not the error, which is equally clear, but where the version lives: in a CMakeLists or a Makefile, or in a compiler flag a build script passes, and a translation unit compiled with another flag may still link. A C++ project that lasts has to write the standard down in its build files and keep every toolchain that builds it on the same page.

Dependencies years later

A Go module records the exact version of every dependency and a hash of its contents. The module below is one file and one import, which is all it takes to have a dependency:

package main import ( "fmt" "github.com/google/uuid" ) func main() { fmt.Println(uuid.Nil) }

go mod tidy added the requirement, and go mod verify checks the downloaded copy against the hashes in go.sum:

cat go.sum
go mod verify

github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
all modules verified

Three things follow. The version is fixed, so the build in three years resolves the same code. The hash is fixed, so a replaced or tampered module is refused. And the module proxy keeps every version it ever served, so the download still works after the upstream repository is deleted or rewritten. A project that must not depend on a proxy runs go mod vendor and commits the sources; the build then reads them from the repository.

C++ has no command in the language for this. A project pins its dependencies with a system package version, a git submodule, a vendored source tree, Conan, vcpkg or FetchContent with a commit hash, and each mechanism has its own way of being reproducible. The ones that record a hash are as safe as go.sum; the ones that say find_package(ZLIB REQUIRED) take whatever the machine has.

The binary and its libraries

The C++ hello world from the size page needs three shared libraries at run time. That list is baked into the binary:

0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libc.musl-x86_64.so.1]

The ABI of libstdc++ is stable enough that a binary built years ago usually runs on a newer system, which is a real achievement and the reason distributions can ship one C++ runtime. It is not a promise that a binary built against a newer library runs on an older system: the .so version is what the loader checks, and a symbol added in a later release is simply absent. The Go binary from the same page has no dynamic section at all, so the question does not arise, and the price is that Go cannot be the shared library on the other side of that boundary: plugins and C ABI libraries are possible, a Go .so with a stable ABI for other languages is not a design goal.

What is promised

Promise C++ Go
Source compatibility across versions Per standard; old code may need changes for a new one Go 1 promise, enforced by the go directive
Binary compatibility across versions libstdc++ ABI, mostly forward compatible Static binary, no ABI to keep
Dependency resolution The project's choice: package manager, submodule, vendoring go.mod, minimal version selection, go.sum
Reproducible download Only if the project arranged it Checksums by default, proxy keeps versions
Toolchain versions in one place The build files, or the CI image go.mod and the installed toolchain

The cost of the promise

The Go 1 promise is not free: it is why the language changes slowly, why generics arrived ten years after the first release only in a form that did not break anything, and why a proposal that would make old code invalid is rejected. A team that wants a language to keep up with its ideas finds that frustrating. A team that wants its 2019 service to build in 2026 finds it valuable, and both teams are right about their own project.

C++ moves faster in the standard and more slowly in the field, because a new standard takes years to reach every compiler and every platform a project supports. A C++ codebase can stay on C++17 for a decade, and large ones do. The question to ask about a new project is not which language has the better promise but which promise fits the lifetime of the code: a service rewritten every five years and a library used for twenty have different answers. The previous page of this group is onboarding; the last one is when Go instead of C++.

The C++ program was built with g++ 15.2.0 (Alpine 15.2.0), the Go programs with go 1.26.10 and the module github.com/google/uuid v1.6.0; all on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev