<rss version="2.0">
  <channel>
    <title>the state of in a haze</title>
    <link>https://thestateofinahaze.net</link>
    <description>the state of in a haze blog</description>
    <generator>Zine -- https://zine-ssg.io</generator>
    <language>en-US</language>
    <lastBuildDate>Tue, 18 Aug 2026 16:37:33 +0000</lastBuildDate>
    
      <item>
        <title>Raytracing in One Weekend in Zig</title>
        <description>&lt;p&gt;Some time well over a year ago, I did &lt;a href=&quot;https://raytracing.github.io/books/RayTracingInOneWeekend.html&quot; target=&quot;_blank&quot;&gt;Raytracing in One Weekend&lt;/a&gt; so I could learn Zig. It’s a neat book, I recommend it if you haven’t tried it. (See also &lt;a href=&quot;https://github.com/ssloy/tinyraycaster/wiki&quot; target=&quot;_blank&quot;&gt;tinyraycaster&lt;/a&gt; and &lt;a href=&quot;https://matklad.github.io/2022/12/31/raytracer-construction-kit.html&quot; target=&quot;_blank&quot;&gt;Ray Tracer Construction Kit&lt;/a&gt; for less hand holding).&lt;/p&gt;&lt;p&gt;RTIOW is a project book, providing C++ code snippets for each step along the way. I’ve never done any real work in C++, and I hope I never will. The fun part about the book being written in C++ is translating it into Zig (which I did &lt;em&gt;poorly&lt;/em&gt;, I was still new to Zig, and based off feedback in #zig IRC I still have a lot to learn lol). In this post I’m going to compare some of the book’s C++ snippets to my own Zig translations, highlighting where I think Zig shines and where it doesn’t.&lt;/p&gt;&lt;p&gt;The repo is here btw: &lt;a href=&quot;https://git.sr.ht/~allidoisclassic/zigtracer&quot; target=&quot;_blank&quot;&gt;https://git.sr.ht/~allidoisclassic/zigtracer&lt;/a&gt;. You can send me an email if you think there’s any particularly awful code in there. But I want to emphasize I wrote it in Zig 0.14, halfway migrated to 0.15.1, and did another quick n dirty migration again to 0.16 just last week. It’s not the prettiest Zig code, and I refuse to make any promises about cleaning it up.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://raytracing.github.io/books/RayTracingInOneWeekend.html#thevec3class&quot; target=&quot;_blank&quot;&gt;Right away&lt;/a&gt; RTIOW defines a &lt;code&gt;vec3&lt;/code&gt; class with with basic vector math and operator overloading so you can easily do things like &lt;code&gt;u * v&lt;/code&gt; and &lt;code&gt;cross(u, v)&lt;/code&gt;, etc. Zig doesn’t have classes or operator overloading. It does have &lt;a href=&quot;https://ziglang.org/documentation/0.16.0/#Vectors&quot; target=&quot;_blank&quot;&gt;Vectors&lt;/a&gt; built into the language, and they come with  support for arithmetical operators.&lt;/p&gt;&lt;p&gt;In short, all of this boilerplate:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;cpp&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;inline&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt; operator&lt;span class=&quot;operator&quot;&gt;+&lt;/span&gt;(&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;, &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constant variable function&quot;&gt;vec3&lt;/span&gt;(&lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;] &lt;span class=&quot;operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;], &lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;] &lt;span class=&quot;operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;])&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
}

&lt;span class=&quot;keyword&quot;&gt;inline&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt; operator&lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt;(&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;, &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constant variable function&quot;&gt;vec3&lt;/span&gt;(&lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;] &lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;], &lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;] &lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;])&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
}

&lt;span class=&quot;keyword&quot;&gt;inline&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt; operator&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;(&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;, &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constant variable function&quot;&gt;vec3&lt;/span&gt;(&lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;] &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;], &lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;constant variable&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;] &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;])&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
}

&lt;span class=&quot;keyword&quot;&gt;inline&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt; operator&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;(&lt;span class=&quot;type&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;t&lt;/span&gt;, &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constant variable function&quot;&gt;vec3&lt;/span&gt;(&lt;span class=&quot;constant variable&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;], &lt;span class=&quot;constant variable&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;constant variable&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;e&lt;/span&gt;[&lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;])&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
}

&lt;span class=&quot;keyword&quot;&gt;inline&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt; operator&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;(&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;, &lt;span class=&quot;type&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;t&lt;/span&gt;) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
}

&lt;span class=&quot;keyword&quot;&gt;inline&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt; operator/(&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;vec3&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;, &lt;span class=&quot;type&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;t&lt;/span&gt;) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; (&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;constant variable&quot;&gt;t&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;is given for free in Zig just with:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;module constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;function_builtin keyword_import&quot;&gt;@Vector&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;f64&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, Vectors are intended to be used for SIMD, not for vector math. LLVM’s autovectorization optimizations on regular arrays are pretty good, and using built-in Vectors strictly enforces SIMD usage at all times, even when it may hurt performance. I don’t care. Being able to use arithmetical operators is higher priority because I find it more readable. When I complete all 3 RT books I might profile array vs vecotr implementations to see if there’s a significant difference. My gut says no.&lt;/p&gt;&lt;p&gt;Vectors come with their own annoyances, I can’t trivially scalars to multiply or divide Vectors. I have to create a 3D vector of the scalar and multiply the two vectors together, which Zig provides @splat for, but I don’t really like it. I end up with lines like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;pixel_delta_u&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;viewport_u&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@as&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@splat&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
self&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;pixel_delta_v&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;viewport_v&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@as&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@splat&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In my perfect world that snippet would be:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;pixel_delta_u&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;viewport_u&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
self&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;pixel_delta_v&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;viewport_v&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I know that has an implicit cast of a scalar to a vector, and Zig emphasizes explicitness and correctness, and probably doesn’t play nice with the SIMD instructions, but it’s just so much easier on the eyes. I’ll live with it for now.&lt;/p&gt;&lt;p&gt;The biggest pain point for Zig on this project is math with ints and floats. There are no implicit casts between floats and ints, so I end up with &lt;code&gt;@as(f64, @floatFromInt(x))&lt;/code&gt; or &lt;code&gt;@as(usize, @trunc(y))&lt;/code&gt; everywhere, which again I just find cumbersome. I’m making this more difficult than it needs to be, I haven’t put much time into trying smooth it over. Adding constants like &lt;code&gt;const x_f64: f64 = @floatFromInt(x)&lt;/code&gt; where I need them is probably enough to address it. Anyway here’s a snippet showing my dark, twisted reality:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;viewport_upper_left&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;center&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;function_builtin&quot;&gt;@as&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@splat&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;focus_distance&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;viewport_u&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@as&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@splat&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;number_float&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;viewport_v&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@as&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@splat&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;number_float&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;pixel_origin&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;viewport_upper_left&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@as&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;function_builtin&quot;&gt;@splat&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;number_float&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;pixel_delta_u&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;pixel_delta_v&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Zig shines brighter in other areas like using tuples for multiple return values, and optionals. In C++ it’s typical to modify parameters via pointers and return a boolean indicating whether anything was modified. From what I can tell (not a C++ expert) it’s more common when there’s multiple values you want to return. Something like this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;cpp&quot;&gt;&lt;span class=&quot;type&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;constant variable function&quot;&gt;scatter&lt;/span&gt;(&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;ray&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;r_in&lt;/span&gt;, &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;hit_record&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;rec&lt;/span&gt;, &lt;span class=&quot;type&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;attenuation&lt;/span&gt;, &lt;span class=&quot;type&quot;&gt;ray&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;scattered&lt;/span&gt;)
&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;override&lt;/span&gt; {
    &lt;span class=&quot;constant variable&quot;&gt;attenuation&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable function&quot;&gt;color&lt;/span&gt;(&lt;span class=&quot;number&quot;&gt;1.0&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;1.0&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;1.0&lt;/span&gt;)&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;constant variable&quot;&gt;scattered&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;comment&quot;&gt;/* snippy snip */&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; true&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Translated to Zig, using an optional tuple  of &lt;code&gt;Ray&lt;/code&gt; and &lt;code&gt;Vec3&lt;/code&gt; for the return type:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;scatter&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Dielectric&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;Io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;r_in&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;HitRecord&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;keyword_type&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;ri&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;f64&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;keyword_conditional&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;front_face&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;number_float&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;refraction_index&lt;/span&gt; &lt;span class=&quot;keyword_conditional&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;refraction_index&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;scattered&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;origin&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;snip&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;direction&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;snip&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;keyword_return&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;scattered&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The call site is cleaner in comparison:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;cpp&quot;&gt;&lt;span class=&quot;type&quot;&gt;ray&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;scattered&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;type&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;attenuation&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;constant variable&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;mat&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;property function&quot;&gt;scatter&lt;/span&gt;(&lt;span class=&quot;constant variable&quot;&gt;r&lt;/span&gt;, &lt;span class=&quot;constant variable&quot;&gt;rec&lt;/span&gt;, &lt;span class=&quot;constant variable&quot;&gt;attenuation&lt;/span&gt;, &lt;span class=&quot;constant variable&quot;&gt;scattered&lt;/span&gt;))
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;attenuation&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable function&quot;&gt;ray_color&lt;/span&gt;(&lt;span class=&quot;constant variable&quot;&gt;scattered&lt;/span&gt;, &lt;span class=&quot;constant variable&quot;&gt;depth&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;constant variable&quot;&gt;world&lt;/span&gt;)&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword_conditional&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;mat&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;type constant variable_builtin function_call variable_member variable&quot;&gt;scatter&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;punctuation_bracket operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;punctuation_bracket operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;scattered&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;attenuation&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;keyword_return&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;attenuation&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;scattered&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;type constant variable_builtin function_call variable_member variable&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;depth&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;world&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I really don’t like modifying parameters of a function because it’s not always clear to the caller. It just seems like bad manners. Returning a tuple and destructuring it to &lt;code&gt;scattered&lt;/code&gt; and &lt;code&gt;attenuation&lt;/code&gt; is much more explicit.&lt;/p&gt;&lt;p&gt;Another big difference is obviously that Zig is not an object-oriented language. There are structs, there are methods, but there are no classes. RTIOW uses an abstract class, &lt;code&gt;material&lt;/code&gt;, to encapsulate behavior unique to each type of material (lambertian, metal, dielectric). Then each material is implemented in its own class, inheriting from &lt;code&gt;material&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;cpp&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;material&lt;/span&gt; {
  &lt;span class=&quot;keyword&quot;&gt;public&lt;/span&gt;:
    &lt;span class=&quot;keyword&quot;&gt;virtual&lt;/span&gt; ~&lt;span class=&quot;constant variable&quot;&gt;material&lt;/span&gt;() &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;keyword&quot;&gt;virtual&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;property function&quot;&gt;scatter&lt;/span&gt;(
        &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;ray&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;r_in&lt;/span&gt;, &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;hit_record&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;rec&lt;/span&gt;, &lt;span class=&quot;type&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;attenuation&lt;/span&gt;, &lt;span class=&quot;type&quot;&gt;ray&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;scattered&lt;/span&gt;
    ) &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; {
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; false&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
    }
}&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;lambertian&lt;/span&gt; : &lt;span class=&quot;keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;material&lt;/span&gt; {
  &lt;span class=&quot;comment&quot;&gt;// ...&lt;/span&gt;
}&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;metal&lt;/span&gt; : &lt;span class=&quot;keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;material&lt;/span&gt; {
  &lt;span class=&quot;comment&quot;&gt;// ...&lt;/span&gt;
}&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;dielectric&lt;/span&gt; : &lt;span class=&quot;keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;material&lt;/span&gt; {
  &lt;span class=&quot;comment&quot;&gt;// ...&lt;/span&gt;
}&lt;span class=&quot;delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From my (limited) experience, when you are in control of all possible types (in this case, the materials), using static dispatch with unions is the simplest way to implement polymorphism in Zig:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;
&lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Material&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;keyword_type&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;keyword_type&quot;&gt;enum&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;lambertian&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Lambertian&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;metal&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Metal&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;dielectric&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Dielectric&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt;

    &lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;scatter&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Material&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;Io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;r_in&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;HitRecord&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;keyword_type&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;keyword_return&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword_conditional&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;keyword_modifier&quot;&gt;inline&lt;/span&gt; &lt;span class=&quot;keyword_conditional&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;punctuation_delimiter&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punctuation_bracket operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;mat&lt;/span&gt;&lt;span class=&quot;punctuation_bracket operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;mat&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;type constant variable_builtin function_call variable_member variable&quot;&gt;scatter&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;r_in&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Lambertian&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;keyword_type&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;albedo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt;

        &lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;scatter&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Lambertian&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;Io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;r_in&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;HitRecord&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;keyword_type&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;comment_documentation comment spell&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Metal&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;keyword_type&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;albedo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;fuzz&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;f64&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt;

        &lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;scatter&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Metal&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;Io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;r_in&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;HitRecord&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;keyword_type&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;comment_documentation comment spell&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Dielectric&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;keyword_type&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;refraction_index&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;f64&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt;

        &lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;scatter&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Dielectric&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;Io&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;r_in&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;rec&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;HitRecord&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;keyword_type&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Ray&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;Vec3&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;comment_documentation comment spell&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I think this static dispatch pattern is fairly simple, and shouldn’t be that crazy to anyone familiar with C++ classes. I’m more accustomed to Go interfaces and wrapped my head around this just fine. For other scenarios where static dispatch isn’t feasible, I recommend reading &lt;a href=&quot;https://www.openmymind.net/Zig-Interfaces/&quot; target=&quot;_blank&quot;&gt;Zig Interfaces&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Anyway, despite some growing pains around casting, I think using Zig for RTIOW is a step up from how it’s written in C++. If you’re a C++ diehard and you feel offended by that, please send any and all thoughts to &lt;code&gt;/dev/null&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Here’s my final render:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://thestateofinahaze.net/blog/raytracing-in-one-weekend-in-zig/rtiow_final_render.png&quot;&gt;&lt;/p&gt;&lt;p&gt;The more eagle-eyed readers among you might spot that this image is slightly skewed. That’s because there’s a bug in my &lt;code&gt;Camera.zig&lt;/code&gt; render implementation, which despite rewriting three times I cannot identify the cause of. If you read the code and something jumps out at you, please send a patch or email. I’m going to leave it like this while I proceed through the rest of the &lt;a href=&quot;https://raytracing.github.io/&quot; target=&quot;_blank&quot;&gt;series&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Thanks for reading :)&lt;/p&gt;</description>
        <link>https://thestateofinahaze.net/blog/raytracing-in-one-weekend-in-zig/</link>
        <pubDate>Mon, 17 Aug 2026 00:00:00 +0000</pubDate>
        <guid>https://thestateofinahaze.net/blog/raytracing-in-one-weekend-in-zig/</guid>
      </item>
    
      <item>
        <title>Smells Like Productivity</title>
        <description>&lt;p&gt;I know everyone is tired about talking about AI. But I’m gonna write about it anyway because I’m fired up and I gotta get it out of my system. So just dip out now if you don’t wanna hear it.&lt;/p&gt;&lt;p&gt;When people argue about AI usage, it’s common that they bring up the productivity gains (or losses). &lt;em&gt;It’ll make you 10x more productive! Agents will cause brain drain, impacting productivity! We need to make sacrifices to find what productivity gains we can get from AI.&lt;/em&gt; It’s the obsession with productivity that rubs me the wrong way. Why are you so obsessed with increasing output, when any increase in profitability isn’t being passed along to you or your fellow workers? Why are you so set on churning out more features for less pay? Why are you so comfortable with outsourcing your skill development and labor value to trillion dollar companies?&lt;/p&gt;&lt;p&gt;The stink of greed polluting the air around AI turns me off of all of this.&lt;/p&gt;</description>
        <link>https://thestateofinahaze.net/blog/smells-like-productivity/</link>
        <pubDate>Wed, 03 Jun 2026 00:00:00 +0000</pubDate>
        <guid>https://thestateofinahaze.net/blog/smells-like-productivity/</guid>
      </item>
    
      <item>
        <title>Many-Item Pointers in Zig</title>
        <description>&lt;p&gt;I wrote this to better understand Zig’s many-item pointers (and also to work on the syntax highlighting on my site).&lt;/p&gt;&lt;p&gt;Zig offers &lt;a href=&quot;https://codeberg.org/ziglang/translate-c&quot; target=&quot;_blank&quot;&gt;translate-c&lt;/a&gt; as a way to translate C source &amp; header files into Zig code. Translating primitive types is trivial: C’s &lt;code&gt;unsigned int&lt;/code&gt; becomes &lt;code&gt;c_uint&lt;/code&gt;. However, pointer types are trickier. There’s no way to determine whether a pointer is referencing a single value or the start of an array, so all pointers are translated to Zig’s C pointer type &lt;code&gt;[*c]T&lt;/code&gt; (a C pointer to one or more &lt;code&gt;T&lt;/code&gt;).&lt;/p&gt;&lt;p&gt;C code before translation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;type&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;constant variable function&quot;&gt;fizz&lt;/span&gt;(&lt;span class=&quot;type&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;constant variable&quot;&gt;buzz&lt;/span&gt;) {
    &lt;span class=&quot;comment&quot;&gt;// ...&lt;/span&gt;
}

&lt;span class=&quot;type&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;constant variable function&quot;&gt;foo&lt;/span&gt;(&lt;span class=&quot;type&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;constant variable&quot;&gt;size&lt;/span&gt;, &lt;span class=&quot;type&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;constant variable&quot;&gt;bar&lt;/span&gt;) {
    &lt;span class=&quot;comment&quot;&gt;// ...&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Translated into Zig:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;fizz&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;buzz&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;variable_builtin&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;comment_documentation comment spell&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;variable_builtin&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;comment_documentation comment spell&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;a href=&quot;https://ziglang.org/documentation/0.16.0/#C-Pointers&quot; target=&quot;_blank&quot;&gt;Zig language reference&lt;/a&gt; recommends avoiding using C pointers directly. The idea is that we should know which pointer type a translated function expects and edit the generated Zig code to use the proper single-item pointer &lt;code&gt;*T&lt;/code&gt; or a many-item pointer &lt;code&gt;[*]T&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;fizz&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;buzz&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;comment_documentation comment spell&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;keyword_modifier&quot;&gt;pub&lt;/span&gt; &lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;c_int&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;comment_documentation comment spell&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Trying to to pass a slice to a function expecting a many-item pointer results in a compilation error:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword_function&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable function&quot;&gt;expectManyItemPointer&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;keyword_modifier&quot;&gt;comptime&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin variable_parameter variable type&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;usize&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;keyword_repeat&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;punctuation_bracket operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;punctuation_bracket operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;expectManyItemPointer&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;u8&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;constant variable_builtin function_call variable type&quot;&gt;expectManyItemPointer&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;type_builtin&quot;&gt;u8&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;punctuation_bracket&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;sh&quot;&gt;&lt;span class=&quot;constant function&quot;&gt;error:&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;expected&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;string constant&quot;&gt;&amp;apos;[*]const u8&amp;apos;&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;string constant&quot;&gt;&amp;apos;[]const u8&amp;apos;&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;expectManyItemPointer&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant function&quot;&gt;u8,&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;foo,&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;11&lt;/span&gt;);
                          &lt;span class=&quot;constant function&quot;&gt;^~~&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s actually pretty easy to get around this, we can pass in the slice’s pointer instead, because slices are just fat pointers with a base address and length:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;u8&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;comment_documentation comment spell&quot;&gt;// before (compilation error)&lt;/span&gt;
&lt;span class=&quot;constant variable_builtin function_call variable type&quot;&gt;expectManyItemPointer&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;type_builtin&quot;&gt;u8&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;comment_documentation comment spell&quot;&gt;// after (good, no error, amazing)&lt;/span&gt;
&lt;span class=&quot;constant variable_builtin function_call variable type&quot;&gt;expectManyItemPointer&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;type_builtin&quot;&gt;u8&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable_member variable&quot;&gt;ptr&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The original reason I wrote this post was because I was confused when trying to pass a single-item pointer to a function expecting a many-item pointer. This Zig code doesn’t compile because a &lt;code&gt;*c_uint&lt;/code&gt; cannot coerce to a &lt;code&gt;[*]c_uint&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;vbo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;c_uint&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;gl&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;type constant variable_builtin function_call variable_member variable&quot;&gt;GenBuffers&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;vbo&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;sh&quot;&gt;&lt;span class=&quot;constant function&quot;&gt;error:&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;expected&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;string constant&quot;&gt;&amp;apos;[*]c_uint&amp;apos;&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;string constant&quot;&gt;&amp;apos;*c_uint&amp;apos;&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;gl.GenBuffers&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant function&quot;&gt;1,&lt;/span&gt; &amp;amp;&lt;span class=&quot;constant function&quot;&gt;vbo&lt;/span&gt;);
                &lt;span class=&quot;constant function&quot;&gt;^~~~&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After smacking my head on the wall I eventually found that passing a pointer to a single-element array would work, but it’s ugly and I hate it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;vbo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;type_builtin&quot;&gt;c_uint&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;gl&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;type constant variable_builtin function_call variable_member variable&quot;&gt;GenBuffers&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;vbo&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I’d have to access it with &lt;code&gt;vbo[0]&lt;/code&gt; everywhere even though I know it’s just one element, and that sucks. Technically, &lt;code&gt;@ptrCast&lt;/code&gt; also works here, but the folks in #zig told me that would be uncouth, ungodly, and unwise. So instead I found a simple, idiomatic, non-&lt;code&gt;@ptrCast&lt;/code&gt; way to do it, just by reading the &lt;a href=&quot;https://ziglang.org/documentation/0.16.0/&quot; target=&quot;_blank&quot;&gt;docs&lt;/a&gt;. Can you imagine that? We can coerce a single-item pointer to a many-item pointer by slicing it with a length of one:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;zig&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;constant variable_builtin type variable&quot;&gt;vbo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;type_builtin&quot;&gt;c_uint&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;gl&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;type constant variable_builtin function_call variable_member variable&quot;&gt;GenBuffers&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;constant variable_builtin type variable&quot;&gt;vbo&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At first glance it wasn’t obvious what this snippet did, so I’ll break it down: With &lt;code&gt;&amp;amp;vbo&lt;/code&gt; we’re taking the address of &lt;code&gt;vbo&lt;/code&gt;, which yields a single-item pointer, &lt;code&gt;*c_uint&lt;/code&gt;. Then we slice it with the &lt;code&gt;[start..len]&lt;/code&gt; syntax. And because both bounds of the slice are known at compile time the resulting type is a pointer to an array with one element, &lt;code&gt;*[1]c_uint&lt;/code&gt;. And because pointers to arrays coerce to many-item pointers, we can pass &lt;code&gt;(&amp;amp;vbo)[0..1]&lt;/code&gt; to any function expecting a many-item pointer.&lt;/p&gt;&lt;p&gt;This little area of Zig was interesting to explore and learn more about its pointers and type coercion. I hope you learned something from this post, or find it helpful when running into the same problem I had. Thanks for reading :)&lt;/p&gt;</description>
        <link>https://thestateofinahaze.net/blog/many-item-pointers/</link>
        <pubDate>Mon, 27 Apr 2026 00:00:00 +0000</pubDate>
        <guid>https://thestateofinahaze.net/blog/many-item-pointers/</guid>
      </item>
    
      <item>
        <title>Raise the Bottom Line for Humanity</title>
        <description>&lt;p&gt;I love programming, and each year it feels like I’ve &lt;em&gt;just now&lt;/em&gt; started getting good at it. I’m not on board with people trying to convince me I’ll be &lt;em&gt;sooooo much more productive&lt;/em&gt; if I use AI to do programming, or even left behind if I don’t fall in line.&lt;/p&gt;&lt;p&gt;Learning and improving and getting better at programming and creating software brings me the most joy out of any hobby. And I don’t want to just be good or great, I want to be amazing, I want to be the best. I have absolutely zero interest in sacrificing my ability to learn so that I can &lt;em&gt;maybe&lt;/em&gt; produce more lines of code in a shorter amount of time. The supposed pros do not outweigh the cons for me.&lt;/p&gt;&lt;p&gt;Being able to create software independently (not via a subscription to a massive corporation that trains and hosts models) is such an incredibly powerful ability. Free and accessible software &lt;a href=&quot;https://youtu.be/zYAif5PhhoQ?t=8967&quot; target=&quot;_blank&quot;&gt;raises the standard of quality&lt;/a&gt; that corporations have to meet with their own proprietary products. We should not willingly cede control of this ability to technofascist corporations. We should tell them to get bent, and make better alternatives to their sofware. We should be defending the freedoms of everyone when corporate interests &lt;a href=&quot;https://web.archive.org/web/20260313143853/https://www.reddit.com/r/linux/comments/1rshc1f/i_traced_2_billion_in_nonprofit_grants_and_45/&quot; target=&quot;_blank&quot;&gt;lobby against our rights&lt;/a&gt; so they can make more money off of spying on us. We should be striving to create for the good of all humans instead of just for ourselves. We should raise the bottom line for humanity.&lt;/p&gt;</description>
        <link>https://thestateofinahaze.net/blog/bottom-line/</link>
        <pubDate>Sat, 11 Apr 2026 00:00:00 +0000</pubDate>
        <guid>https://thestateofinahaze.net/blog/bottom-line/</guid>
      </item>
    
      <item>
        <title>Breaking Ground</title>
        <description>&lt;p&gt;Well, I’ve finally launched a personal website. This has been on my TODO list foreverrrrrr. I had a lot of fun toying with the CSS and making it feel like &lt;em&gt;me&lt;/em&gt;. If you find the fried header elements difficult to read, you can view this site through your favorite RSS reader instead, but first you should stick around for a little while to longer to admire my distorted design. Don’t forget to check out the favicon too :)&lt;/p&gt;&lt;p&gt;I’ve been teaching myself a lot since graduating college, but up until recently I haven’t written anything down. Reflecting on what I’ve learned and writing down my thoughts has helped me develop a better understanding. I’m gonna try to edit what I write into some blog posts, with the hope that my writing and learning will improve. If not, oh well, at least this site looks cool as hell.&lt;/p&gt;</description>
        <link>https://thestateofinahaze.net/blog/breaking-ground/</link>
        <pubDate>Mon, 19 Jan 2026 00:00:00 +0000</pubDate>
        <guid>https://thestateofinahaze.net/blog/breaking-ground/</guid>
      </item>
    
  </channel>
</rss>
