I LIKE ZIG P1
Hi, I have been learning Zig for about a month, and here are some things I really like about it:
Type System:
In real life, not in the 2^n world of computers, we encounter many types of numbers.
Such as:
- The number of members in a class: 30~200
- The number of days in a year: 365-366 (I wish we had more LoL)
- The number of seats in a football stadium
- ….
We can easily define such numbers in any programming language, but wait… In almost programming languages, we are usually constrained to specific types to store numbers. For instance, in Java:
- byte: 8 bits -2^7 ~ 2~7
- short: 16 bits which means from -2^15 ~ 2^15 (why 15, because we lost 1 bit for the fucking useless “-”)
- int: ….
- long …
These are all designed for the "2^n world." However, the creators of these languages don't give us much flexibility when it comes to defining numbers that fall between those power-of-two boundaries, like 2^7 → 2^15.

- But in zig, this issue (many people will argue with what I say) will be resolved. This fact is from ziglang.org
In addition to the integer types above, arbitrary bit-width integers can be referenced by using
How beautiful is that. That means you can have some custom integer types. I think it is so simple but yet not many languages allow or encourage us to do this. Plus, in zig and some languages, you have unsigned integer which means ≥ 0 integer, this helps you save a bit by this fucking useless “-” where negative values are not required.
Here's a simple example: Suppose I need a variable to store the number of students in a class. I know for certain that this number will never exceed 60 (let's say it's a rule enforced by the school’s organizing system).
Result:
This is how zig helps us save memory!!!
Anonymous struct
If you're using Zig, have you tried using anonymous structs?
Anonymous structs are very useful when you need a struct for one-time use.
For example, they are great for test code or in functions where you need to interact with or return a struct, but that struct is only used once. In such cases, using an anonymous struct keeps the code concise and avoids cluttering your namespace with unnecessary type definitions.
Many other languages have this feature too (though I’m not sure how to use it in some of them 😅).
Example:
Alright guys, That is enough for this time. I would like to write more but, time does not permit. I will write about union and enum in zig in the next topic. Thank you.