Replies: 12 comments 65 replies
-
One thing I've thought a lot about for the trait system is the naming convention for traits. To fit the English-like readability of the rest of GDScript, I propose PascalCase adjectives. For example, a trait that allows a node to be interacted with could be called if some_node is Shootable:
some_node.on_shot() # on_shot() is a method on the Shootable trait I know C# uses the if some_node is TShootable:
some_node.on_shot() This looks a bit weirder to me personally, though, so I think I'd prefer the first option. Of course, if anyone has other ideas, please express those as well! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I see there are no VM changes in godotengine/godot#107227. Is the goal for it to be a runtime feature, or like Python's |
Beta Was this translation helpful? Give feedback.
-
I was thinking of unifying them all under a single word class_name CustomClass
has CustomTraits1, CustomTraits2
if CustomClass has CustomTraits1: # don't mix `is` with classes?
pass Or perhaps, the original class_name CustomClass
uses CustomTraits1, CustomTraits2
if CustomClass uses CustomTraits1:
pass |
Beta Was this translation helpful? Give feedback.
-
With the current implementation of traits, is it possible to statically type/type check for traits ? var foo : Movable if foo uses Movable:
foo.move() Also if yes, would the second example enable autocompletion for Movable properties and methods like the following would ? if foo is MyClass:
foo.method_of_myclass() #this will be autocompleted in the editor |
Beta Was this translation helpful? Give feedback.
-
Reposting that in the correct thread:
Small suggestion, use another keyword instead of extends. Extends might cause confusion implying Movable is a node, which is not the case (unless I understood it wrong) trait Movable requires Node2D
trait Movable implies Node2D
trait Movable concerns Node2D et caetera |
Beta Was this translation helpful? Give feedback.
-
Was there discussion on using interfaces (which cannot define data ownership, only API surfaces) over traits? I feel like the introduction of multiple inheritance through traits (and the accompanying collision resolution strategies and class data layout questions that come with it) is a large can of worms. |
Beta Was this translation helpful? Give feedback.
-
hello, is it possible to add/remove traits runtime? aka under a condition or event. thanks |
Beta Was this translation helpful? Give feedback.
-
One thing I would like to adress is the use of unimplemented functions. Since abstract functions are already that and are part of the engine. The only difference between the two is that unimplemented would force abstract class to implement the function while abstract functions wouldn't require that. In most cases I think not forcing the abstract to implement anything is what is expected. Except if there is a particular reason unimplemented adds a lot of value compared to abstract function I think it shouldn't be added as it will add confusion and will add maintainance cost |
Beta Was this translation helpful? Give feedback.
-
What governs if a trait's method will run in the editor? Suppose I have a class:
And another:
If I call My hope is that it would, as it would be nice if traits could run code in the editor without having to make every class that uses it a tool script also, even if they don't need to be otherwise. If that's not really feasible or possible, then oh well, traits will still be a huge improvement for lots of things. |
Beta Was this translation helpful? Give feedback.
-
is the trait system still going to use |
Beta Was this translation helpful? Give feedback.
-
Regarding the keyword for trait implementation, how about the keyword class_name Enemy
extends Node2D
applies Damageable, Movable In general, in fits the GDScript style of using plain English, especially verbs, to convey meaning. It is more precise than terms like Comparing it to other "verb" keywords:
# Do I just get these traits for free?
# This reads more like a plugin/module
class_name Enemy
extends Node2D
uses Damageable, Movable In contrast, # I have to apply for something, like a contract
# There are rules to follow before things can work
class_name Enemy
extends Node2D
applies Damageable, Moveable
Synonym to class_name Foo
extends Bar # 7 characters
applies Baz # also 7 characters class_name Foo
extends Bar # 7 characters
implements Baz # 10 characters
# You are going to be looking at these a lot Having a perfectly aligned declaration would look prettier than not having one, especially when you consider how often they would appear.
I believe classes and traits are different enough to warrant separate keywords, not to mention situations like class_name SomeClass
extends TraitA, ClassA, TraitB That is all. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Here you can discuss various aspects of the trait system. Please use separate branches for different topics:
implements
vsuses
, traits vs interfaces, etc.Beta Was this translation helpful? Give feedback.
All reactions