Should the Error enum even exist? #11944
Niriel
started this conversation in
Engine Core
Replies: 2 comments
-
Actually, |
Beta Was this translation helpful? Give feedback.
0 replies
-
A lot of methods return an Error type, especially those that handle parsing text and file system stuff. And yes, it is an int internally, but all enums are and they're a rather thin abstraction to begin with. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
TL;DR
I feel like there may be a little cleaning up to do. Maybe it's just a matter of documentation.
We have an
Error
enum, but nothing uses it yet. Functions that semantically could return anError
still return anint
instead. For example,signal.connect
could returnError
instead ofint
.It's not a big deal, but to me it feels messy. It also misses some advantages of strongly-typing in GdScript.
The long, overly detailed, explanation
The global scope contains an enum
Error
that lists 49 of error-code names and their corresponding integer value. For some reason, all that information is duplicated in the global scope: there are also 49 integer global-scope constants with the same values.Good strongly-typed code
Look at this code. It is perfectly typed. No complains from the parser, no warning upon execution. Using
Error
makes the intent clear and the code is self-documenting.Of course, in the end, we know it's all
int
. Place a breakpoint on theprint
line, and you'll see err in the local displayed as an int. Fine. Error isn't real, it's a type-checking tool that helps the developers.Weird code that GdScript forces us to write
Now, look at this code. This raises a warning during execution.
We get the following warning when we hit
err = pause_changed.connect()
:This makes sense because
signal.connect
returns anint
. But from the documentation, we can clearly see that the possible return values are part of theError
enum.This code must be changed to:
Which entirely defeats the point of
Error
existing. Why does theError
enum even exist when built-in functions and methods don't use it?Suggestion
It feels like a dev in the past started to move from
int
toError
but never finished the work. Either we continue that work, or we revert it.Error
, and we compare with theError
enum (if err == Error.ERR_INVALID_PARAMETER
);Error
enum, keep all the integer constants, and our functions return integer like in the old times.Beta Was this translation helpful? Give feedback.
All reactions