Replies: 4 comments 10 replies
-
Double underscore to me hurts readability, it's hard to tell at a glance, it is also used in at least some other language standards as prefixes for reserved things, which might complicate things While changing the style guide is a non-functional change I'd also say it still affects existing guides, official demos, any work on linters existing or planned (including official ones), so it should be done with care IMO, especially if people expect others to follow a particular version of the style guide Edit: Also one engine feature would have to be changed, namely the names of signal receivers, so they should be adjusted to this and be I think it's an interesting idea though |
Beta Was this translation helpful? Give feedback.
-
In my opinion, we could drop the "use underscores for virtual methods" recommendation. There is no point in using underscores for public methods. Native virtual methods like As for abstract/virtual/final/must-override methods, I think we could use keywords/annotations instead. The base class is always known statically, so we won't have problems with the dynamic nature of GDScript, unlike access modifiers. class A:
func f1(): pass
@virtual func f2(): pass
@virtual func f3(): pass
# No func f4().
# No func f5().
class B extends A:
func f1(): pass # Warning: Overriding a non-virtual method.
func f2(): pass # Warning: Overriding a method without @override.
@override func f3(): pass # OK.
@override func f4(): pass # Error: Overriding a non-existent method.
func f5(): pass # OK. |
Beta Was this translation helpful? Give feedback.
-
GDScript borrowed the term "virtual" from C++, but for a different usage. The virtual qualifier is also not well-documented. I think that's the cause of the confusion. All methods are virtualC++ in GDScript. The virtual qualifier in GDScript specifically means "it's an engine callback" rather than the broader meaning of "to be overriden". The current style guide makes sense: Leaving aside the fact that there is an overlap between the concepts of virtualGDScript methods and private methods, neither should be called manually from outside. So the You can generate the class reference XML with the |
Beta Was this translation helpful? Give feedback.
-
possible future annotations @abstract func foo()
@virtual func foo(): pass
@override func foo(): #code
@private func foo(): pass |
Beta Was this translation helpful? Give feedback.
-
This proposal is a non-functional change, just a suggestion on the style guide. Sorry if this is not the right channel for these types of proposals.
The styleguide suggests prepending a single
_
to the name of "to virtual methods functions the user must override, private functions, and private variables". This makes it difficult to add a linter rule for warning against private member access as the same syntax is used for functions that are intended to be overridden. I suggest updating the style for private members to__
(double underscore) to avoid this issue. The convention of using underscores is pretty common in other languages but given that it is a non-functional change it would be much easier to update.Beta Was this translation helpful? Give feedback.
All reactions