Replies: 1 comment
-
Thank you for your proposal, consolidating in: And a few other related proposals already open |
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
-
Currently all GDScript functions can be overridden at will. I however propose that in the future, GDScript functions that should be overridable need to be marked with
@virtual
or a similar annotation, e.g. previously:Now:
In this example, the class
MyClass
defined a simple linear interpolation function. However, it was overridden bySubClass
to turn it into a quadratic interpolation. When looking at just the code ofMyClass
however, it is not obvious that this function is being overridden at all - one could think that the definition inMyClass
is the one that is actually being used, however due to it being overridden this might not be the case. Introducing an@virtual
annotation would solve this problem since it is now clearly documented that, indeed, that function can be overridden and one can now search such occurrences.This change could also benefit performance, though: the GDScript compiler doesn't optimize very much currently but with this change it would be possible to inline short functions or at least replace function calls with direct references to the code.
Additionally, this makes GDScript functions similar to builtin-in functions that are also only overridable when they are defined as virtual.
However there is one major downside to this: all existing functions that can are being overridden would need to now be defined as
@virtual
. To simplify this, one could introduce some kind of "quick fix" tool that automatically adds@virtual
where needed.Beta Was this translation helpful? Give feedback.
All reactions