3 ms·
> Zig forces you to pass the allocator in, so you might as well think about the most appropriate one! I really feel like this is an underappreciated aspect of
by csnover 4y ago
> Zig forces you to pass the allocator in, so you might as well think about the most appropriate one!
I really feel like this is an underappreciated aspect of some of the more complained-about constraints that these newer languages place on programmers.
Like an i32, the default allocator will do a reasonable thing most of the time, but having to think about each allocation (is this short-lived or long-lived? is it actually necessary to do a heap allocation at all here? do you actually want GC?) makes code better and pushes the programmer to improve their ability to rationalise about what they’re actually doing in ways that provide tangible benefits.
By way of comparison, when I started writing Rust I was very frustrated by all the explicit conversions, but eventually realised that it (a) forces me to actually stop and think about what the most natural type is for a given value, and (b) also makes it clearer where the natural boundaries are between components. In my experience, if there’s a lot of conversion going on within a function or module, it’s usually not because the language is ‘too verbose’. Instead, it’s because the API boundaries are in the wrong places, and the language has helped to reveal this by making doing the wrong thing harder.
- kaba0 4y agoAd absurdum that would make assembly a better choice — we can just as well reason about better register allocation strategies. I think the fundamental abstraction level is very important to get right. Of course it depends on the problem domain, and it might just make sense for Zig to expose explicitly allocators everywhere, but maybe some implicitly passed allocator when not otherwise specified could be a better trade off (correct me if it is a thing)