Open Xrayez opened 3 years ago
I agree that it was helpful in this case.
However on the other hand, if we disable it all at once, then we would lose advantages of using undocumented methods available from gdscript especially when making plugins.
For example, there are many useful ScriptEditor
methods like _menu_option()
get_editor_interface().get_script_editor()._menu_option(7)
is for saving all scripts an script list.
I understand that it is risky to rely on such methods, but often this is the only way to solve a certain problem. And it may take a while to wait for the desired method to be exposed back.
So I am for careful manual selecting of methods that should be hidden and those that could be exposed.
Yes, for those we'd simply have to provide additional public API, but yeah I totally understand the problem.
Given that Godot's development philosophy is based on extreme pragmatism, oftentimes it takes a while for something to be exposed in Godot until a use case pops up to justify an addition (especially for less frequently used features), even if it makes perfect sense to expose something for completeness sake in the first place, regardless whether something has real-life usage.
I believe most features in Godot will find a use case in real-life projects anyways, the only problem I see with Godot development is maintenance, yet it shouldn't really be a problem given Godot is advertised to be a community-driven project, and I hope it is. 🙂
P.S. Sorry to talk about this from a fundamental point of view (which may seem like off-topic), but this is just where most problems can be identified and eliminated with the engine development.
Simple script shows that there is 671 methods which starts with _
- some like _ready
are proper but some are not
func _ready() -> void:
var hidden_methods : Array = []
for name_of_class in ClassDB.get_class_list():
for method_data in ClassDB.class_get_method_list(name_of_class,true):
var method_name = method_data["name"]
if !method_name.begins_with("_"): # Non hidden method
continue
hidden_methods.append(name_of_class + "." + method_name)
hidden_methods.sort()
print("------ Found " + str(hidden_methods.size()) + " hidden methods")
for i in hidden_methods:
print(i)
List of all functions
This is really out there, but I usually like to be explicit when writing code. Since the tag system is already implemented in 4.0, wouldn't it be useful to use it for overrides?
Like so:
@override
func _ready() -> void:
# do stuff
pass
# and so on for every "magic" method
It doesn't have to be this syntax exactly, but the point I'm trying to make here is that it's better to be explicit when you're overriding a method rather than silently shadow it. If you don't explicitly do it, it could show an error or warning.
Honestly I don't like "magic" names that by convention are supposed to be shadowed. I always prefer to be explicit so anyone can read the code know what it's doing. Also, it's useful to use underscore names as a way to signify you shouldn't call that method explicitly from outside that class (private member signifier by naming convention); in such cases like the given example accidental shadowing can occur when using this convention.
in such cases like the given example accidental shadowing can occur when using this convention.
I think we'd get the same problem either way, explicit or not, because there's just no core mechanism that determines whether those methods are internal or not. Currently, these internal callbacks can be overridden just like public methods, because they are technically public methods as well, even though they are not visible in documentation, autocompletion etc.
I'd even go as far to say that it's not a GDScript problem, it's core ClassDB
problem, which indeed does not have an explicit way to mark methods as internal (so GDScript could properly implement it).
One of the reasons (or the only reason) why they're "exposed" is because some of these methods must be called deferred (even when used internally), and that requires registering those methods in ClassDB
that start with underscore (yeah, that's how core distinguishes between internal and public methods, unless they are marked as virtual explicitly, like _ready
). That's how I came up with godotengine/godot#42968.
My argument is that godot uses _
to mean public access but an internal function. If we decide to implement this proposal, I should suggest renaming the current uses of _
. We currently don't have a pattern for private functions that are accessible by scripting and this proposal is indirectly arguing for a private script method.
My opinion is this conflicts with existing decision of "public access for internal functions" and so we should revisit the earlier decision and choose that one or this one. The preference is for the decision made earlier in time.
Describe the project you are working on
Goost Godot Engine Extension.
Describe the problem or limitation you are having in your project
If you look at reports such as:
you'll see that those methods are not part of public API, yet it's still possible to call those methods and callbacks manually via script (autocompletion also won't work for those methods).
For instance, some time ago I've accidentally overridden
_update_callback()
inNode2D
to schedule world update:As it turns out,
_update_callback
uses a similar mechanism to schedule draw calls toupdate()
, but since I'm overriding it, nothing is actually drawn, and I couldn't figure out why until I renamed_update_callback
toupdate_callback
.Here's another example: godotengine/godot#42755.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I'm not saying that those methods should be exposed, but I think there should be a clear and intuitive mechanism to either completely forbid the access of those methods via script, or allow to show a warning when such methods get used/overridden.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I've previously submitted a proof-of-concept PR which helps to alleviate this issue by showing a warning for those internal methods: godotengine/godot#42968.
The problem is that it's still possible to call those methods without seeing the warning (only works for methods which get overridden).
If this enhancement will not be used often, can it be worked around with a few lines of script?
No, there's no apparent mechanism which could allow to detect those internal callbacks via script.
Is there a reason why this should be core and not an add-on in the asset library?
Can only be resolved in core.