3 ms·
Destructors are good. Though if the language does not have unwinding, catchable panics you could be even better served with linear types. Constructors, though,
by masklinn 5y ago
Destructors are good. Though if the language does not have unwinding, catchable panics you could be even better served with linear types.
Constructors, though, are solely an attractive nuisance.
For the constructors themselves you're better off with factory function whose semantics match your needs (fallibility, or the lack thereof, being a big one) and for other protocols (e.g. copy, move, conversion, ...) you're better off either not having them or having dedicated protocols which are clearly and explicitly opt-in, depending on language semantics.
> I am always amazed when a new language omits destructors.
Destructors require deterministic destruction, so that only works for non-managed languages. That's why managed languages try to find alternative solutions to the resource problem (except for languages used to research substructural typing I guess, as well as languages which mandate refcounting as part of their semantics).