3 ms·
I agree here. I really like what Zig has done with pointer types. I wrote about it here [0]. What I like most is that all the types consistently read from left
by cturtle 4y ago
I agree here. I really like what Zig has done with pointer types. I wrote about it here [0]. What I like most is that all the types consistently read from left to right, and there are types that encode the cardinality of a pointer unlike C. I wonder what you or others think about Zig’s pointers syntax.
[0]: https://nathancraddock.com/blog/consistency-in-zigs-type-system/#simple-types https://nathancraddock.com/blog/consistency-in-zigs-type-sys...
- chongli 4y agoI can’t even get past the simple values syntax: var value: i32 = 0; This looks like you’re assigning the value 0 to i32, a type. It’s nonsensical. Also what is the purpose of the var keyword? Why not put the type there? The array syntax makes even less sense! I think what you’re missing in your examples is how the values are used after declaration. C syntax was designed so that declaration resembles use. The reason array subscript brackets come after the variable name is because that’s how you access elements of the array: int arr[3] = { 12, 76, -42}; arr[1] += 4; if (arr[2] < 0) { printf(“it’s negative!\n”); }
- glouwbug 4y agoSame goes for pointers. int *foo = &bar; *foo = 1; As far as syntax goes, tying the pointer to the identifier doesn't make sense to me, at least. Pointers associated with types makes much more sense: int* foo = &bar; C++ thinks so too.