<story><title>What Makes the Zig Programming Language Unique?</title><url>https://erikexplores.substack.com/p/what-makes-the-zig-programming-language</url></story><parent_chain></parent_chain><comment><author>belmarca</author><text>&lt;p&gt;&lt;pre&gt;&lt;code&gt;    Programming language experts told Andrew Kelley, the creator of the Zig
    programming language, that having code which could run at compile time was a
    really dumb idea. But he went ahead and implemented it anyway. Years later,
    this has proven to be one of the killer features of Zig. In the Zig world, we
    call it comptime, from the keyword used to mark code required to run at compile
    time or variables to be known at compile time.
&lt;/code&gt;&lt;/pre&gt;
Which experts? The &amp;quot;comptime&amp;quot; is just macro-expansion from Scheme&amp;#x2F;Lisp which has been around for a long time. Aren&amp;#x27;t C++ templates also &amp;quot;code that runs at compile time&amp;quot;?</text></comment>
<story><title>What Makes the Zig Programming Language Unique?</title><url>https://erikexplores.substack.com/p/what-makes-the-zig-programming-language</url></story><parent_chain></parent_chain><comment><author>evil-olive</author><text>I wrote a Sudoku solver (my go-to &amp;quot;learn a new language&amp;quot; project) in Zig and the compile-time features were extremely useful.&lt;p&gt;entirely at compile-time, I was able to generate lookup tables for &amp;quot;given this cell index, give me the indexes of the cells in its row, column, and box&amp;quot;. and I simply looped over that for each board size I wanted to support, from the standard 9x9 all the way up to 64x64.&lt;p&gt;another useful feature was support for arbitrary-sized ints [0] and packed structs [1]. for a 9x9 board, a cell can be represented with a 9-bit bitfield for possible values; a uint4 for the actual value; and a single bit indicating whether the value is known. Zig will happily pack that into a struct that occupies only 16 bits, and handle all the bit shifting &amp;amp; masking for you when you access the struct fields.&lt;p&gt;this meant I was able to represent the state of a 9x9 board in just 162 bytes - a flat array of those packed structs. and the exact same code could operate on the ~28kb of state needed for 64x64.&lt;p&gt;0: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;ziglang.org&amp;#x2F;documentation&amp;#x2F;0.9.1&amp;#x2F;#Primitive-Types&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;ziglang.org&amp;#x2F;documentation&amp;#x2F;0.9.1&amp;#x2F;#Primitive-Types&lt;/a&gt;&lt;p&gt;1: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;ziglang.org&amp;#x2F;documentation&amp;#x2F;0.9.1&amp;#x2F;#packed-struct&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;ziglang.org&amp;#x2F;documentation&amp;#x2F;0.9.1&amp;#x2F;#packed-struct&lt;/a&gt;</text></comment>