<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Navid</title>
    <description>The latest articles on Forem by Navid (@navidm).</description>
    <link>https://forem.com/navidm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3417062%2F0afa33b0-88a6-4859-af49-f1ba5413206f.jpg</url>
      <title>Forem: Navid</title>
      <link>https://forem.com/navidm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/navidm"/>
    <language>en</language>
    <item>
      <title>Spectrelang - A design by contract programming language built for correctness and low-level control</title>
      <dc:creator>Navid</dc:creator>
      <pubDate>Mon, 06 Apr 2026 16:29:04 +0000</pubDate>
      <link>https://forem.com/navidm/spectrelang-a-design-by-contract-programming-language-built-for-correctness-and-low-level-control-2l6m</link>
      <guid>https://forem.com/navidm/spectrelang-a-design-by-contract-programming-language-built-for-correctness-and-low-level-control-2l6m</guid>
      <description>&lt;p&gt;Repository: &lt;a href="https://github.com/spectrelang/spectre" rel="noopener noreferrer"&gt;https://github.com/spectrelang/spectre&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is often the case that low-level programming suffers from a tension between performance and safety. Languages such as C offer control though provide little protection, others add safety but often at the cost of explicitness, predictability, and performance.&lt;/p&gt;

&lt;p&gt;Spectre is a solution that aims to resolve that by making correctness itself a first-class feature of the language.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Spectre?
&lt;/h2&gt;

&lt;p&gt;Spectre is a contract-based, systems-level programming language designed around formal verification.&lt;/p&gt;

&lt;p&gt;Rather than treating correctness as an afterthought (tests, linting, runtime checks), Spectre bakes it directly into the language through preconditions, postconditions, invariants, and explicit trust boundaries.&lt;/p&gt;

&lt;p&gt;The result is code that is fast, low-level, self-documenting, and provably correct by design.&lt;/p&gt;




&lt;h2&gt;
  
  
  Core Philosophy
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Safety by Contract
&lt;/h3&gt;

&lt;p&gt;Every function defines what it expects and what it guarantees.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn divide(a: i32, b: i32) i32 = {
    pre {
        not_zero: b != 0
    }

    val result = a / b

    post {
        is_scaled: result &amp;lt;= a
    }

    return result
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Preconditions must hold before execution&lt;/li&gt;
&lt;li&gt;Postconditions must hold before returning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any contract fails in debug builds, the program halts safely.&lt;/p&gt;




&lt;h3&gt;
  
  
  Explicit Trust
&lt;/h3&gt;

&lt;p&gt;Spectre introduces the idea that trust is visible in the type system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn print_data() void!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;!&lt;/code&gt; in this case means: "This function cannot be formally verified."&lt;/p&gt;

&lt;p&gt;This typically applies to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I/O&lt;/li&gt;
&lt;li&gt;FFI calls&lt;/li&gt;
&lt;li&gt;Low-level memory operations&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Trust Propagation
&lt;/h3&gt;

&lt;p&gt;If you call unverified code, you must acknowledge it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub fn main() void! = { // Note how this is marked as '!'
    do_some_thing()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or explicitly override through use of the &lt;code&gt;trust&lt;/code&gt; keyword, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;trust std.stdio.puts("hello world")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prevents hidden unsafety from creeping through a codebase.&lt;/p&gt;




&lt;h3&gt;
  
  
  Immutability by Default
&lt;/h3&gt;

&lt;p&gt;Everything is immutable unless you opt in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scala"&gt;&lt;code&gt;&lt;span class="k"&gt;val&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="k"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;i32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;          &lt;span class="c1"&gt;// immutable&lt;/span&gt;
&lt;span class="k"&gt;val&lt;/span&gt; &lt;span class="nv"&gt;y&lt;/span&gt;&lt;span class="k"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;mut&lt;/span&gt; &lt;span class="kt"&gt;i32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;      &lt;span class="c1"&gt;// mutable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even struct fields respect this at the binding level, thus there are no accidental mutation leaks.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Real Example: Verified Data Structure
&lt;/h2&gt;

&lt;p&gt;A stack with enforced correctness:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub fn (Stack) push(s: mut self, vl: i32) void = {
    pre {
        not_full: s.len &amp;lt; trust @capacity(s.data)
    }

    trust @append(s.data, vl)
    s.len = s.len + 1
}

pub fn (Stack) pop(s: mut self) option[i32] = {
    pre {
        not_empty: s.len &amp;gt; 0
    }

    val top = trust @get(s.data, s.len - 1)
    trust @remove(s.data, s.len - 1)
    s.len = s.len - 1

    return top
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means no more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;popping from empty stacks&lt;/li&gt;
&lt;li&gt;overflowing buffers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are guaranteed by construction, rather than by testing.&lt;/p&gt;




&lt;h2&gt;
  
  
  Compile-Time vs Runtime Verification
&lt;/h2&gt;

&lt;p&gt;Spectre currently uses a hybrid model:&lt;/p&gt;

&lt;h3&gt;
  
  
  Runtime (today)
&lt;/h3&gt;

&lt;p&gt;Contracts are lowered into runtime checks in non-release builds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compiled into branches&lt;/li&gt;
&lt;li&gt;Failures trigger immediate program termination&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Compile-time (future)
&lt;/h3&gt;

&lt;p&gt;Planned features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Range analysis&lt;/li&gt;
&lt;li&gt;Symbolic reasoning&lt;/li&gt;
&lt;li&gt;Proof-based elimination of checks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Meaning, if something can be proven safe at compile time, it will be.&lt;/p&gt;




&lt;h2&gt;
  
  
  Option &amp;amp; Result Types
&lt;/h2&gt;

&lt;p&gt;Spectre embraces explicit error handling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn can_fail(should_fail: bool) option[i32]! = {
    if (should_fail) {
        return some 10
    }
    return none
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And richer error modeling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub fn add_two_strings(a: ref char, b: ref char) result[i64, ParseError]! = {
    val x = string_to_i64(a)?
    val y = string_to_i64(b)?
    return ok (x + y)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No exceptions or hidden control flow. Everything is explicit.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pattern Matching &amp;amp; Unions
&lt;/h2&gt;

&lt;p&gt;Tagged unions are first-class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;match x {
    Int32 a =&amp;gt; { ... }
    Pair z, y =&amp;gt; { ... }
    else =&amp;gt; { ... }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exhaustiveness and correctness are enforced by the compiler.&lt;/p&gt;




&lt;h2&gt;
  
  
  Low-Level Control (Without Giving Up Safety)
&lt;/h2&gt;

&lt;p&gt;Spectre does not hide the machine in any capacity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extern (C) fn my_malloc(space: usize) ref void! = "malloc"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full FFI support&lt;/li&gt;
&lt;li&gt;Explicit unsafe boundaries (&lt;code&gt;!&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Contracts still apply around unsafe code&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Platform-Aware Code
&lt;/h2&gt;

&lt;p&gt;Compile-time conditionals:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;when linux {
    // Linux-specific code
}

when darwin {
    // macOS-specific code
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note how there is no preprocessor or macro required. Instead, we use structured, readable conditions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Spectre Exists
&lt;/h2&gt;

&lt;p&gt;Most languages fall into one of these categories:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Low-level (C, C++)&lt;/td&gt;
&lt;td&gt;Fast but unsafe&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;High-level&lt;/td&gt;
&lt;td&gt;Safe but opaque&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rust, Ada, Modula-2&lt;/td&gt;
&lt;td&gt;Safety exists, but correctness is still implicit&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Spectre takes a different stance, in that correctness should not be inferred. It should be declared, enforced, and visible.&lt;/p&gt;




&lt;h2&gt;
  
  
  Direction
&lt;/h2&gt;

&lt;p&gt;This is still early (v0.0.1), though the direction is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stronger compile-time verification&lt;/li&gt;
&lt;li&gt;Smarter contract elimination&lt;/li&gt;
&lt;li&gt;Better ergonomics around trust boundaries&lt;/li&gt;
&lt;li&gt;A robust standard library built around correctness&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Axelang - A Systems Programming Language with Concurrency as a First-Class feature</title>
      <dc:creator>Navid</dc:creator>
      <pubDate>Fri, 21 Nov 2025 23:55:12 +0000</pubDate>
      <link>https://forem.com/navidm/axelang-a-systems-programming-language-with-concurrency-as-a-first-class-feature-4i3b</link>
      <guid>https://forem.com/navidm/axelang-a-systems-programming-language-with-concurrency-as-a-first-class-feature-4i3b</guid>
      <description>&lt;p&gt;Axelang is a new systems programming language designed around the following question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Why is concurrency an afterthought, a library, or a bolt-on runtime — as opposed to a language-level concept?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Axe aims to resolve the issue in that rather than forcing developers to manually struggle with bolted on threads, locks, futures and external libraries, Axe makes concurrency part of the core language semantics, in that writing Axe forces you to think concurrently by default.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Axe Exists
&lt;/h2&gt;

&lt;p&gt;Modern CPUs have not been about single-thread speed for a long time. Performance improvements are generally achieved by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding more cores&lt;/li&gt;
&lt;li&gt;Adding more threads&lt;/li&gt;
&lt;li&gt;Hiding I/O latency&lt;/li&gt;
&lt;li&gt;Overlapping compute with work&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But most languages still make concurrency:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;verbose&lt;/li&gt;
&lt;li&gt;error-prone&lt;/li&gt;
&lt;li&gt;tacked on after the fact&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;C, C++, Java, and Rust rely heavily on APIs, libraries, and patterns. Go introduced goroutines, but concurrency is still a runtime abstraction — not part of the language type system. Concurrency should feel like a natural mode of thinking, not a box of add-on primitives.&lt;/p&gt;




&lt;h2&gt;
  
  
  Concurrency as a Language Construct
&lt;/h2&gt;

&lt;p&gt;A simple Axe program might include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;main {
    parallel {
        single {
            task1();
            task2();
        }
        task3();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reads almost like pseudocode:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;parallel {}&lt;/code&gt; introduces a parallel execution region&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;single {}&lt;/code&gt; means “one thread runs this block”&lt;/li&gt;
&lt;li&gt;work-sharing and scheduling are handled by the compiler + runtime&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Axe’s concurrency constructs are structured, visible in the syntax tree, easy for static analysis, and safe to optimize.&lt;/p&gt;

&lt;p&gt;Instead of bolting on OpenMP-style pragmas, heavy macro systems, or attributes, Axe builds them directly into the grammar.&lt;/p&gt;




&lt;h2&gt;
  
  
  Platform-Aware Code at Compile Time
&lt;/h2&gt;

&lt;p&gt;Axe also supports compile-time dispatch based on OS or platform:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;platform windows {
    println "Running on Windows";
}
platform posix {
    println "Running on POSIX";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows the compiler to eliminate unused branches, generate smaller binaries, and avoid runtime platform checks.&lt;/p&gt;

&lt;p&gt;Your code can remain portable without littering your project with &lt;code&gt;#ifdef&lt;/code&gt; walls.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Powerful Dispatch System… Without Generics
&lt;/h2&gt;

&lt;p&gt;One standout feature is Axe’s compile-time overload map:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;overload println(x: generic) {
    string =&amp;gt; println_str;
    i32    =&amp;gt; println_i32;
}(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This looks simple, but it’s extremely powerful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Axe can resolve overloads statically&lt;/li&gt;
&lt;li&gt;No generics required&lt;/li&gt;
&lt;li&gt;No template instantiation explosion&lt;/li&gt;
&lt;li&gt;No runtime dispatch cost&lt;/li&gt;
&lt;li&gt;Works with user-defined types&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This lets Axe provide generic-friendly ergonomics without introducing template systems or complex type parameterization.&lt;/p&gt;




&lt;h2&gt;
  
  
  Familiar, But Cleaner
&lt;/h2&gt;

&lt;p&gt;Axe feels like a blend of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;C-style syntax&lt;/li&gt;
&lt;li&gt;Go-like readability&lt;/li&gt;
&lt;li&gt;Rust-level respect for correctness&lt;/li&gt;
&lt;li&gt;Zig-style minimalism&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But it doesn't copy any of them. Axe aims to be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;easier than C++&lt;/li&gt;
&lt;li&gt;more predictable than Rust’s borrow checker&lt;/li&gt;
&lt;li&gt;more explicit than Go&lt;/li&gt;
&lt;li&gt;safer than straight C&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you know a systems language, you can read Axe code in minutes.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Language Designed to Scale
&lt;/h2&gt;

&lt;p&gt;Axe has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;models (its version of simple data types)&lt;/li&gt;
&lt;li&gt;functions with clear signatures&lt;/li&gt;
&lt;li&gt;compile-time branching (for platforms, modes, and toolchains)&lt;/li&gt;
&lt;li&gt;parallel loops and reduction built in&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example parallel loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parallel for mut i = 0 to n reduce(+:sum) {
    sum = sum + i;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The compiler turns this into efficient work sharing, correct reduction handling, and thread safe execution.&lt;/p&gt;

&lt;p&gt;It does not require a single pragma, library import, or thread API.&lt;/p&gt;




&lt;p&gt;You can read more or try it at:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://axelang.org" rel="noopener noreferrer"&gt;axelang.org&lt;/a&gt;&lt;/p&gt;




</description>
      <category>programming</category>
      <category>performance</category>
      <category>development</category>
    </item>
  </channel>
</rss>
