2 ms·
>The idiomatic way to handle that is with some combination of `defer` and `errdefer`. Then, in code, there are no lines between alloc/free, and if a try would e
by pod_krad 2y ago
>The idiomatic way to handle that is with some combination of `defer` and `errdefer`. Then, in code, there are no lines between alloc/free, and if a try would exit before the free then you would instead first free anyway.
Do I understand correctly, that talking about idiomatic way is the same as talking about programming style, but not about language semantic?
- hansvm 2y agoCorrect. Much like in Python or C, you can explicitly handle every error/break/early-return condition and manually free the resource. Each language offers a tool to make that easier (and more likely to be correct, especially as the code changes) in most cases though. In Python it's try/finally, in C it's `goto ERR`, and in Zig it's defer/errdefer.
- pod_krad 2y agoSo, you can't rely that someone will follow that style in Zig. That is my point.