The Hive logo: a bee on a honeycomb

Hive

A compiled language with no runtime exceptions and laws the compiler proves, built for distributed systems, that runs anywhere and is small enough to learn in a day.In Hive, the mistakes other languages leave for production are compile errors: there is no null, nothing is thrown, and every index is checked. You can also write laws about your code, your types and your tables, and the compiler proves them for every possible value. HTTP, SQL, JSON, cryptography, a UI and services across machines come with the language, and the same code runs on Windows, Linux, macOS, the browser and Android.
A complete web service with shared state
type Tick {
	Hit
	Seen { count: Int }
}

// One message at a time, so the count needs no lock.
proc counter(count: mut Int, tick: Tick): Tick {
	count += 1
	return Tick.Seen(count)
}

proc handle(req: hive.net.HttpRequest): hive.net.HttpResponse {
	plain := [["Content-Type", "text/plain"]]
	Address<Tick> service = at(#Hits)
	// Asking a service answers a Result: it may be down.
	if service(Tick.Hit()) is Result.Ok(Tick.Seen(n)) {
		return hive.net.HttpResponse(200, plain, "visitor {n}\n")
	}
	return hive.net.HttpResponse(503, plain, "try again\n")
}

proc main(): void {
	if spawn(counter, 0, #Hits) is Result.Error(err) {
		panic err
	}
	hive.net.httpServe(8080, handle)
}

Why pick Hive

No crashes in productionNo null, no exceptions, no out-of-range index: what would crash elsewhere does not compile.
Runs everywhereThe same code on Windows, Linux, macOS, the browser, a container and Android.
One process or many machinesCalling a service across the network looks exactly like calling one locally.
Secure defaultsEncrypted links between machines, injection-proof SQL, and secrets that never reach a log.
Batteries includedHTTP, SQL, JSON, cryptography and a UI library come with the language.
Productive in a dayA small language. This tour covers all of it, one feature at a time.

Is Hive right for your next project?

A good fit for

Web APIs and backend services

HTTP, SQL and JSON are in the standard library.

Systems spread across machines

Distribution is part of the language, not a framework bolted on.

Software that has to run everywhere

One codebase for the desktop, the server, the browser and the phone.

Command-line and internal tools

One file to hand out, and no runtime to install.

Teams that want no surprises in production

What would have been a crash at 3 a.m. is a compile error instead.

Think twice if

You need long-term stability today

Hive is young — not yet 1.0 — and still changes from one release to the next.

You rely on deep editor integration

There is no language server yet. Errors come as file:line, which any editor can jump to.

You need manual control of memory

Hive is garbage-collected, like the Go it compiles to.

What would crash does not compile

Null references, uncaught exceptions and out-of-range indexes are among the most common causes of crashes in production, and in Hive none of them can happen. Anything that can fail returns a Result, and the compiler makes you check it before you touch the value inside. An index it cannot prove safe is a compile error, and the error says how to fix it. Even a division by zero is a value, not a crash.

The mistakes that would have shown up in production show up while you are still writing the code.

A lookup that can come back empty
type User {
	name:  Str
	email: Str
}

func find(users: User[], name: Str): Result<User, Str> {
	for each user in users {
		if user.name == name {
			return Result.Ok(user)
		}
	}
	return Result.Error("nobody called {name}")
}

proc main(): void {
	users := [User("ada", "[email protected]")]

	if find(users, "ada") is Result.Ok(user) {
		echo user.email          // [email protected]
	}
	if find(users, "alan") is Result.Error(why) {
		echo why                 // nobody called alan
	}
	// echo find(users, "ada").email  — refused: not a User
}

One codebase, every platform

The same Hive code runs on Windows, Linux and macOS, in the browser through WebAssembly, in a container, and on Android. Choosing a platform is a flag on the build, not a port of the program — no separate toolchain, and no C compiler to install. On the desktop and the server, a build is a single native executable with no runtime to ship beside it.

Interfaces travel too. A hive.ui view is drawn as a desktop window, served as a web page, or packaged as an Android app — the same view, unchanged.

The same app.hive, in six places
Windowshive build app.hive --target windows/amd64
Linuxhive build app.hive --target linux/arm64
macOShive build app.hive --target darwin/arm64
Browserhive build app.hive --target js/wasm
Containerhive container app.hive
Androidhive export app.hive --target android/arm64

Start as one process, grow to many machines

Concurrency in Hive is built around services: a piece of state that handles one message at a time, so there are no locks to get wrong. Calling a service on another machine is the same line of code as calling one in the same process, over connections that are encrypted and authenticated for you.

A system can start as a single executable and be spread across machines later, without being rewritten around a message queue or an RPC framework.

The same service, here and on another machine
type Note {
	Say   { text: Str }
	Heard { count: Int }
}

// Handles one message at a time: no lock, wherever it runs.
proc inbox(count: mut Int, note: Note): Note {
	count += 1
	return Note.Heard(count)
}

proc main(): void {
	if hive.syslink.listen("10.0.0.1:9100") is Result.Error(e) {
		panic e
	}
	if spawn(inbox, 0, #Inbox) is Result.Error(e) {
		panic e
	}

	Address<Note> here = at(#Inbox)                     // on this machine
	Address<Note> there = at("10.0.0.2:9100", #Inbox)   // on another one

	// The same call either way. The second one crosses the
	// network, encrypted and authenticated.
	echo here(Note.Say("hi"))
	echo there(Note.Say("hi"))
}

Less to install, less to audit

The standard library covers what most services need, so a project starts with no dependencies and tends to stay with few. Its defaults are the safe ones: SQL values are always sent as parameters, secrets cannot end up in a log by accident, and machines only talk to each other over TLS.

When you do need a package, it is imported straight from its git repository and pinned to a commit — there is no registry in between. And a Go file can be imported directly, bringing the whole Go ecosystem with it.

In the standard library
hive.netHTTP, WebSockets and TCP
hive.sqlSQLite and PostgreSQL
hive.jsonJSON, shaped by your types
hive.cryptoHashing, encryption and JWTs
hive.syslinkServices across machines
hive.uiDesktop, web and Android interfaces
hive.ui.scene3D scenes and sound
hive.fileFiles and folders
hive.termThe terminal and other programs
hive.timeDates, times and time zones
hive.envConfiguration from the environment
hive.mapDictionaries

One tool, from the first line to production

The hive command checks, runs, tests and builds, and the only other thing it needs is Go. Tests are part of the language and every run reports coverage, so there is no test framework to choose.

hive analyze points out code that will be expensive to run before it ever runs, and every error the compiler reports names the problem and says how to fix it.

The hive command
hive checkFind every error, build nothing
hive runCompile and run in one step
hive testRun the tests, with coverage
hive analyzeSpot expensive code before it runs
hive buildA native executable, or WebAssembly

This site is a Hive program

Every page here is served by an HTTP server written in Hive and laid out with Hive's own UI library — no web framework, and no JavaScript but the one script that runs the tour's examples in your browser. The whole site is one executable, deployed in a container.

85 short slides, and you know the language

Every example is a complete program you can copy and run. Start at the beginning, or go straight to what you need from the contents.

Getting started

Control flow and functions

Vectors, bounds and tables

Types, patterns and values

Modules, tests and laws

Threads and services

The standard library

Windows, canvases and scenes

Tools

  • Getting started
  • Control flow and functions
  • Vectors, bounds and tables
  • Types, patterns and values
  • Modules, tests and laws
  • Threads and services
  • The standard library
  • Windows, canvases and scenes
  • Tools