Rodrigo
Heinzen de Moraes

Software engineer

Seven years building web applications and distributed systems. Lately I’ve been drawn to language design: type systems, compilers, and making concurrency something you can reason about.

Hive

A compiled language for distributed systems, in which what would crash does not compile.

Hive is my main project: a small language I designed and built. There is no null, nothing is thrown, and every index is proved in range before the program runs. It compiles to Go and ships as a single native executable. It is young — not yet 1.0 — and its tour covers the whole language in 74 short slides.

  • No crashes in production No null, no exceptions, no out-of-range index: what would crash elsewhere does not compile.
  • One process or many machines Services keep their state behind a mailbox, so nothing needs a lock, and calling one across the network looks exactly like calling one locally.
  • Runs everywhere The same code on Windows, Linux, macOS, the browser, a container and Android.
Example program

Every index is proved in range before the program runs · tour, slide 18

Index the last element with
proc main(): void {
	v := ["a", "b", "c"]
	echo v[len(v) - 1]
}
proc main(): void {
	v := ["a", "b", "c"]
	last := len(v) - 1
	if v bounds last {
		echo v[last]
	}
}
$ hive check guard.hive

Refused at compile time

guard.hive:1: in `main`: cannot prove this index is in range: it is a computed expression, and there is nothing to hang a guard on. Bind it to a name first, then guard that
$ hive run guard.hive

Compiles: the guard proves the index

c

A JWT is a codec: sign a value of your own type, and check it before reading it back · tour, slide 60

type Claims { user: Str }
proc main(): void {
	if hide(hive.crypto.randomHex(32)) is Result.Ok(key) {
		jwt := hive.crypto.jwtCodec(key)
		token := encode(Claims("ada"), jwt)
		// Checks the signature and the times, then reads the claims.
		if Claims.decode(token, jwt) is Result.Ok(claims) {
			echo claims.user
		}
	}
}
$ hive run token.hive

Signed, checked and read back

ada

“Only HS256 is accepted, which closes the classic algorithm-confusion attack outright.” (slide 60)

A service handles one message at a time, here or on another machine · tour, slides 38 and 59

type Note {
	Say   { text: Str }
	Heard { count: Int }
}
// 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
	}
	spawn(inbox, 0, #Inbox)
	there := at("10.0.0.2:9100", #Inbox)   // on another machine
	echo there(Note.Say("hi"))
}

Run it on both machines

On the second one, swap the two addresses. A node is identified by where it can be reached, so nothing else about the two processes differs.

Calling the service over there is the same line as calling one here, and messages between two nodes arrive in the order they were sent. “Every connection between two nodes is TLS 1.3, mutually authenticated” (slide 59).

An interface is a value: a tree of widgets, served as a page or shown in a window · tour, slides 64 and 65

proc main(): void {
	view := hive.ui.column([hive.ui.pad(24), hive.ui.gap(12)], [
		hive.ui.text([hive.ui.heading(1)], "Hive Tour"),
		hive.ui.row([hive.ui.gap(8)], [
			hive.ui.input([hive.ui.placeholder("your name")], ""),
			hive.ui.button([hive.ui.tone(hive.ui.Tone.Good())], "Say hi"),
		]),
	])
	// a whole document, served directly
	body := hive.ui.page("Hive", view)
	echo len(body)
}

Roughly how hive.ui draws it

“Because a view is a value, an interface is testable without a browser” (slide 64).

Four small programs adapted from the Hive tour. The first comes in a form the compiler refuses and a form it accepts; its message is hive check’s own, quoted from slide 70.

The sky above

Six Tupi-Guarani constellations are drawn in this page’s sky. They were recorded among the Tupinambá by Claude d’Abbeville in 1614 and mapped again by the astronomer Germano Afonso with Guarani communities. Sweep across the stars to light them, or pick one below.