Mach Systems Language Overview
Mach is a statically-typed, compiled systems programming language designed for developers who prioritize transparency and maintainability. Its core objective is to eliminate "hidden behavior," ensuring that the code written is exactly what the computer executes without implicit magic or automated abstractions.
Core Design Philosophy
Mach is built on the principle that computers are not magic and that programming languages should not promote that illusion. The language prioritizes long-term maintainability and simplicity over short-term developer convenience.
Prioritized Principles
- Explicitness: Mach is intentionally verbose. The design follows a "What You See Is What You Get" (WYSIWYG) approach, ensuring no behavior is hidden from the programmer.
- Simplicity: The language is designed to be easy to learn, read, write, and maintain.
- Maintainability: Semantics are chosen to ensure code remains manageable over long periods.
Non-Prioritized Principles
- Built-in Features: Mach does not include "batteries included" functionality; features are intentionally omitted from the core language.
- Flexibility: The language avoids providing multiple ways to achieve the same result to maintain consistency.
- Code Reduction: Verbosity is viewed as a meaningful trade-off for clarity; more code is not considered worse code.
- Automated Safety: Safety is treated as a programmer's decision rather than a restriction imposed by the language. Mach does not prevent the programmer from performing dangerous operations.
Technical Implementation and Tooling
Mach is a self-hosted compiler, meaning it is written in Mach and builds itself. It is developed without relying on LLVM or other external dependencies, a feat noted by the community as particularly impressive for a project of its scale.
Command-Line Interface (CLI)
Mach provides a unified toolchain via the mach command:
| Command | Description |
|---|---|
build |
Compiles the current project into an executable or object file |
run |
Builds and then executes the current project |
test |
Builds and runs project tests |
dep |
Manages vendored dependencies (list, add, remove, sync, vendor) |
init |
Scaffolds a new project |
doc |
Generates Markdown reference documentation from source doc-comments |
Language Syntax Examples
Mach's syntax is designed to be intuitive while remaining explicit. Below are examples of basic language constructs.
Hello World
use std.runtime;
use print: std.print;
$main.symbol = "main";
fun main(argc: i64, argv: **u8) i64 {
print.println("Hello, World!");
ret 0;
}
Recursive Fibonacci
use std.runtime;
use print: std.print;
fun fibr(n: u64) u64 {
if (n < 2) {
ret n;
}
ret fibr(n - 1) + fibr(n - 2);
}
$main.symbol = "main";
fun main(argc: i64, argv: **u8) i64 {
print.printf("fib(%d) = %d\n", 10::i64, fibr(10));
ret 0;
}
Community Discussion and Analysis
Following its introduction on Hacker News, the Mach language sparked discussion regarding its design trade-offs and performance.
Performance and Optimization
Community members observed that Mach is currently slower than C, with some noting it is approximately four times slower in certain benchmarks. This has led to questions regarding future plans for advanced optimization passes to improve execution speed.
Safety vs. Control
The language's stance on safety—leaving it to the developer—has drawn attention. While some users appreciate the "anti-magic" philosophy, others have questioned whether modern safety features, such as safe/unsafe code separation or algebraic types, could provide transparency without introducing hidden behavior.
Implementation Feats
Contributors and observers have praised the project for being fully self-hosted and avoiding external dependencies like LLVM, describing the work as "incredibly impressive" given the development timeline of two years.
"Quite impressive to develop so much without turning to LLVM. But it’s unclear to me from the docs the value prop of why developers would want to use Mach instead of Go or C."
Current State
Mach is an open-source project under the MIT License, with a macOS backend currently in development.