Hacker News new | ask | show | jobs
by hyper_frog 47 days ago
Any reasons for not using odin? It seems great for gamedev
1 comments

Odin has no destructors. That's a fatal flaw.
well neither does C or zig right? but zig and odin do offer defer, which should be good enough while maintaining simplicity right?
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).
>One need to write it manually each time in each function where some cleanup is needed.

You can structure your code to not need cleanup in every function.

The biggest problem with destructors is, how do you handle errors? close() can fail you know?

Usually destructors can't fail. But for rare cases like with close() you can write a helper function (static method) which destroys the given object and returns an error if has one.