Why Kode?

A language that reads like Python, feels like JavaScript and builds like C.

  • Python-readable

    Plain syntax. Variables need no keyword, strings interpolate with ${name}, and blocks use braces.

  • JavaScript-familiar

    Closures, optionals with ?. and ??, and try / catch feel like home. Static types catch the rest.

  • Small native binaries

    A hello world builds to about 450 KB, or 373 KB stripped. No VM and nothing to install on the server.

  • Written for agents

    Every error has a code and a hint, and diagnostics come as JSON, so an agent can fix its own code.

Read it once. Write it twice.

The first sample is from the README. More one-idea programs are in examples/, and the language fits on a one-page cheat sheet.

fib.kode
1fn fib(n: int) -> int {
2 if n < 2 {
3 return n
4 }
5 return fib(n - 1) + fib(n - 2)
6}
7
8name = "Asha"
9print("${name}: fib(30) =", fib(30))
output Asha: fib(30) = 832040

Fast where it counts

Time to compute fib(35), measured on one development machine: macOS arm64, Apple silicon.

Binary size: 450,696 bytes for hello world, 373,336 after strip -x. The numbers, targets and the rows that still miss are in benchmarks/report.md. HTTP benchmarks are still preliminary.

  • Python4,658 ms
  • Kode93 ms
  • C58 ms

Shorter is faster. Bars are to scale.

One compiler, written in Rust

Source goes through the lexer, parser, AST, type check and MIR, then Cranelift writes an object file and the linker makes the binary. Each stage is its own crate.

Run kode mir file.kode to see the MIR, including retain and release, and kode doctor to see the target, linker and runtime ABI.

  1. 1Lexer
  2. 2Parser
  3. 3AST
  4. 4Type check
  5. 5MIRretain and release included
  6. 6Craneliftwrites an object file
  7. 7Linkermakes the binary

What is in v0.3

A working compiler and an active standard library. Known gaps are tracked in docs/STATUS.md.

PostgreSQL, built in

A client in the runtime with SCRAM-SHA-256 authentication and JSON results. It speaks plain TCP today. TLS is planned in ADR 0033.

pg.connectpg.execpg.querypg.close

Worked example: examples/db/postgres.kode

Memory

Reference counted, with a leak checker. The test runner fails a program that leaks.

Language

int, float, bool, string. if, while, for, match. Named arguments, closures, generics, interfaces, classes and enums.

Data and errors

Lists, maps, optionals T?, and errors with throw, try / catch and expr catch e { }.

Concurrency and I/O

spawn and await, Channel<T>, a web server with Router, JSON, an HTTP client and files.

Tested the way you would want

test blocks live in the language, run by kode test.

tests/run-pass programs must run and are checked for leaks.

tests/compile-fail programs must fail with the right error code.

Built for the age of agents

Errors carry codes and hints, diagnostics come out as JSON, and a language server runs on stdio. An agent can write Kode and fix it from the compiler output.

Where Kode is going

See docs/ROADMAP.md and docs/PLAN-v1.md.

  1. Shipped

    v0.3

    Working compiler, standard library, PostgreSQL client, Linux x86-64 and macOS arm64 releases.

  2. Next

    M9 production track

    TLS, cycle-safe memory, byte buffers and enum payloads.

  3. Planned

    Windows

    Builds with the GNU toolchain today. Not a release target yet.

  4. Goal

    v1

    The plan is in docs/PLAN-v1.md.

Build Kode from source

Needs Rust 1.91 or newer and a C compiler. On macOS, run xcode-select --install first.

$ cargo build --workspace
$ cargo test --workspace
$ ./target/debug/kode run examples/hello.kode