4 ms·
> No destructors. What's the logic behind this? It's nice to have a way to pair resource usage with disposal. Or does the linear type system allows not to forg
by solomatov 3y ago
> No destructors.
What's the logic behind this? It's nice to have a way to pair resource usage with disposal. Or does the linear type system allows not to forget about the resources which have to be closed.
- olodus 3y agoYes, the compiler will remind you if you haven't cleaned up a value of linear type. The 'no destructor' rule follows the 'no hidden flow' design, similar to Zig. Some doesn't like it, but personally I prefer it.
- solomatov 3y agoYep, I agree with you that it's better to be explicit than implicit here. Initialization/destruction order is often tricky, and source of obscure bugs.
- ZoltanAK2 3y agoIndeed, the linear type systems makes sure that you won't forget to dispose of resources. Linear types enable manual memory management without memory leaks, use-after-free, double free errors, garbage collection, or any runtime overhead in either time or space other than having an allocator available. More generally, it enables us to manage any resource (file handles, socket handles, etc.) that has a lifecycle without letting us forget to dispose of the resource (e.g. leaving a file handle open), dispose of it twice, or use it after disposal (e.g. reading from a closed socket), all without runtime overhead. The Austral tutorial's chapter on linear types (https://austral-lang.org/tutorial/linear-types https://austral-lang.org/tutorial/linear-types) explains how this works in a fairly clear way.