Design Rationale
Why Braid Was Created
Braid was created to unify language research across three domains that historically require separate tools: systems programming (C/Rust), ML/AI (Python/PyTorch), and web development (JavaScript/TypeScript). No existing language bridges all three with a single syntax, memory model, and compilation pipeline. Braid targets this gap with a unified toolchain — one language for writing kernels, training models, and serving web applications.
Design Decisions
ARC over GC
Chosen: Automatic Reference Counting (ARC) with cycle detection. Alternatives considered: Tracing GC (Java, Go), manual memory management (C), ownership/borrowing (Rust). ARC provides deterministic destruction without stop-the-world pauses, critical for real-time ML inference and web serving. Cycle detection handles reference cycles that pure RC cannot. Compared to Rust's borrow checker, ARC imposes lower cognitive overhead while still providing memory safety.
Diameter over Probabilistic
Chosen: Deterministic dialectical reasoning via Diameter construct. Alternatives considered: Bayesian inference, Monte Carlo methods, fuzzy logic. The Diameter construct provides a deterministic, composable primitive for modeling opposing forces — unlike probabilistic approaches, its behavior is reproducible and debuggable. This makes it suitable for simulation, game AI, and dialectical ML training where deterministic tension modeling is required.
DTS over Relational
Chosen: Distinction Trees (DTS) for multi-dimensional branching. Alternatives considered: SQL-based relational queries, pattern matching (ML/Haskell). DTS provides a tree-structured distinction system that integrates natively with Braid's type system and tensor operations, avoiding the impedance mismatch between query languages and host languages. DTS enables compile-time optimization of branching logic across multiple dimensions.
Brace Syntax over Indentation
Chosen: C-style braces {} and semicolons. Alternatives considered: Python indentation, ML-style syntax, Lisp s-expressions. Braces provide unambiguous block structure, simplify tooling (no significant whitespace), and are familiar to C/Java/TypeScript developers. Semicolons enable the parser to recover from errors more gracefully. The Python-like keywords and conventions are preserved for readability.
Comparison of Alternatives Considered
| Feature | Chosen | Alternatives | Why |
|---|---|---|---|
| Memory | ARC + cycle detection | GC, borrow checker | Deterministic, no pauses |
| Dialectics | Diameter | Bayesian, Monte Carlo | Deterministic, composable |
| Branching | DTS | SQL, pattern matching | Native integration, compile-time opt |
| Syntax | Braces + semicolons | Indentation, ML, s-exp | Unambiguous, familiar |
| Typing | Hindley-Milner inference | Gradual, dynamic | Safety + inference |
| Codegen | C codegen + LLVM | Direct machine code | Portability, leveraging GCC |
| Tensors | Native [[ ]] syntax | Library types, macros | First-class in grammar + compiler |