Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've played with it for a few hours now and it feels promising. But also very hard to get into. There is not a lot of documentation nor code examples to look at. I'm trying to write the equivalent of int main(...) { for (int i = 0; i < argc; i++) { for (int j = 0; j < strlen(argv[i]); j++) { printf("%d %d %c\n", i, j, argv[i][j]); } } } in Zig, but figuring out how to do formatted output in the language wasn't so easy.

Another small annoyance was Zig rejecting \r in line endings. Thankfully, I'm using Emacs so it only took me 15 minutes to google the right fix. But it felt a little "gratuitous" if you know what I mean.



Here is a repository with a few more small code examples which may be helpful: https://github.com/tiehuis/zig-rosetta

The code itself should be up to date for most, but I'm aware of a few examples than need touch-ups. Unfortunately there is a bit more boilerplate compared to other languages for some simple tasks, since Zig requires you to be quite explicit about things (e.g. i/o, memory allocation).

Regarding the rejection of '\r', there is the intention for `zig fmt` to handle these minor issues and reformat code as needed which hopefully reduces this barrier. There was a long issue regarding hard tabs with discussion here: https://github.com/ziglang/zig/issues/544




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: