Jakt is a memory-safe systems programming language created for SerenityOS. It combines Rust-like safety with C++-like ergonomics, featuring automatic reference counting, null safety, and modern type features.
Why Jakt Matters
Jakt was created by Andreas Kling (creator of SerenityOS and the Ladybird browser) as a language that's practical for systems programming without Rust's complexity. It transpiles to C++ for immediate compatibility.
What you get for free:
- Memory safety through automatic reference counting
- Null safety (no null pointer exceptions)
- Algebraic data types and pattern matching
- Transpiles to C++ (use existing C++ libraries)
- Familiar syntax for C++/TypeScript developers
- Built-in error handling with try/throw
- Strong, static typing with inference
Quick Start
# Clone and build
git clone https://github.com/SerenityOS/jakt
cd jakt
cmake -B build && cmake --build build
# Compile a Jakt program
./build/bin/jakt main.jakt
./build/main
The Basics
function main() {
let name = "Jakt"
println("Hello from {}!", name)
let x = 42
let y = x * 2
println("x = {}, y = {}", x, y)
// Type inference
mut counter = 0
while counter < 5 {
println("Count: {}", counter)
counter++
}
}
Classes and Methods
class Point {
x: f64
y: f64
function create(x: f64, y: f64) throws -> Point {
return Point(x, y)
}
function distance(this, other: Point) -> f64 {
let dx = .x - other.x
let dy = .y - other.y
return (dx * dx + dy * dy).sqrt()
}
function to_string(this) -> String {
return format("({}, {})", .x, .y)
}
}
function main() {
let a = Point::create(x: 0.0, y: 0.0)
let b = Point::create(x: 3.0, y: 4.0)
println("Distance: {}", a.distance(other: b)) // 5.0
}
Enums and Pattern Matching
enum Shape {
Circle(radius: f64)
Rectangle(width: f64, height: f64)
Triangle(a: f64, b: f64, c: f64)
}
function area(shape: Shape) -> f64 {
return match shape {
Circle(radius) => 3.14159 * radius * radius
Rectangle(width, height) => width * height
Triangle(a, b, c) => {
let s = (a + b + c) / 2.0
yield (s * (s - a) * (s - b) * (s - c)).sqrt()
}
}
}
function main() {
let shapes = [
Shape::Circle(radius: 5.0),
Shape::Rectangle(width: 3.0, height: 4.0),
]
for shape in shapes {
println("Area: {}", area(shape))
}
}
Optional Types (No Null)
function find_user(id: i64) -> String? {
if id == 1 {
return "Alice"
}
return None
}
function main() {
let user = find_user(id: 1)
// Must handle None explicitly
match user {
Some(name) => println("Found: {}", name)
None => println("User not found")
}
// Or use if-let
if let Some(name) = find_user(id: 1) {
println("User: {}", name)
}
}
Error Handling
enum AppError {
NotFound(String)
ValidationError(String)
}
function parse_age(input: String) throws -> i64 {
let age = input.to_int() ?? throw AppError::ValidationError("Not a number")
if age < 0 or age > 150 {
throw AppError::ValidationError("Age out of range")
}
return age
}
function main() {
try {
let age = parse_age(input: "25")
println("Age: {}", age)
} catch error {
println("Error: {}", error)
}
}
Generics
function find_max<T>(items: [T]) -> T? {
if items.is_empty() {
return None
}
mut max = items[0]
for item in items {
if item > max {
max = item
}
}
return max
}
Useful Links
- GitHub
- SerenityOS
- Ladybird Browser — built partially with Jakt
Building systems-level data tools? Check out my developer tools on Apify for ready-made web scrapers, or email spinov001@gmail.com for custom solutions.
Top comments (0)