Hive
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
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.
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.
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.
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.
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.
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