<?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: Brandon Harrell</title>
    <description>The latest articles on DEV Community by Brandon Harrell (@brharrelldev).</description>
    <link>https://dev.to/brharrelldev</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1577662%2F7b41bc47-1f34-45f8-9d36-ae5f1075a221.png</url>
      <title>DEV Community: Brandon Harrell</title>
      <link>https://dev.to/brharrelldev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brharrelldev"/>
    <language>en</language>
    <item>
      <title>Unemployed proejct #1: KV Store concepts and WAL</title>
      <dc:creator>Brandon Harrell</dc:creator>
      <pubDate>Tue, 23 Jun 2026 16:32:23 +0000</pubDate>
      <link>https://dev.to/brharrelldev/unemployed-proejct-1-kv-store-concepts-and-wal-17dn</link>
      <guid>https://dev.to/brharrelldev/unemployed-proejct-1-kv-store-concepts-and-wal-17dn</guid>
      <description>&lt;h1&gt;
  
  
  Introduction to database design
&lt;/h1&gt;

&lt;p&gt;So as we start looking into the internal of a database. We must ask what a database actually is?  According to Amazon AWS website this is the description:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A database is an electronically stored, systematic collection of data. It can contain any type of data, including words, numbers, images, videos, and files. You can use software called a database management system (DBMS) to store, retrieve, and edit data. In computer systems, the word _database_ can also refer to any DBMS, to the database system, or to an application associated with the database.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is somewhat accurate. But the next question becomes:&lt;/p&gt;

&lt;p&gt;"If we are storing data, how do we represent it?"&lt;/p&gt;

&lt;p&gt;This is of course through something we've all used called &lt;em&gt;files&lt;/em&gt;. Essentially a database just represents files on a disk. And a database retrieves these files on disk through a pointer to the location on disk or an index. This also happens in file systems, as we have file pointers to locations on disk. But a database is very organized way of doing this.&lt;/p&gt;

&lt;p&gt;So why do I use term KV store? Well databases have a long history and have gone through many different technological changes. One of the key changes was the change for hierarchical databases to relational databases. The history of that is beyond the scope of this blog entry. But we started to see the dominance of relational database systems like Oracle, SQL Server, Postgres, and MySQL in the industry. These database are fairly complex, typically have a storage engine and a query engine built on top of them. As long with other design considerations like being ACID which gives consistency and durability gurantees.  In the late 2000s a certain class of databases emerged called NoSQL databases.  These addressed issues with relational databases (again won't get into them here). But they were even sub-divided into categories like Document databases, Graph databases, and more importantly Key/Value stores&lt;/p&gt;

&lt;p&gt;I would say in terms of databases KV stores are the most foundational. We just take a key and point to a value. Popular KV stores are Redis, RocksDB, LevelDB, etc. They can often serve as caching layers for distributed systems, or a place to store information about clusters. They also allow you to play around a bit with the shape of data, as data modeling just require a big composite key.&lt;/p&gt;

&lt;p&gt;As an educational exercise (as this clearly is). Its a really good target without being too ambitious. Its a solid foundation at the very least. &lt;/p&gt;

&lt;p&gt;Now lets go over the architecture of a KV store&lt;/p&gt;

&lt;h2&gt;
  
  
  KV Store high level overview
&lt;/h2&gt;

&lt;p&gt;When you store data into a database. Your storage engine will take your data, segement your infomation into chunks and then eventually flush it to the file system. Writes to disk are expensive, so the sake of efficiency your data is kept in memory for for a certain amount of time. But since memory is volatile, if your program crashes before this happens all data can be post or partially be persisted to disk which can cause data corruption. &lt;/p&gt;

&lt;p&gt;KV Stores often use something called Log Structred Merge Trees (as opposed to B-trees). This consist of 3 parts&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memtable&lt;/li&gt;
&lt;li&gt;String Sorted Table&lt;/li&gt;
&lt;li&gt;Write Ahead Log&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Memtable is often where your data is sent.  This holds your data in memory, and is usually backed by some tree like data structures.  For Memtables you need a balanced tree. It is common to use a Red-Black Tree or a Skiplist. The reason being is because these data structures make writes less expensive and can be good for concurrent writes. B-trees in traditional relational database systems tend to be better for reads, but more expensive for writes&lt;/p&gt;

&lt;p&gt;Memtables often persist to disk and this is where a String Sorted Table (henceforth SSTable) comes into play.  These will be chunks of your data sorted to disk.&lt;/p&gt;

&lt;p&gt;Write Ahead Logs are for durability. It is basically a copy or memo of your database. When there is a crash its a bit of a backup of your database that can be recovered in the case of a crash.  WAL is the most basic part of a KV store. So that is what we are beginning with&lt;/p&gt;

&lt;h2&gt;
  
  
  WAL log and how it works
&lt;/h2&gt;

&lt;p&gt;The build blocks of a WAL is a checksum. This will ensure that the file is intact when read from disk. If the checksum is incorrect, then this will likely be a file corruption problem of a bug reading from disk. WAL usually have a message format, and the checksum is inside of what is known as its &lt;em&gt;header&lt;/em&gt;.  For my code I have an incredibly simple WAL format.  Its probably way too simple, but I hope to expand on it in this blog.&lt;/p&gt;

&lt;p&gt;My header is 7 bytes long.  Below is a table of the layout&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;th&gt;data&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0-4&lt;/td&gt;
&lt;td&gt;checksum data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5-6&lt;/td&gt;
&lt;td&gt;header length.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You'll see more feature rich WALs have things like LSN or SNs (sequence numbers) and other metadata but this is fine for now.&lt;/p&gt;

&lt;p&gt;Each WAL chunk is about 64KB.  The rest of the data is they key_length, key, value_length, and value.  And this makes up the entirity of our payload.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up and next steps
&lt;/h2&gt;

&lt;p&gt;Ok I gave a huge theoretical overview of WALs. Next Blog entry I'll actually dig into writing some code. What I didn't want to do is just start with code, and there is nothing to follow along with.  &lt;/p&gt;

&lt;p&gt;Code is here: &lt;a href="https://github.com/brharrelldev/walbash_db/tree/main/walbash-rust" rel="noopener noreferrer"&gt;https://github.com/brharrelldev/walbash_db/tree/main/walbash-rust&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And you can always email me at: &lt;a href="mailto:ministerofdefense1979@gmail.com"&gt;ministerofdefense1979@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>rust</category>
      <category>database</category>
      <category>systemdesign</category>
      <category>systems</category>
    </item>
    <item>
      <title>Employed project. KV Store from scratch in Rust</title>
      <dc:creator>Brandon Harrell</dc:creator>
      <pubDate>Tue, 23 Jun 2026 16:30:43 +0000</pubDate>
      <link>https://dev.to/brharrelldev/employed-project-kv-store-from-scratch-in-rust-23lh</link>
      <guid>https://dev.to/brharrelldev/employed-project-kv-store-from-scratch-in-rust-23lh</guid>
      <description>&lt;h2&gt;
  
  
  Introduction and motivations
&lt;/h2&gt;

&lt;p&gt;Hello my name is Brandon, thought I'm known through most of my social media as Minister Of Defense. One day I a more casual blog, I'll give some lore behind the name. Anyway I just want to say I've been a software professional for about 25 years. I've held a number of different roles and titles.  But I think one of my most transformative titles I had was a data engineer.&lt;/p&gt;

&lt;p&gt;In 2013 I worked a very long term contract with Comcast. And there I worked for their cable modem provisioning team. I won't go into too many details. But I found myself dealing with a lot of data realated problems. And I found working with data to be really exciting. &lt;/p&gt;

&lt;p&gt;At the time the NoSQL craze was really hitting the industry. And in that I really started to dig deeper into core database fundamentals. I started understanding tradeoffs in data, consistency gurantees, and the shape of data.  I was also dealing with distributed state across clusters. And these became interesting problems to solve.&lt;/p&gt;

&lt;p&gt;This started my obsession with database foundations and internals. It started as a curiosity and it became something I wanted to do. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why did it take you 13 years?
&lt;/h2&gt;

&lt;p&gt;So I said I start my obsession with database internals 13 years ago. But why did it take 13 years to want to build one? 2 words.  Skill issue. &lt;/p&gt;

&lt;p&gt;The first problem was the lack of a programming language. At the time I was working in a strong Java shop, and why it was a more data oriented team (we did a lot of Hadoop and Elastic search a the time), it was still firmly an enterprise position. I also did a lot of Python during this time, and Python wasn't powerful enough to really build a database.  At least not the one I wanted to build.&lt;/p&gt;

&lt;p&gt;I wanted to re-learn C++ since most of my education was in C++. But it felt overwhelming. Eventually I ran into things like LevelDB and RocksDB. I tried to study these code bases, but it felt like I really couldn't understand what was going on.&lt;/p&gt;

&lt;p&gt;Eventually over the years I started to understand things like B+ trees vs Skiplist/LSM trees. But it was a slow process, and I never really knew where to get started.&lt;/p&gt;

&lt;p&gt;In 2016 I would leave Comcast, and I would work for a government contractor. This lead me to using Go in the backdoor.  And as many known I've built a Go career from there. Go gave me a little more confidence in building a database. But I wanted to understand it from first principles. I wanted to understand memory, building memory maps, etc. I knew I still needed to learn a lower level language to do so.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter Rust, then Zig, then Rust again
&lt;/h2&gt;

&lt;p&gt;Now the plot thickens. During my years as a software engineer I was never good with side projects.  I felt that a side project had to really become a business. And I'm not going to lie, I'm not very project focused. I'm a tech guy, and the stuff I was interested in building was lower level stuff.  Things I didn't do on my day job, and I felt was too wide of a skill gap. However, Go gave me this new sense of confidence move forward and try lower level things.&lt;/p&gt;

&lt;p&gt;However something was also fascinating about Rust. So I tried to used it.  And failed. And tried again and failed. I started to realize that this language is very hard to get productive in. You need to study borrow checker rules and semantics. Its a language that didn't lend itself to experimentation. &lt;/p&gt;

&lt;p&gt;So let's fast forward to 2024, I was laid off for the first time in probably over a decade. And I found myself with time on my hand. I knew that I no longer wanted to build side projects just to start a business.  I just wanted to build cool software. I learned about the Primegen's channel at the time, and he talked about Zig. He spoke of Zig as a simple language that didn't get in your way, but was also lower level and powerful. And I had to try it. I fell in love. And for the first time, I attempted to write a database in Zig.&lt;/p&gt;

&lt;p&gt;I didn't get far, and eventually I went back to work. And once that happened I abandoned my side project.&lt;/p&gt;

&lt;p&gt;Fast forward to September 2025, after frustration with AI. I decided to write a game in Zig. I decided to use AI as a tutor, and not as something that just hands me answer. I would write the code myself, and AI would be an advisor to teach me game dev.  And its been working out.&lt;/p&gt;

&lt;p&gt;So it gave me the confidence to also create a database in Zig. Yes Zig.  I started writing a dabase in Zig, and even completed a write-ahead log (WAL). Again, AI not writing any code, just advising me, teaching my concepts, and me struggling  through the implementation and code. &lt;/p&gt;

&lt;p&gt;So you may be asking, where is the "and Rust again part"?  Glad you asked. As of June 2026, I find myself unemployed yet again. And I want to get back into infrastructure. So as a career signaling initiative, I decided to write my KV store in Rust. &lt;/p&gt;

&lt;h2&gt;
  
  
  TLDR bro. What are your plans
&lt;/h2&gt;

&lt;p&gt;My plan is to make this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic functionality
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Write Ahead Log implementation&lt;/li&gt;
&lt;li&gt;Memtable and SSTable&lt;/li&gt;
&lt;li&gt;Bloom filter/range queries&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Polish and UI
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;write basic CLI using clap&lt;/li&gt;
&lt;li&gt;maybe a tui to visualize data&lt;/li&gt;
&lt;li&gt;debugging and diagnostic tool chain&lt;/li&gt;
&lt;li&gt;integrated performance monitoring&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Neuromorphic modeling
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;z-curve order indexing&lt;/li&gt;
&lt;li&gt;neuromorphic memory representation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  stretch goal
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;consensus algorithm (RAFT)&lt;/li&gt;
&lt;li&gt;secret feature I don't want to disclose&lt;/li&gt;
&lt;li&gt;create API and kubernetes operator&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Currently I am in a job search, and I am building a game in Zig from scratch. So lots of things to work on. This KV store work will tie into my game, as I have some ambitious ideas around it. So this is important to my overall mission.&lt;/p&gt;

&lt;p&gt;Code for the project is here: &lt;a href="https://github.com/brharrelldev/walbash_db/tree/main/walbash-rust" rel="noopener noreferrer"&gt;https://github.com/brharrelldev/walbash_db/tree/main/walbash-rust&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have any questions feel free to email me at: &lt;a href="mailto:ministerofdefense1979@gmail.com"&gt;ministerofdefense1979@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rust</category>
      <category>database</category>
      <category>kv</category>
      <category>systems</category>
    </item>
    <item>
      <title>Neuromorphic KV store in Zig</title>
      <dc:creator>Brandon Harrell</dc:creator>
      <pubDate>Sun, 01 Feb 2026 20:07:54 +0000</pubDate>
      <link>https://dev.to/brharrelldev/neuromorphic-kv-store-in-zig-4hnc</link>
      <guid>https://dev.to/brharrelldev/neuromorphic-kv-store-in-zig-4hnc</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Hello in 2026 I decided to start a new project in Zig. It's actually a neuromorphic DB engine called Walbash DB.  The name walbash is a play on Wabash. A neighborhood where I grew up in KC&lt;/p&gt;

&lt;p&gt;Walbash is just a play on that.  WAL-Bash.  WAL (Write Ahead Log) and Bash (bourne again shell).  But honestly its just a silly name.  Moving on&lt;/p&gt;

&lt;p&gt;I'm building a game, but I also want an excuse to do something with neuromorphic computing.  I have a design concept using neuromorphic computing with my game that I may reveal later.  But this database is to store synaptic weights to be used for a neuromorphic engine I'm working on&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Zig
&lt;/h2&gt;

&lt;p&gt;I'm not a smart guy. And what I mean by that is that I do like a lot of cognitive load.  I've found in my engineering career that I prefer languages that give me maximum control while be cognitively straightforward.  I remember trying to learn Scala and Rust over the years.  These languages frontload you with features and makes it difficult to be productive&lt;/p&gt;

&lt;p&gt;I work with Go professionally.  But I wanted something low level because that's my interest. So Zig fit the bill.  Odin exists too, but it syntatically is too similar to Go.  Its hard for me to not think I'm not just writing in Go.  Zig introduces a different muscle memory for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why build your own database?
&lt;/h2&gt;

&lt;p&gt;Because I've always wanted to. Just never had a good reason. And its really hard.  Not just to execute, but to learn all the supporting theory. I've read books on databases and found myself just copy and pasting the code without understanding it. Which robs me of learning the "why".  &lt;/p&gt;

&lt;p&gt;AI has been a good way to research and learn on my own time with my own style. So AI is more of a research partner&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is this not being generated with AI?
&lt;/h2&gt;

&lt;p&gt;This is important. First I think the performance I'm going for isn't going to be done well by AI. It's too low level and niche for me to trust its output. Secondly I don't want to robbed of the joy or learn and implementing it myself.  If my repo you will notice markdown files, but they are explicitly told not to generate code. This is very important for me&lt;/p&gt;

&lt;h2&gt;
  
  
  What makes your DB unique?
&lt;/h2&gt;

&lt;p&gt;Absolutely nothing.  It's just a learning exercise. I don't expect competitive features.  This is also for my personal project.  Not really meant to be used by anyone else. I'm blogging this because I just want to share my journey.  It also keeps me on track.&lt;/p&gt;

&lt;h1&gt;
  
  
  How often should we expect updates?
&lt;/h1&gt;

&lt;p&gt;Depending on progress.  I'm starting the DB now so progress is fast.  As I get into Memtables and testing, I expect things to slow down a lot. DB from scratch is hard. I anticipate a lot of testing. I'm also splitting time between my game and my neuromoprhic engine. And this is all being done part time.&lt;/p&gt;

</description>
      <category>zig</category>
      <category>neuromoprhic</category>
      <category>kv</category>
      <category>database</category>
    </item>
    <item>
      <title>Following my passion #2: position vector and learning more Zig</title>
      <dc:creator>Brandon Harrell</dc:creator>
      <pubDate>Thu, 01 Jan 2026 03:20:29 +0000</pubDate>
      <link>https://dev.to/brharrelldev/following-my-passion-2-position-vector-and-learning-more-zig-58fg</link>
      <guid>https://dev.to/brharrelldev/following-my-passion-2-position-vector-and-learning-more-zig-58fg</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Ok, so actually doing some coding for my project on a work night. And boy did I have a busy day at work. I'm in crunch time and I had to debug this really annoying issue with Kafka. Thats a blog for another  time lol&lt;/p&gt;

&lt;h3&gt;
  
  
  Ok moving the square
&lt;/h3&gt;

&lt;p&gt;So yesterday I made a bootstrap Raylib project and it was just drawing a square to the screen. Today the goal was to make the square move. Which I did accomplish&lt;/p&gt;

&lt;h3&gt;
  
  
  How did I do it?
&lt;/h3&gt;

&lt;p&gt;Well I'm going to admit I'm cheating a little. I'm not entirely new to game development. Well at least this isn't my first attempt. I once tried to write a game in C++ in 2024 during a layoff (layoff didn't last long, and I dropped the project once I got a job). So I do know about position vectors to some extent. But since I'm fairly new to Zig this was going to be an interesting challenge&lt;/p&gt;

&lt;h3&gt;
  
  
  Interesting stuff about Zig
&lt;/h3&gt;

&lt;p&gt;So Zig reminds me a lot of Go, but there are obviously some big differences. I tried to introduce a little code structure to my project by keeping a Player struct.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Player = struct{
  .x: usize,
  .y: usize,
  .width: usize,
  .height: usize,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is just to define the position and size of our square on the screen. You'll immediately see and issue if you've worked with Raylib, but I'll get into that.&lt;/p&gt;

&lt;p&gt;Like Go or Rust you can also attach methods to your structs. However unlike Go, your constructor goes inside your struct. In Go you typically have your construct to create and initialize the struct. Which is happening here. But in Go you don't usually have the construct as a function receiver.&lt;/p&gt;

&lt;p&gt;By convention (pretty sure this isn't imposed by the language), you construct your object via the &lt;code&gt;init&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;So it would look something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c"&gt;// initializations are here&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This actually looks pretty similar to Rust. You can optionally do something like &lt;code&gt;const Self = @This()&lt;/code&gt;. This allows you to identify your class reference as a Self or anything you choose. Pretty nice for people who come from other languages. I decided not to go with this though.&lt;/p&gt;

&lt;p&gt;Next I put a draw function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;origin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;Vector2&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;

        &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;Rectangle&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;

        &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drawRectanglePro&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;@as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;f32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;@floatFromInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;white&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here i define the origin as a 2 dimensional vector. And I take my initialization values from the constructor and I update a rectangle. Last I just draw the triangle. But this is all stuff I did yesterday this is just me organizing it better.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;rl&lt;/code&gt; identifier is just an alias to the Raylib library.&lt;/p&gt;

&lt;p&gt;Last there is an update I need to call.  It looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Ok discovering the problems
&lt;/h3&gt;

&lt;p&gt;One thing I did to try to center the square in the middle of the screen was this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getScreenHeight&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getScreenWidth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now this math may be incorrect and I'm sure it is. But the point is that r1.getScreenHeight() returns an i32. But all of the draw square functions from Raylib takes in f32.  So I had to convert them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;@as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;f32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;@floatFromInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getScreenHeight&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;@as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;f32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;@floatFromInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getScreenWidth&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again not perfect due to the precision values now here. But it makes the compiler happy and I plan to fix all of this later.&lt;/p&gt;

&lt;p&gt;The one that was most weird was my update. It couldn't update because it was a constant! Then I remember I have to actually pass the address and update the address. A bit of a quirk, but actually it would have worked the same way in Go. However Go would have made a copy of the struct and updated that. Which wouldn't have been ideal for state reasons. Zig makes everything a constant unless you're explict about it.  So easy fix.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So my code looked like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;     &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isKeyDown&lt;/span&gt;&lt;span class="p"&gt;(.&lt;/span&gt;&lt;span class="py"&gt;d&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginDrawing&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endDrawing&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clearBackground&lt;/span&gt;&lt;span class="p"&gt;(.&lt;/span&gt;&lt;span class="py"&gt;dark_gray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I ended up with a square that could move if hold down the 'D' key.&lt;/p&gt;

&lt;h3&gt;
  
  
  What did I learn
&lt;/h3&gt;

&lt;p&gt;I learned more zig than game dev today. Again today there was just some hours I set aside to sit back and play with this. Tomorrow I am going to try to draw some more squares (yay) and see if I can get my little square to sit on top of them. So looks like I need to learn some lessons in collision detection.&lt;/p&gt;

</description>
      <category>devjournal</category>
      <category>gamedev</category>
      <category>learning</category>
    </item>
    <item>
      <title>Following my passion #3: Long overdue update on animation</title>
      <dc:creator>Brandon Harrell</dc:creator>
      <pubDate>Thu, 01 Jan 2026 02:56:53 +0000</pubDate>
      <link>https://dev.to/brharrelldev/following-my-passion-3-long-overdue-update-on-animation-2d0</link>
      <guid>https://dev.to/brharrelldev/following-my-passion-3-long-overdue-update-on-animation-2d0</guid>
      <description>&lt;h1&gt;
  
  
  Long overdue update
&lt;/h1&gt;

&lt;p&gt;So while I know I have no audience here. I just want to apologize for.a long overdue update. I've been building, I just haven't been blogging. This whole documenting my journey thing is kind of new to me. And I to be better at this.&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's talk about game animation
&lt;/h1&gt;

&lt;p&gt;Ok I am not going to say too much that hasn't been said a lot before. So let's just talk about animation and spritesheets. A lot of games, particularly 2D games rely on spritesheets. This calls back to the old days of flipbook animations.&lt;/p&gt;

&lt;p&gt;In this animation you draw multiple frame images (or frames) and you flip through them giving the illusion of motion. 2D games are pretty similar, but instead of having an actual flip book, you have one big image divided into animation.&lt;/p&gt;

&lt;p&gt;What you do is you take the frames, calculate the offset of them, and then every single frame you cycle through them. Typical games run 60 frames per second.  So if you have a game you must progress the x position that amount of frames.&lt;/p&gt;

&lt;p&gt;So what you would have is first, a frame counter. A max length, and a way to progress the sprite sheet that many pixels.  The math can be tricky but you get the hang of it after a few days of playing around with it.&lt;/p&gt;

&lt;p&gt;I'm not showing any code for this, because well its lost. And I didn't go with spritesheets.  I had build an animation system for an asset with sprite-sheets, and then scrapped it after a month or so.  I'll explain the pivot and the alternative.&lt;/p&gt;

&lt;h1&gt;
  
  
  Closing
&lt;/h1&gt;

&lt;p&gt;Bit of a cop out, but I want to keep these brief and digestible. When I try to cram too much in one blog post I can lazy about keeping these update. So I've decided to split this topic up to keep it more manageable.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>devjournal</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Following my passion #2: position vector and learning more Zig</title>
      <dc:creator>Brandon Harrell</dc:creator>
      <pubDate>Tue, 16 Sep 2025 02:05:55 +0000</pubDate>
      <link>https://dev.to/brharrelldev/following-my-passion-2-position-vector-and-learning-more-zig-bm</link>
      <guid>https://dev.to/brharrelldev/following-my-passion-2-position-vector-and-learning-more-zig-bm</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Ok, so actually doing some coding for my project on a work night. And boy did I have a busy day at work. I'm in crunch time and I had to debug this really annoying issue with Kafka. Thats a blog for another  time lol&lt;/p&gt;

&lt;h3&gt;
  
  
  Ok moving the square
&lt;/h3&gt;

&lt;p&gt;So yesterday I made a bootstrap Raylib project and it was just drawing a square to the screen. Today the goal was to make the square move. Which I did accomplish&lt;/p&gt;

&lt;h3&gt;
  
  
  How did I do it?
&lt;/h3&gt;

&lt;p&gt;Well I'm going to admit I'm cheating a little. I'm not entirely new to game development. Well at least this isn't my first attempt. I once tried to write a game in C++ in 2024 during a layoff (layoff didn't last long, and I dropped the project once I got a job). So I do know about position vectors to some extent. But since I'm fairly new to Zig this was going to be an interesting challenge&lt;/p&gt;

&lt;h3&gt;
  
  
  Interesting stuff about Zig
&lt;/h3&gt;

&lt;p&gt;So Zig reminds me a lot of Go, but there are obviously some big differences. I tried to introduce a little code structure to my project by keeping a Player struct.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Player = struct{
  .x: usize,
  .y: usize,
  .width: usize,
  .height: usize,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is just to define the position and size of our square on the screen. You'll immediately see and issue if you've worked with Raylib, but I'll get into that.&lt;/p&gt;

&lt;p&gt;Like Go or Rust you can also attach methods to your structs. However unlike Go, your constructor goes inside your struct. In Go you typically have your construct to create and initialize the struct. Which is happening here. But in Go you don't usually have the construct as a function receiver.&lt;/p&gt;

&lt;p&gt;By convention (pretty sure this isn't imposed by the language), you construct your object via the &lt;code&gt;init&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;So it would look something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c"&gt;// initializations are here&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This actually looks pretty similar to Rust. You can optionally do something like &lt;code&gt;const Self = @This()&lt;/code&gt;. This allows you to identify your class reference as a Self or anything you choose. Pretty nice for people who come from other languages. I decided not to go with this though.&lt;/p&gt;

&lt;p&gt;Next I put a draw function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;origin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;Vector2&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;

        &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;Rectangle&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;

        &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drawRectanglePro&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nb"&gt;@as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;f32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;@floatFromInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;white&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here i define the origin as a 2 dimensional vector. And I take my initialization values from the constructor and I update a rectangle. Last I just draw the triangle. But this is all stuff I did yesterday this is just me organizing it better.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;rl&lt;/code&gt; identifier is just an alias to the Raylib library.&lt;/p&gt;

&lt;p&gt;Last there is an update I need to call.  It looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Ok discovering the problems
&lt;/h3&gt;

&lt;p&gt;One thing I did to try to center the square in the middle of the screen was this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getScreenHeight&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getScreenWidth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now this math may be incorrect and I'm sure it is. But the point is that r1.getScreenHeight() returns an i32. But all of the draw square functions from Raylib takes in f32.  So I had to convert them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;@as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;f32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;@floatFromInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getScreenHeight&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;@as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;f32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;@floatFromInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getScreenWidth&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again not perfect due to the precision values now here. But it makes the compiler happy and I plan to fix all of this later.&lt;/p&gt;

&lt;p&gt;The one that was most weird was my update. It couldn't update because it was a constant! Then I remember I have to actually pass the address and update the address. A bit of a quirk, but actually it would have worked the same way in Go. However Go would have made a copy of the struct and updated that. Which wouldn't have been ideal for state reasons. Zig makes everything a constant unless you're explict about it.  So easy fix.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So my code looked like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;     &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isKeyDown&lt;/span&gt;&lt;span class="p"&gt;(.&lt;/span&gt;&lt;span class="py"&gt;d&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginDrawing&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endDrawing&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clearBackground&lt;/span&gt;&lt;span class="p"&gt;(.&lt;/span&gt;&lt;span class="py"&gt;dark_gray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I ended up with a square that could move if hold down the 'D' key.&lt;/p&gt;

&lt;h3&gt;
  
  
  What did I learn
&lt;/h3&gt;

&lt;p&gt;I learned more zig than game dev today. Again today there was just some hours I set aside to sit back and play with this. Tomorrow I am going to try to draw some more squares (yay) and see if I can get my little square to sit on top of them. So looks like I need to learn some lessons in collision detection.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Following my passion #1: Raylib, Zig and the Square on screen</title>
      <dc:creator>Brandon Harrell</dc:creator>
      <pubDate>Sun, 14 Sep 2025 22:07:50 +0000</pubDate>
      <link>https://dev.to/brharrelldev/following-my-passion-1-raylib-zig-and-the-square-on-screen-5eii</link>
      <guid>https://dev.to/brharrelldev/following-my-passion-1-raylib-zig-and-the-square-on-screen-5eii</guid>
      <description>&lt;p&gt;Hello, my name is Brandon and I am a Senior Software Engineer/Architect. By day I do event driven programming in Golang. I am mostly a professional programmer, and usually don't finish many personal projects. I hope to change that.&lt;/p&gt;

&lt;p&gt;My 30+ year software engineering journey&lt;/p&gt;

&lt;p&gt;I started to learn programming at the age of 14. Way back in the 90s. I wanted to learn how to program for one reason only. &lt;/p&gt;

&lt;p&gt;TO MAKE GAMES&lt;/p&gt;

&lt;p&gt;I ended up not being a game dev. After a really rough start in my career in the early 2000s, I pivoted to Java programming and production support at banks and financial service companies. Then I moved into the telecoim realm. And I have worked on and built many many large skill systems.&lt;/p&gt;

&lt;p&gt;I'm not the best in the world but I think I know my domain of programming pretty well. And I've always wanted to do personal projects but I just procrastinate or never stick with it.  This year I plan to change that.&lt;/p&gt;

&lt;h3&gt;
  
  
  September 13, 2025: The journey begins
&lt;/h3&gt;

&lt;p&gt;Ok, ok. So today technically is September 14th, but yesterday I just did planning and design. Today I put some hands on keyboard. So it's my first day actually making my game idea tangible.&lt;/p&gt;

&lt;p&gt;Why is September 13th so important? Well its my birthday. I won't go into my personal life, but 2025 has been a year of reflection. And it has not been the smoothest year.  Quite the opposite. I've been doing some major soul searching. &lt;/p&gt;

&lt;p&gt;I turned 46. I'm seeing the threat of AI on my profession. And if our AI overlord take us over, it will be humans leaning into creativity who will move forward.  So that's what I'm doing. I'm being an artist. Reverting to my 14 year-old self, and rediscovering my passion for game programming.&lt;/p&gt;

&lt;h3&gt;
  
  
  Yeah I love gaming, but I'm not a game developer
&lt;/h3&gt;

&lt;p&gt;I've been interested in Zig for a few years.  And I've always had an interest in game dev. So here we are. Learning both in this year. My MVP is to have the first stage done.  &lt;/p&gt;

&lt;p&gt;So the goal is to learn game development and Zig all within this year. It will be a fun journey I think.&lt;/p&gt;

&lt;h3&gt;
  
  
  So how is it going so far?
&lt;/h3&gt;

&lt;p&gt;Well I've been using Google Gemini AI as a bit of a sounding board. Its been helping me fill in some of the gaps of my game development. But I gave it explicit instructions not to write any code for me. Just to kind of go over different concepts and ideas with me. Its been going well. I call him "Lil Homie Jimmy".&lt;/p&gt;

&lt;p&gt;At first  I wanted to use the Mach Engine&lt;a href="https://dev.tourl"&gt;https://machengine.org/&lt;/a&gt;. But it uses Zig nightly builds and nominates a build. It's also locked into the ECS pattern, which is probably not a horrible thing for what I'm going to be doing. But I think the Zig build nomination makes my workflow so cumbersome, especially since its only on Zig 0.14. It makes more sense to be on 0.15 and it also doesn't break my toolchain (like ZLS).&lt;/p&gt;

&lt;p&gt;So I decided on Raylib. It has a lot of examples in many many languages. So its a great choice for someone who is a novice game dev.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fqs1strtdw99o3f5o0tys.png" class="article-body-image-wrapper"&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%2Farticles%2Fqs1strtdw99o3f5o0tys.png" alt=" " width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is what I have so far. It took all day to do this. So not the best start.  But this square will serve as a hitbox for my eventual character. This will be a 2D game and an action platformer, so collision detection will make a huge difference here.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the game idea?
&lt;/h3&gt;

&lt;p&gt;Its going to be a 2D action platformer. That's all I can say now. And I want to put a big emphasis on boss battles. I think there is a good idea here, but I kind of want to see it to completion before I say too much.&lt;/p&gt;

&lt;h3&gt;
  
  
  So how are we going to move forward?
&lt;/h3&gt;

&lt;p&gt;Well tomorrow I want to start doing some stuff with the user input. This shouldn't take too long to complete. But it will probably introduce me to some stuff like vector geometry. That's my goal for tomorrow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;If all goes well, this time next year will be my #365th entry. My issues is sticking with stuff, so this is a habit I'm going to hav eto try to break this year.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>gamedev</category>
      <category>zig</category>
    </item>
    <item>
      <title>Learning Zig, day #1</title>
      <dc:creator>Brandon Harrell</dc:creator>
      <pubDate>Wed, 05 Jun 2024 12:17:53 +0000</pubDate>
      <link>https://dev.to/brharrelldev/learning-zig-day-1-g6l</link>
      <guid>https://dev.to/brharrelldev/learning-zig-day-1-g6l</guid>
      <description>&lt;h1&gt;
  
  
  The why
&lt;/h1&gt;

&lt;p&gt;So I have decided to learn Zig. This is kind of an odd decision because I have never had any interest in Zig. But I have had an interest in Rust for years.  Just a little about my background.  I am a professional Go developer (well was I've been unemployed for 2 weeks). And during my downtime I decided to pick up a new programming language. This will be the 4th professional language I've learned. My first professional language being Java, then Python years later, now Go for the last 8 years. &lt;/p&gt;

&lt;h2&gt;
  
  
  Toy Program to get started
&lt;/h2&gt;

&lt;p&gt;Anyway I plan writing my own message broker.  And for no reason other to see if I can. One of my favorite simple things to write in Go are TCP sockets. So figuring out how to do that in Zig was a priority, surprisingly it's not too bad.&lt;/p&gt;

&lt;p&gt;So first they suggest that I create a new &lt;strong&gt;&lt;em&gt;Ip4Address&lt;/em&gt;&lt;/strong&gt;. Here it is below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;    &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;addr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;Ip4Address&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alright not too painful. I then have to initialize an &lt;strong&gt;&lt;em&gt;Address&lt;/em&gt;&lt;/strong&gt;. This is a struct that takes in an Ip4Address, which I created above. So my next step kind of looks like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;   &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="n"&gt;local_addr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;{.&lt;/span&gt;&lt;span class="py"&gt;reuse_port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
   &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deinit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what's happening here is pretty cool.  We call the "listen" method. Because this can return an error, we call it with "try". This looks suspiciously like an exception. But not to worry, errors are values in Zig, just like Golang.  This can alternatively be written like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;local_addr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;{.&lt;/span&gt;&lt;span class="py"&gt;reuse_port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;|{&lt;/span&gt;
       &lt;span class="c"&gt;//handle value&lt;/span&gt;
 &lt;span class="p"&gt;};&lt;/span&gt;
 &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deinit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the &lt;strong&gt;try&lt;/strong&gt; semantic is kind of syntactic sugar. Since I'm new to the language and this was my first day using it, I just went with try, but I can see using the "catch" version for better debugging and logging.&lt;/p&gt;

&lt;p&gt;Now finally I'm ready to accept a connection, so lets start our loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;readAllAlloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader_allocator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{s}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="n"&gt;reader_allocator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we use the "try" syntactic sugar again. Then we obviously read from our connection.  What's important is the "readAllAlloc" call. It takes an allocator, and a size which is the size of the allocator.  I actually define an "allocator" earlier.  I won't get too much into allocators because I only have a super basic understanding of them.  But essentially instead of the ownership and borrow checker model found in Rust, we instead can create an allocator structure.  We can clean it up whenever we want, but it's usually done via a &lt;strong&gt;defer&lt;/strong&gt;. I'm in a an infinite loop, meaning this will never reach the end of the function.  So I an deallocating manually with &lt;code&gt;reader_allocator.free(message)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Here is the fully code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;@import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"std"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;net&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;print&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;gpa&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GeneralPurposeAllocator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;{}){};&lt;/span&gt;

    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="mi"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gpa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deinit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;reader_allocator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gpa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;allocator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;addr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;Ip4Address&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;local_addr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;Address&lt;/span&gt;&lt;span class="p"&gt;{.&lt;/span&gt;&lt;span class="py"&gt;in&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;addr&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="n"&gt;local_addr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;{.&lt;/span&gt;&lt;span class="py"&gt;reuse_port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deinit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;readAllAlloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader_allocator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{s}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="n"&gt;reader_allocator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Thoughts and review so far
&lt;/h2&gt;

&lt;p&gt;So playing around with Zig is actually pretty fun. I've had a lot of false starts with Rust, and it's just hard to get started with.  But Zig I was able to just start writing code right away. Zig, while simple, does have a learning curve.  But it seems to not be wearing its concepts on its sleeve like Rust. I also think the allocator strategy is genius.  And while the Rust borrow checker is also an incredibly good idea, it can make the ownership semantics extremely difficult to work with.&lt;/p&gt;

&lt;p&gt;Clearly my program will need some improvements. While this compiles and works, I'm not sending anything back to the client. I also need to build a client as well.  Probably put the server in its own package.  And I need to figure out what to do with this allocator, because calling it in a loop probably isn't incredibly safe.  So I may need to free up memory based on a few conditions, like after a response to the client.&lt;/p&gt;

&lt;p&gt;Anyway it's not everyday I'm excited about a new language.&lt;/p&gt;

</description>
      <category>zig</category>
      <category>vim</category>
      <category>neovim</category>
      <category>go</category>
    </item>
  </channel>
</rss>
