Post #487541
2026-02-27 21:39 UTC
So while getting familiar with the oddities of GDScript i noticed that it really doesn't have much in way of handling errors as a language feature. So while most languages I'm familiar with use try-catch statements, there just isn't anything. I hate returning nulls or sentinel values from functions so... I took a page from Rust's design and implemented `Result`.
Now if I'm doing an operation where I would want to generate an error to notify the calling function you did something bad, I am in a more functional paradigm.
Attached is a unit test around some bit reading using the `Result` and a match function that will pass along either the value or error message as needed. Second picture is the match function, it is pretty simple. A great use case for Monads overall.
Trying to find information on error handling in GDScript lead to a lot of "Just don't write code with errors in it" advice... which is frankly unrealistic and unhinged. It is okay to admit a language has some missing features.
#godot #rustlang #programming
Replies (2)
-
@patricktcoakley@mastodon.gamedev.place 2026-02-27 21:45
@Aut A lot of the discourse around GDScript is coming from beginners or people without deep programming experience, so that's probably why you don't see it come up as often. This is often why a lot of people opt for C# despite the deficiencies it might have with Godot because it's still just a normal general-purpose programming language using the standard .NET toolchain.
-
@schrockwell@mastodon.social 2026-02-28 01:04
@Aut I made a Result class for a Rails project and it makes business logic SO much nicer to grok. Looks very similar to this.