Consistently prefix bound virtual methods with _#48746
Consistently prefix bound virtual methods with _#48746akien-mga merged 1 commit intogodotengine:masterfrom
Conversation
a526254 to
1a2c38c
Compare
|
I am not sure this makes a lot of sense. We use the underscore as a prefix to notify a function is private or protected, not if it's virtual or not. The I mean, we can discuss if we want to change our naming rules, but right now it seems to me that this PR makes things less consistent than they are now. |
In GDScript it denotes virtual methods. Check methods like Also some classes bind these methods for internal use, which results in duplicate docs that shouldn't exist. See #47260 (comment) for example. Prefixing with underscore fixes this problem, because non-virtual methods starting with underscore are hidden by default. |
Well, yeah, in a way they are private. Of course in GDscript there's no real notion of public or private, but the goal of those functions here is internal to the node, and thus they are not supposed to be called from outside of it. Which kind of make them "private". On the other hand, The documentation issue is another problem though, maybe we should have usage flag that does not put the function in the documentation? |
Well, in such cases we separate the public method that is called vs the class specific implementation that is prefixed. See Object's |
Indeed. Though that kind of makes my point, as I believe it makes sense to keep methods without the underscore prefix as public, and internal stuff with a prefix. Here both function are clearly different (even if the naming is similar), since one will return all properties (get_property_list) and the other should only return the properties of the given class/script (_get_property_list). |
|
We discussed this in a PR review meeting today. We had a lengthy discussion on the public/protected status of those methods and whether there should be public (non virtual) methods bound that match the protected (virtual, with underscore prefix), so that you still have e.g. But it turns out that all the methods which are bound as virtual are actually not public methods and can't be called from script, so this change is correct to make it even more obvious (you can't call There are still some cases where a public non-virtual method is bound, such as TL;DR: The change is good. |
akien-mga
left a comment
There was a problem hiding this comment.
Can be merged once rebased.
384f593 to
4d97fea
Compare
4d97fea to
7ff135b
Compare
|
Thanks! |
|
Uh , I just noticed that |
Adresses #16863 (comment)
All methods bound as virtual were renamed to have underscore at the beginning. Previously it was inconsistent.
As a bonus, this also removes some docs of methods that were needlessly documented (see ScriptEditor.xml for example).
I also changed
AnimationNode::has_filter(), because it wasn't using the designated virtual method.I also also changed some methods that were using
ClassDB::add_virtual_methodinstead ofBIND_VMETHODand simplified some of the binds.