Skip to the page

A language, its templates and a web framework

Code that agents write, and people can trust.

Hematite reads in plain words, and it's strict on purpose. Each thing has one obvious way to be written, mistakes are caught before the program runs, and every failure is dealt with right where it happens.

Ways to loop
1
way to loop
Ways to say nothing
1
way to say nothing
Hidden defaults
0
hidden defaults
hematite.hem
enum Status
  reading
  done
end

record Book
  title: String
  pages: Int
  status: Status
end

def label(book: Book): String
  const place = when book.status
    is Status.reading then "on the nightstand"
    is Status.done then "back on the shelf"
  end

  return "#{book.title}, #{book.pages} pages, #{place}"
end

const dune = new Book(title: "Dune", pages: 412, status: Status.reading)

print(label(dune))

Prints

Dune, 412 pages, on the nightstand
No. 01.hemHematite
The language
No. 02.ochOchre
Its templates
No. 03kilnKiln
Its web framework

1

One obvious way

No aliases and no shortcuts. Code reads the same, whoever (or whatever) wrote it.

2

Checked before it runs

Types, nil and every case of an enum are checked first, and each mistake comes with what to write instead.

3

Failures in the open

A method that can fail says so with !, and every call to it deals with that, using try or rescue.

4

Safe by default

Every page escapes its text, and no value ever becomes part of an SQL query.

Why it exists

Writing got cheap. Reading didn't.

Agents write more and more of our code, and people still have to trust it. Every rule in Hematite, Ochre and Kiln is there to make code quicker to read, and harder to misread.

The ideas behind it
01 Hematite.hem

The language

Records hold data and classes hold behaviour. An enum is handled in full, every time, and a method that can fail says so in its type. Programs run on a fast VM that turns their busiest code into native code as they run, and hem build makes a whole program into one executable.

Readable first
Logic in words, not symbols: and, or and not.
Nil, checked
A value that can be nil says so, as String?, and has to be checked before it's used.
Every message helps
A mistake is named, along with what to write instead. Messages are written for whoever, or whatever, fixes the code.
02 Ochre.och

Templates that can't be broken into

Pages written as Hematite, a line for each element, checked like any other code. A template says what it takes, escapes every value for the place it lands, and becomes a method that gives Html.

books.och
takes
  books: [String]
  reader: String
end

h2 "#{reader}'s shelf"

ul
  books.each do (title)
    li title
  end
end
ochre.hem
import "views/books.och" as shelf

print(shelf.render(books: ["Dune", "Emma <3"], reader: "Ada"))

Prints

<h2>Ada's shelf</h2><ul><li>Dune</li><li>Emma &lt;3</li></ul>
03 Kilnlode run kiln dev

The web framework

Routes are checked against their handlers, tables are the one truth about the database, and queries are written in Hematite, so they mean exactly what they say.

  • lode run kiln new makes an app, and lode run kiln dev runs it again on every change.
  • lode run database migrate brings the database in line with its tables, and loses data only when you say so.
kiln.hem
import "@kiln"

class Pages
  static def hello(request: Request, name: String): Response
    return Response.text("Hello, #{name}!", status: 200)
  end
end

const routes = [Route.get("/hello/:name", to: Pages.hello)]
const request = new Request(method: "GET", path: "/hello/Ada", query: "", headers: {}, body: "")

print(Pages.hello(request, name: "Ada").body)

Prints

Hello, Ada!

Benchmarks

Measured, side by side

The same programs in Hematite, Ruby and Python, and the same web app in Kiln, Rails and Django, with the CPU and memory each one took.

See the numbers
The languageTemplatesWeb apps