News for hackers. Stuff that matters.
Re:Making your own programming language is easier than you t... by hyper_frog on Sunday May 10, 2026 @01:41AM (#48081312)
Any reasons for not using odin? It seems great for gamedev
Re:Making your own programming language is easier than you t... by Panzerschrek on Sunday May 10, 2026 @01:44AM (#48081334)
Odin has no destructors. That's a fatal flaw.
Re:Making your own programming language is easier than you t... by hyper_frog on Sunday May 10, 2026 @02:19AM (#48081464)
well neither does C or zig right? but zig and odin do offer defer, which should be good enough while maintaining simplicity right?
Re:Making your own programming language is easier than you t... by Panzerschrek on Sunday May 10, 2026 @02:58AM (#48081625)
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).
Re:Making your own programming language is easier than you t... by cv5005 on Sunday May 10, 2026 @08:55AM (#48083610)
>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?

Re:Making your own programming language is easier than you t... by Panzerschrek on Sunday May 10, 2026 @09:38AM (#48083894)
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.