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

I've used both to work on a hobby OS project (Nim[1], Zig[2]). I very much prefer Nim. Code is succinct, elegant, and lets you focus on your core logic rather than fighting the language.

Zig is nice and I like its optionals support and error handling approach. But I was put off by its noisy syntax, e.g. !?[]u8 to represent an error union of an optional pointer to a many-pointer of uint8. Also having to prepare and weave allocators throughout most of the code that needs to dynamically allocate (which is most of the code) gets in the way of the main logic. Even little things like string concatenation or formatting becomes a chore. Zig also doesn't have dynamic dispatch, which makes polymorphic code hard to write; you have to work around it through some form of duck typing. In the end I realized that Zig is not for me.

[1] https://github.com/khaledh/axiom [2] https://github.com/khaledh/axiom-zig



Couldn't edit my post, but forgot to mention my main pain points with Nim have been:

- its module system, especially not being able to have mutually recursive imports (there has been a 7 year old proposal[1])

- order-sensitive declarations of procs (i.e. can't use a proc defined further down in the file unless you add a forward reference to it). For the latter there's an experimental pragma[2], but it doesn't work a lot of times once you introduce mutually recursive calls

- object variants requiring declaration of a separate enum instead of allowing inline declaration of the variant cases, and a close issue[3] with not being able to define the same field names under different variant cases.

[1] https://github.com/nim-lang/rfcs/issues/6

[2] https://nim-lang.org/docs/manual_experimental.html#code-reor...

[3] https://github.com/nim-lang/RFCs/issues/19


You might like Patty. It makes case types more ergonomic: https://github.com/andreaferretti/patty


Neat! Thanks for sharing. This might come in handy, although the constraint of unique field names across variant cases is still there.


Yah it's annoying, but I just rename one. Beff331 made a lib that uses tuples and avoids the naming issue: https://github.com/beef331/fungus


If I recall correctly, lazy symbol resolution, which would allow both circular module imports and order-independent procs, was initially on the roadmap for 2.0. Currently, it was moved to a stretch goal for 2.2.

https://github.com/nim-lang/RFCs/issues/503


> Zig also doesn't have dynamic dispatch

It doesn't have it as a language feature, but it does have VTables just like C would. The `std.mem.Allocator` is an example of this.




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

Search: