<?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>DEV Community: Karac Thweatt</title>
    <description>The latest articles on DEV Community by Karac Thweatt (@kvthweatt).</description>
    <link>https://dev.to/kvthweatt</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%2F3901205%2F29c89d83-b41a-42e3-abad-8f671872dc61.jpg</url>
      <title>DEV Community: Karac Thweatt</title>
      <link>https://dev.to/kvthweatt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kvthweatt"/>
    <language>en</language>
    <item>
      <title>Flux: The New Programming Language Built for Tomorrow’s CPUs</title>
      <dc:creator>Karac Thweatt</dc:creator>
      <pubDate>Wed, 13 May 2026 20:04:27 +0000</pubDate>
      <link>https://dev.to/kvthweatt/flux-the-new-language-built-for-tomorrows-cpus-2381</link>
      <guid>https://dev.to/kvthweatt/flux-the-new-language-built-for-tomorrows-cpus-2381</guid>
      <description>&lt;p&gt;As we enter an era of massive hardware innovation, the design of programming languages must evolve to keep pace with modern advancements. Flux is more than just a language, it’s the embodiment of a new paradigm in systems programming, purpose-built to leverage the architectural trajectory of modern CPUs, particularly the advent of massive cache hierarchies.&lt;/p&gt;

&lt;p&gt;Designed with insights into how hardware is evolving, Flux stands out as the only systems programming language that fully embraces stack-by-default memory allocation, making it the fastest and most efficient language for modern performance-critical applications. Here’s why Flux is not just relevant today, but also future-proof for the next generation of CPUs.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Hardware Shift: CPUs Are Scaling Cache, Not Clock Speed
&lt;/h2&gt;

&lt;p&gt;For decades, performance gains in CPUs came largely from increasing clock speeds. However, as heat and power efficiency limits closed that path, CPU designers turned to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Multi-core processing&lt;/strong&gt; for parallelism&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Out-of-order execution&lt;/strong&gt; for smarter instruction handling, and&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Massive on-chip caches&lt;/strong&gt; to reduce memory latency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Recent CPUs, such as AMD’s models with 448MB of total cache, reflect this shift towards leveraging low-latency, high-bandwidth cache hierarchies. These caches are the new performance battleground, capable of delivering data at speeds 10–20x faster than main memory (RAM).&lt;/p&gt;

&lt;p&gt;However, most programming languages have not adapted to this evolution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Heap-first architectures&lt;/strong&gt; lead to fragmented, unpredictable memory patterns that fail to exploit the benefits of caches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Legacy languages like C and C++&lt;/strong&gt; require manual and deliberate stack management, creating unnecessary friction for developers aiming to optimize their performance&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Even systems languages like Rust pay penalties&lt;/strong&gt; due to memory safety guarantees and reliance on the heap for ownership-validation mechanisms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Flux changes all of this.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Flux Advantage: Stack-by-Default Design
&lt;/h2&gt;

&lt;p&gt;Flux is the only language built from the ground up with stack allocation as the default behavior.&lt;/p&gt;

&lt;p&gt;Unlike other systems languages that encourage or allow heap-dependence unless explicitly overridden, &lt;strong&gt;Flux ensures that everything is allocated on the stack by default&lt;/strong&gt;, including pointers, unless otherwise specified by the programmer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Stack-First Optimizations Matter:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Faster Memory Access&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory allocated on the stack stays cache-resident or close to it, making it up to 20x faster than heap memory.&lt;/li&gt;
&lt;li&gt;Heap memory, by contrast, is dynamically allocated and often ends up scattered across random regions in main memory, slowing access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cache-Friendly by Design:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stack allocation leverages spatial and temporal locality — data is laid out in a predictable, linear fashion, making it easy for modern CPUs to prefetch and cache efficiently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Zero Fragmentation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The stack eliminates the challenges of heap fragmentation, ensuring predictable memory management. This simplifies programs while improving both performance and reliability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Minimal Runtime Overhead:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stack management has virtually zero overhead since allocation and deallocation follow straightforward linear patterns. Heap management requires algorithms with non-trivial costs to handle allocation, garbage collection, or reference counting.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Competitive Edge: Why Flux Outperforms C, Rust, and Others
&lt;/h2&gt;

&lt;p&gt;With its stack-first philosophy, Flux inherently delivers predictable performance gains, even against heavyweight competitors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flux vs C:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;C requires explicit management: While C allows stack allocation, developers must manually ensure variables remain on the stack. Flux removes this cognitive overhead by making the stack the default.&lt;/li&gt;
&lt;li&gt;Flux also avoids C’s reliance on the heap for constructs like dynamic pointers — critical in systems programming.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Flux vs Rust:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rust’s borrow checker introduces runtime overhead and restricts developers to ownership-based memory models, often forcing heap usage for safety.&lt;/li&gt;
&lt;li&gt;Flux trusts the programmer while offering opt-in ownership without unnecessary restrictions, enabling stack-first patterns that outperform Rust in cache-bound workloads.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Flux vs Python/Go:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unlike managed languages (Python, Go), which abstract memory management entirely with heap and garbage collection, Flux gives direct control over allocation allowing it to operate in low-latency and resource-constrained environments.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Flux Is Future-Proof for the New CPU Era
&lt;/h2&gt;

&lt;p&gt;The trend of massive CPU caches and increasingly complex memory hierarchies solidifies Flux’s position as the language of the future. Here’s why:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Made for Modern Hardware:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modern CPUs are optimized for patterns of locality, and Flux’s stack-first design takes advantage of this by ensuring that data resides in low-latency, high-speed caches.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Scalable Performance:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As CPUs integrate even larger caches, the performance gap between stack and heap usage will only grow. Flux’s focus on stack allocation guarantees that it remains the fastest option on high-end hardware.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Low Overhead for High Throughput:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Massive parallel systems with dozens or hundreds of cores require predictable memory behavior for lock-free, low-contention programming. Flux’s stack philosophy ensures that even in heavily threaded environments, memory contention is minimized.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ideal for Real-Time and Embedded Systems:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With its stack-first design, Flux is ready for embedded systems, IoT, edge computing, and game engines — domains where deterministic performance, low latency, and efficient use of limited resources are critical.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Aligned with Green Computing:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Efficient cache usage not only improves speeds but also reduces energy consumption, making Flux a natural fit for energy-efficient software development in a resource-conscious world.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Future is Flux
&lt;/h2&gt;

&lt;p&gt;Programming languages often lag behind hardware advancements, but Flux flips the equation. By aligning itself with the trajectory of &lt;strong&gt;cache-optimized, high-core-count CPUs&lt;/strong&gt;, Flux redefines systems programming for the modern and future eras of computing.&lt;/p&gt;

&lt;p&gt;Whether you’re optimizing embedded devices, building network protocols, developing game engines, or working on memory-intensive applications, Flux delivers unmatched performance with its stack-first design philosophy. It is not just a language for today — it is the future of systems programming.&lt;/p&gt;




&lt;h2&gt;
  
  
  Where Can I Get Flux?
&lt;/h2&gt;

&lt;p&gt;Flux is on GitHub at &lt;a href="https://github.com/kvthweatt/Flux" rel="noopener noreferrer"&gt;https://github.com/kvthweatt/Flux&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>hardware</category>
      <category>compilers</category>
      <category>flux</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Karac Thweatt</dc:creator>
      <pubDate>Mon, 27 Apr 2026 21:23:35 +0000</pubDate>
      <link>https://dev.to/kvthweatt/-44a8</link>
      <guid>https://dev.to/kvthweatt/-44a8</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/kvthweatt/flux-the-new-programming-language-built-for-speed-easy-to-read-and-familiar-378p" class="crayons-story__hidden-navigation-link"&gt;Flux - the new programming language is built for speed, easy to read, and familiar.&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/kvthweatt" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3901205%2F29c89d83-b41a-42e3-abad-8f671872dc61.jpg" alt="kvthweatt profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/kvthweatt" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Karac Thweatt
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Karac Thweatt
                
              
              &lt;div id="story-author-preview-content-3559140" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/kvthweatt" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3901205%2F29c89d83-b41a-42e3-abad-8f671872dc61.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Karac Thweatt&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/kvthweatt/flux-the-new-programming-language-built-for-speed-easy-to-read-and-familiar-378p" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Apr 27&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/kvthweatt/flux-the-new-programming-language-built-for-speed-easy-to-read-and-familiar-378p" id="article-link-3559140"&gt;
          Flux - the new programming language is built for speed, easy to read, and familiar.
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/language"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;language&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/compilers"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;compilers&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/flux"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;flux&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/kvthweatt/flux-the-new-programming-language-built-for-speed-easy-to-read-and-familiar-378p" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;1&lt;span class="hidden s:inline"&gt; reaction&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/kvthweatt/flux-the-new-programming-language-built-for-speed-easy-to-read-and-familiar-378p#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Flux - the new programming language is built for speed, easy to read, and familiar.</title>
      <dc:creator>Karac Thweatt</dc:creator>
      <pubDate>Mon, 27 Apr 2026 21:20:55 +0000</pubDate>
      <link>https://dev.to/kvthweatt/flux-the-new-programming-language-built-for-speed-easy-to-read-and-familiar-378p</link>
      <guid>https://dev.to/kvthweatt/flux-the-new-programming-language-built-for-speed-easy-to-read-and-familiar-378p</guid>
      <description>&lt;p&gt;I've been working on Flux - my new compiled, general-purpose systems programming language - and wanted to write up what it looks like today. This isn't a roadmap post or a vision doc, just a walkthrough of the language as it exists right now. Source files use the &lt;code&gt;.fx&lt;/code&gt; extension, the compiler targets LLVM, and the language is nearing bootstrap.&lt;/p&gt;

&lt;p&gt;First things first. Flux is not C, nor a C derivative / wrapper.&lt;/p&gt;

&lt;p&gt;Let's start simple and build up from there.&lt;/p&gt;




&lt;h2&gt;
  
  
  Hello, World
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#import "standard.fx";

using standard::io::console;

def main() -&amp;gt; int
{
    print("Hello, World!\n");
    return 0;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few things to notice immediately: &lt;code&gt;def&lt;/code&gt; is the function keyword, &lt;code&gt;-&amp;gt;&lt;/code&gt; declares the return type, and the closing brace of a compound statement gets a semicolon - compound statements are terminated just like any other statement in Flux. It's consistent everywhere once you internalize it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;#import&lt;/code&gt; is textual - it splices the file contents at the import site. Multiple imports are processed left to right:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#import "standard.fx";
#import "mylib.fx", "foobar.fx";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;using&lt;/code&gt; declaration brings a namespace into scope. Namespaces use &lt;code&gt;::&lt;/code&gt; for access, and duplicate namespace definitions merge rather than conflict - a library can spread a namespace across multiple files and it behaves as one namespace at the use site.&lt;/p&gt;




&lt;h2&gt;
  
  
  Variables and Primitives
&lt;/h2&gt;

&lt;p&gt;Flux has the types you'd expect for systems work:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;uint&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;ulong&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;, &lt;code&gt;double&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;void&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And one you might not: &lt;code&gt;data&lt;/code&gt;. More on that shortly.&lt;/p&gt;

&lt;p&gt;Variables are stack-allocated by default. Heap allocation requires the &lt;code&gt;heap&lt;/code&gt; keyword - there's no implicit dynamic allocation anywhere.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int x = 5;
uint y = 300u;
float pi = 3.14159;
bool flag = true;

heap string s = "some data";
(void)s;   // explicit cleanup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multiple declarations can be comma-chained:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int x = 10,
    y = 20,
    z = y - x; // declared in order, so this works
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;void&lt;/code&gt; as a value equals &lt;code&gt;0&lt;/code&gt; equals &lt;code&gt;false&lt;/code&gt;. You can use it directly in expressions and comparisons, and it serves as the null value for pointers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;p&gt;Functions live at module, namespace, or object scope - no nested function definitions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myAdd(int x, int y) -&amp;gt; int
{
    return x + y;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Overloading works on type signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myAdd(float x, float y) -&amp;gt; float
{
    return x + y;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Prototypes (forward declarations) don't require parameter names, only types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def myAdd(int, int) -&amp;gt; int,
    myAdd(float, float) -&amp;gt; float;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;def&lt;/code&gt; is &lt;code&gt;fastcall&lt;/code&gt; by default. Other calling conventions are first-class keywords like &lt;code&gt;stdcall&lt;/code&gt;, &lt;code&gt;cdecl&lt;/code&gt;, &lt;code&gt;vectorcall&lt;/code&gt;, and &lt;code&gt;thiscall&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Control Flow
&lt;/h2&gt;

&lt;p&gt;Standard &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;elif&lt;/code&gt;/&lt;code&gt;else&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;do&lt;/code&gt;/&lt;code&gt;while&lt;/code&gt;, and &lt;code&gt;switch&lt;/code&gt; - all terminated with semicolons. &lt;code&gt;switch&lt;/code&gt; only puts the semicolon on the &lt;code&gt;default&lt;/code&gt; block. &lt;code&gt;try&lt;/code&gt;/&lt;code&gt;catch&lt;/code&gt; only puts it on the last catch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 0; i &amp;lt; 10; i++)
{
    if (i % 2 == 0) { continue; };
    print(f"{i}");
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ternary works as expected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int z = x &amp;lt; y ? y : 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flux also has a null-coalesce operator &lt;code&gt;??&lt;/code&gt; and a conditional assign &lt;code&gt;?=&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int z = y ?? 0;    // z = y if y is non-null, else 0
x ?= 50;           // assign 50 only if x is currently null/zero
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Structs
&lt;/h2&gt;

&lt;p&gt;Structs are always packed - no compiler-inserted padding. You control alignment by choosing your types. They're non-executable: no functions, no objects, just data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct xyzStruct
{
    int x, y, z;
};

xyzStruct v {x = 1, y = 2, z = 3};
print(v.x);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Structs can contain other structs, support composition (prepend/append another struct's fields), and can be templated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct Pair&amp;lt;A, B&amp;gt;
{
    A first;
    B second;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Template arguments are inferred at the call site.&lt;/p&gt;




&lt;h2&gt;
  
  
  Objects
&lt;/h2&gt;

&lt;p&gt;Objects are executable types with constructors, destructors, and methods. &lt;code&gt;this&lt;/code&gt; is always implicit - never a parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;object Counter
{
    int val;

    def __init(int start) -&amp;gt; this
    {
        this.val = start;
        return this;
    };

    def __exit() -&amp;gt; void {};

    def increment() -&amp;gt; void
    {
        this.val++;
    };
};

Counter c = 0;       // sugar for Counter c(0);
c.increment();
print(c.val);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Single-parameter &lt;code&gt;__init&lt;/code&gt; allows the assignment-style instantiation shown above.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;defer&lt;/code&gt; runs cleanup in LIFO order, immediately before the function returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Counter c = 0;
defer c.__exit();
// ... c is cleaned up automatically at return
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Traits&lt;/strong&gt; enforce structural contracts at compile time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;trait Drawable
{
    def draw() -&amp;gt; void;
};

Drawable object Sprite
{
    def draw() -&amp;gt; void
    {
        // must not be empty
        return void;
    };
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a &lt;code&gt;Drawable&lt;/code&gt; object doesn't implement &lt;code&gt;draw()&lt;/code&gt;, compilation fails.&lt;/p&gt;




&lt;h2&gt;
  
  
  Error Handling
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;throw&lt;/code&gt; accepts any type. &lt;code&gt;catch&lt;/code&gt; matches by type, with &lt;code&gt;auto&lt;/code&gt; as the catch-all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def risky(int mode) -&amp;gt; void
{
    if (mode == 1) { throw(ErrorA(100)); }
    elif (mode == 2) { throw(ErrorB("failed")); }
    else { throw("generic"); };
};

try
{
    risky(2);
}
catch (ErrorA e) { print(f"code: {e.code}"); }
catch (ErrorB e) { print(f"msg: {e.message}"); }
catch (string s) { print(s); }
catch (auto x)   { print("unknown"); };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Memory and Pointers
&lt;/h2&gt;

&lt;p&gt;Heap allocation goes through &lt;code&gt;fmalloc&lt;/code&gt; and &lt;code&gt;ffree&lt;/code&gt; directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;u64 p = fmalloc(sz);
if (!(@)p) { ok = false; break; };
total_bytes += (i64)sz;
ffree(p);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@&lt;/code&gt; is address-of. &lt;code&gt;(@)&lt;/code&gt; is an address cast - converts an integer value to a pointer. &lt;code&gt;!&lt;/code&gt; applied to a pointer emits a null check. There's also a postfix not-null operator &lt;code&gt;!?&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (ptr!?) { /* ptr is non-null */ };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pointer arithmetic, casting, and raw dereferencing all work as you'd expect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;byte* bp = (byte*)@addr;
int val = *some_ptr;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The &lt;code&gt;data&lt;/code&gt; Type and Bit-Level Work
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;data{N}&lt;/code&gt; declares N-bit raw storage, unsigned by default. You can apply &lt;code&gt;signed&lt;/code&gt; and create type aliases with &lt;code&gt;as&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;signed data{32} as fixed16_16;

def to_fixed(float value) -&amp;gt; fixed16_16
{
    return (fixed16_16)(value * 65536.0);
};

def fixed_mul(fixed16_16 a, fixed16_16 b) -&amp;gt; fixed16_16
{
    i64 temp = ((i64)a * (i64)b) &amp;gt;&amp;gt; 16;
    return (fixed16_16)temp;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flux also has endian-aware width types as first-class aliases: &lt;code&gt;nybble&lt;/code&gt;, &lt;code&gt;be16&lt;/code&gt;, &lt;code&gt;be32&lt;/code&gt;, &lt;code&gt;be64&lt;/code&gt;, &lt;code&gt;le16&lt;/code&gt;, &lt;code&gt;le32&lt;/code&gt;, and so on. Network and binary protocol structs look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct IPHeader
{
    nybble version, ihl;
    byte tos;
    be16 total_length, identification, flags_offset;
    byte ttl, protocol;
    be16 checksum;
    be32 src_addr, dst_addr;
};

def parse_ip(byte* packet) -&amp;gt; IPHeader
{
    IPHeader* header = (IPHeader*)packet;
    return *header;
};

def format_ip(be32 addr) -&amp;gt; string
{
    byte* bp = (byte*)@addr;
    return f"{bp[0]}.{bp[1]}.{bp[2]}.{bp[3]}";
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Operators
&lt;/h2&gt;

&lt;p&gt;Flux separates logical and bitwise operators syntactically. Logical: &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;^^&lt;/code&gt; (XOR), &lt;code&gt;!&amp;amp;&lt;/code&gt; (NAND), &lt;code&gt;!|&lt;/code&gt; (NOR). Bitwise versions are prefixed with a backtick: &lt;code&gt;`&amp;amp;&lt;/code&gt;, &lt;code&gt;`|&lt;/code&gt;, &lt;code&gt;`^^&lt;/code&gt;, &lt;code&gt;`!&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Shifts: &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;.&lt;br&gt;
Bit slice (extracts a range of bits):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a[x``y]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Operator overloading is supported as long as at least one parameter is not a built-in primitive - &lt;code&gt;struct&lt;/code&gt; and &lt;code&gt;object&lt;/code&gt; types are always eligible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def operator+(xyzStruct a, xyzStruct b) -&amp;gt; xyzStruct
{
    return xyzStruct {x = a.x + b.x, y = a.y + b.y, z = a.z + b.z};
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Templates and contracts can be attached to operator definitions.&lt;/p&gt;

&lt;p&gt;The chain operator &lt;code&gt;&amp;lt;-&lt;/code&gt; passes the right-hand result as the first argument to the left-hand function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int z = foo() &amp;lt;- bar();   // == foo(bar())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And &lt;code&gt;&amp;lt;~&lt;/code&gt; on a function declaration emits &lt;code&gt;musttail&lt;/code&gt;, guaranteeing zero stack growth for tail-recursive functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def trampoline(int n) &amp;lt;~ int;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Contracts and Macros
&lt;/h2&gt;

&lt;p&gt;Contracts are pre/post conditions attached to functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contract positive { assert(x &amp;gt; 0, "x must be greater than zero"); };

def sqrt_int(int x) -&amp;gt; int : positive
{
    // x is guaranteed &amp;gt; 0 here
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Parameterized contracts match the arity of the function they're attached to.&lt;/p&gt;

&lt;p&gt;Macros are expression-only and expand at the call site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;macro CLAMP(val, lo, hi)
{
    (val, lo, hi) ((val) &amp;lt; (lo) ? (lo) : (val) &amp;gt; (hi) ? (hi) : (val))
};
int c = CLAMP(x, 0, 255);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Macros and contracts can be mixed on the same function.&lt;/p&gt;




&lt;h2&gt;
  
  
  Enums, Unions, and the Preprocessor
&lt;/h2&gt;

&lt;p&gt;Enums are typed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum Color { Red, Green, Blue };

Color c = Color::Red;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unions share memory across members in the usual way, declared like structs.&lt;/p&gt;

&lt;p&gt;The preprocessor is minimal: &lt;code&gt;#import&lt;/code&gt;, &lt;code&gt;#dir&lt;/code&gt;, &lt;code&gt;#def&lt;/code&gt;, &lt;code&gt;#ifdef&lt;/code&gt;, &lt;code&gt;#ifndef&lt;/code&gt;, &lt;code&gt;#else&lt;/code&gt;, &lt;code&gt;#warn&lt;/code&gt;, &lt;code&gt;#stop&lt;/code&gt;. &lt;code&gt;#dir&lt;/code&gt; adds a path to the search list. &lt;code&gt;#stop&lt;/code&gt; hard-halts compilation with a message.&lt;/p&gt;




&lt;h2&gt;
  
  
  Putting It Together:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#import "standard.fx";

using standard::io::console;

struct myStru&amp;lt;T&amp;gt;
{
    T a, b;
};

def foo&amp;lt;T, U&amp;gt;(T a, U b) -&amp;gt; U
{
    return a.a * b;
};

def bar(myStru&amp;lt;int&amp;gt; a, int b) -&amp;gt; int
{
    return foo(a, 3);
};

macro macNZ(x)
{
    x != 0
};

contract ctNonZero(a,b)
{
    assert(macNZ(a), "a must be nonzero");
    assert(macNZ(b), "b must be nonzero");
};

contract ctGreaterThanZero(a,b)
{
    assert(a &amp;gt; 0, "a must be greater than zero");
    assert(b &amp;gt; 0, "b must be greater than zero");
};

operator&amp;lt;T, K&amp;gt; (T t, K k)[+] -&amp;gt; int
:     ctNonZero(  c,   d), // works on arity and position, not identifier name.
ctGreaterThanZero(e,   f)
{
    return t + k;
};

def main() -&amp;gt; int
{
    myStru&amp;lt;int&amp;gt; ms = {10,20};

    int x = foo(ms, 3);

    i32 y = bar(ms, 3);

    println(x + y);

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  Current State
&lt;/h2&gt;

&lt;p&gt;The standard library is actively growing - JSON, UUIDs, networking, hashing, and encryption are all in progress. Bootstrapping - rewriting the compiler in Flux - is the next major milestone. There's a GitHub repository, Discord server, and website if you want to follow along or get involved.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/kvthweatt/Flux" rel="noopener noreferrer"&gt;https://github.com/kvthweatt/Flux&lt;/a&gt;&lt;br&gt;
Discord: &lt;a href="//discord.gg/wVAm2E6ymf"&gt;discord.gg/wVAm2E6ymf&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>language</category>
      <category>compilers</category>
      <category>flux</category>
    </item>
  </channel>
</rss>
