envzn
0.8 · beta · not released

What Makes Envzn Different

Four unusual design choices, and eleven trouble spots it closes

Most of what a systems language does is settled practice, and Envzn follows it. This page covers the rest: places where Envzn made a choice few other languages have made, and places where a familiar language lets a defect through silently and Envzn refuses it. Every example below is checked by the documentation build. A block marked as failing must fail to compile with the error shown, so a claim here cannot drift from the compiler without the build noticing.

The features that make Envzn safe and exact by default (memory safety, checked overflow, no casts, diagnostics that cite the Constitution, numbers for money and data, N-D arrays, calling C) have their own page: Features of Envzn.

Part 1: Design choices that are unusual

1. Leak-freedom proven at compile time. Every object is owned, and the graph of owning and counted references must contain no cycle, so a leak is a compile error (E3033). Swift's ARC and Rust's Rc leak a cycle silently (I.I.i(b.i)).


2. Parameter modes spelled as words. A plain parameter owns its argument, REFERENCE reads it, and MUTABLE REFERENCE writes it, exclusively (I.I.vi). The same three meanings are sigils in Rust and drift between &, const& and && in C++.


3. Bounds-check removal you ask for, and that is proven. HOTLOOP asks the compiler to replace a loop's per-element bounds checks with one check up front. If it cannot prove that one check covers every access, the build fails (E5027) rather than run unchecked (I.H.iii(f)).


4. Three assignment operators, one per meaning. = copies a value, := takes ownership (constructing, cloning or moving), and =@ binds a reference. A move is visible at the point it happens (I.F).

Part 2: Trouble spots other languages leave open

(a) Shifting by the width of the type or more

Where it bites: C and C++, where the result is undefined. Envzn: a shift count must lie in [0, width), and a constant that breaks the rule is a compile error (I.F.ii(c.iv)).

int32 a = 5
int32 b = a LSHIFT 40

(b) Bitwise operators that bind looser than comparison

Where it bites: C, C++, Java and JavaScript, where x & mask == 0 means x & (mask == 0). Envzn: mixing a bitwise operator with a comparison requires parentheses.

int64 x = 6
int64 mask = 4
IF x BAND mask == 0 THEN { printline("clear") }

(c) A leading zero that silently means octal

Where it bites: C, C++ and Java, where 0755 is 493. Envzn: octal literals are refused; write decimal, 0x or 0b (I.C(e)).

int32 mode = 0755

(d) == on strings comparing references

Where it bites: Java, and C's char*, where two equal strings can compare unequal. Envzn: == on a String is a compile error; content equality is ->equals() (I.F.ii(c.i)).

String a = "hello"
String b := a->clone()
IF a == b THEN { printline("same") }

(e) Null dereference

Where it bites: C, C++, Java, Go and C#. Envzn: there is no null. A class-typed value may be EMPTY, and the compiler refuses any use it cannot prove is present; IF w IS VALID is the proof (I.D.iv).

MODULE nullExample

CLASS Widget {
    PRIVATE int32 id
    INIT(int32 i) { .id = i }
    METHOD ident() RETURNS int32 { RETURN (.id) }
}

CLASS Main IMPLEMENTS TaskStarter {
    METHOD start() RETURNS STATUS {
        Widget w = EMPTY
        printline(("id $1")->format(w->ident()))
        RETURN (SUCCESS)
    }
}

(f) Numbers used as truth values

Where it bites: C, C++, Python and JavaScript, where if (count) and if (ptr) hide a comparison. Envzn: a condition must be a boolean (I.D.i(b.iii)).

int64 count = 3
IF count THEN { printline("some") }

(g) Changing a collection while iterating over it

Where it bites: C++, where it is undefined behaviour, and Java, where it throws at run time. Envzn: a live loop or view locks its source against change, at compile time (I.D.vi(d.ii)).

int64[] items := CREATE()
items->append(1)
FOR x IN items { items->append(x) }

(h) Error results that are never checked

Where it bites: C and Go, where an error code can be stored and forgotten. Envzn: a STATUS kept in a variable must be checked before it goes out of scope. Dropping a result on purpose is written visibly, as $? := call() (I.F.iv).

MODULE statusExample

CLASS Main IMPLEMENTS TaskStarter {
    METHOD save() RETURNS STATUS {
        RETURN (SUCCESS)
    }

    METHOD start() RETURNS STATUS {
        STATUS s = save()
        RETURN (SUCCESS)
    }
}

(i) Catch-all error handlers

Where it bites: Java, C# and Python (except:), where one handler silently swallows every failure. Envzn: recovering from the base Error class is refused; name the errors you handle (I.M.ii).

TRY { printline("work") }
RECOVER (Error e) { printline("swallowed") }

(j) Switch fall-through

Where it bites: C, C++ and Java, where a forgotten break runs the next case. Envzn: MATCH never falls through, and it dispatches only over closed sets (an enum, a GROUP of types, or a STATUS). Matching on arbitrary values is an IF chain (I.H.v).

int32 n = 5
MATCH n {
    WHEN 5: { printline("five") }
}

(k) Build steps that run arbitrary code

Where it bites: npm install scripts, Cargo's build.rs, CMake: a dependency can run code on your machine at build time. Envzn: manifest build flags that could run code are refused, inline C blocks are not part of the language, and a module may call C only after opting in with "allows_foreign": true (I.N).

{ "name": "netio", "version": "1.0.0", "target": "library", "allows_foreign": true, "sources": ["Socket.ev"] }