Zig NEWS

Discussion on: Beware the copy!

Collapse
 
david_vanderson profile image
David Vanderson

Great write up! I had a similar experience - it took me a while to realize that obj.foo() works the same way and could pass a copy of obj.

It was surprising enough that I proposed changing zig:
github.com/ziglang/zig/issues/13249

Trying to implement the proposal showed it wasn't as good as I hoped.

This is one of those things that people (at least me!) have to learn through experience and reading writeups like this!

Collapse
 
gowind profile image
Govind

Interesting issue. I admit that one area where Zig (or Zig documentation) fails big time is with memory, more specially when copies are made and when they aren't. In Rust, this is more explicit due to this being in the type, but in Zig, for ex, when you have an ArrayList(SomeStruct) and try to do append, you are making a copy of SomeStruct which is the one that ends up being added to the ArrayList. For a lot of us who come from memory managed languages, understanding all this nuance without docs explaining why is a big learning curve before feeling comfortable with Zig.