Hacker News
points by winrid 1 day ago | 0 comments
That's because in Zig that would be seen as a surprise side effect - the allocator is expected when the action is performed, not when it's "prepared", this way you know append() allocates. Otherwise it wouldn't be explicit which Array methods allocated.

The Odin way is useful, too. Depends on what you're building.

[–] brabel 1 day ago
The whole argument that you always know when Zig allocates is just wrong, as this shows. They “fixed” the hidden allocation by making it explicit in the append function but now you can pass in the wrong allocator. Not great is it? It is just all so fragile and relying on convention rather than hard checks. People sometimes pursue a bad idea to incredible lengths and then everything else is justifiable based on that initial, bad idea that just causes much more pain than it solves.
[–] winrid 1 day ago
What do you mean wrong allocator? What if you want to use a different one (will it work?)
[–] philippta 1 day ago
If the array list has enough capacity, you don't know if it allocated or not.