Zig, like many ‘modern’ languages uses postfix typing. This means that when you declare a variable, the type of the variable goes after the name. So you see:
const is_foo: bool = true;
Here we see that is_foo
has the type of boolean variable. This postfix annotation is in contrast to prefix annotation where the type comes before the name. You will see this in languages like C.
bool isFoo = true;
However, a further nice feature of zig’s type system is that it is almost strictly read from left to right. This means that when you read zig code, you can grasp your types in a natural way (or at least natural if you are used to reading from left to right). For example, lets take a look at the following type:
const bar: [20]**u32 = undefined;
This can be pronounced as “bar is an array of 20 pointers to pointers to u32’s”. I don’t think i’m overstating how nice it is. When it is easy to name what things are, it makes our ability to reason about them easier. And when the names are read just as they are written it makes it easier to know what we are dealing with. Contrast this with C’s notorious spiral type system. A similar declaration above would be written as (example lifted from the aforementioned link):
uint32_t **bar[20]
There is, however, one ‘class’ of types in zig, that I find breaks this strict “left-to-right” pronunciation rule. It is the “sentinal-terminated-slice/sentinel-terminated-array” type. In zig you can show that an array is terminated by a “sentinel” value. This value is almost always 0, (for null terminated arrays), but it doesn’t have to be. To indicate such a slice or an array you use the following syntax:
const sentinel_array: [10:0]u8 = undefined;
Notice that in the array we specify the length (10) and then that it has a sentinel value using the colon. Here the sentinel value is 0. However this syntax introduces a slight inversion of the pronunciation. I would read this as “sentinel_array is a zero-terminated array of 10 u8’s”. Notice how the zero terminator qualification comes before the size of the array. I’ve scratched my head for other ways to read it that follow the left-to-right rule but none of them seem quite natural. Thankfully, it is pretty easy to get a grasp of this one deviation from the general rule.