logoalt Hacker News

hyper_frogtoday at 6:19 AM1 replyview on HN

well neither does C or zig right? but zig and odin do offer defer, which should be good enough while maintaining simplicity right?


Replies

Panzerschrektoday at 6:58 AM

defer is not a proper replacement for destructors. One need to write it manually each time in each function where some cleanup is needed. It's easy to forget to do so or to do this in a wrong way. Destructors in the other hand are called automatically and all cleanup logic is written exactly once (within destructor body).

show 1 reply