I did this project to learn zig. The existing cmake formatters are all written in python for some weird reason which makes them annoying to use/keep e.g., they break every time my distro updates.
Overall, I think Zig is nice to use and pragmatic. It took maybe a couple of hours before I was comfortably coding in the language. The things that annoyed me:
std.debug.print is annoying AF. Typing in .{} every single time for the second arg is frustrating. I worked around it by using editor snippets.
std.ArrayList() doesn’t provide a [] operator. Gets me everytime I use it. Really bad ergonomics. Lack of an emptyness checking function felt weird initially, but not a big deal.
Would love some way to alias a specialization of a function. Perhaps there is already a way to do it? Something like: const stringEqual = std.mem.eql(u8, _, _);
The anon/nested function workaround where you return a function from a struct and store it in a var is just bad with horrible ergonomics. But at least there is a way to do it.
Errors messages can sometimes be very confusing.
Test failure output is hard to read for me. It always takes me a while to find out which case is failing.
std.ArrayList() doesn’t provide a [] operator. Gets me everytime I use it. Really bad ergonomics. Lack of an emptyness checking function felt weird initially, but not a big deal.
I would lie if I said it doesn’t get me sometimes as well. However, It makes sense. [] syntax is limited to arrays and slices. In general, once I know I’m done growing an arraylist, I’ll usually call toOwnedSlice() on it and just pass around the slice.
Would love some way to alias a specialization of a function. Perhaps there is already a way to do it? Something like: const stringEqual = std.mem.eql(u8, _, _);
You can achieve this with just a regular helper function:
std.debug.print is annoying AF. Typing in .{} every single time for the second arg is frustrating. I worked around it by using editor snippets.
Yeah, that’s the price we pay for not having function overloading. You could probably also make helper functions print0, print1, … which has other downsides of course.
/// Contents of the list. This field is intended to be accessed
/// directly.
///
/// Pointers to elements in this slice are invalidated by various
/// functions of this ArrayList in accordance with the respective
/// documentation. In all cases, "invalidated" means that the memory
/// has been passed to an allocator's resize or free function.
items: Slice = &[_]T{},
I also can’t commit print(…, .{}) into muscle memory. Just too many years of experience with printf (C) and print (Python). I workaround this a bit in VSCode by using a snippet for std.debug.print() which helps a bit.
It only works if the text editor supports the LSP snippet format. Afaik, only vscode and neovim-coc support it fully. I use Kate (I happen to be one of its core devs), which supports a small subset of the said snippet format and thus it doesn’t work that well.
I use it from zls on VSCode. Not that I enjoy using snippets for something like this as it feels to me more like a language ergonomics issue than an editor/muscle memory thing. But I’m probably in the minority with this opinion.