-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standardize names for boolean properties, getters and setters #1994
Comments
See the original discussion on the main repository: And here's my feedback:
|
I just name getters/setters like |
I agree with most points in the proposal and with @pouleyKetchoupp's feedback above. In particular, adding more ways to do the same thing with slightly different semantic doesn't strike me as a good idea (e.g. duplicating Similarly for 5., I'd also keep it on a case by case basis for the handful of places where it makes sense. So I wouldn't make it a rule, just a note that, where relevant, this can be done after discussion. For 1., I'm a bit concerned about the scope of changes that this would imply. The To reach a consensus on what the APIs should be like, I think we should take a few concrete examples from the existing API, and see what changes would be implied by the proposed name changes to make things more consistent. Then we can easily see if we like those new APIs, and thus validate the rules. |
Describe the project you are working on
Godot engine
Describe the problem or limitation you are having in your project
Godot properties have underlying methods that can also be used to retrieve and change the property value called the getter and setter. Assuming a property is well named i.e. appropriately describes the value it holds, the
property_name
has a standard getter and setter:get_property_name()
andset_property_name()
.However, with
bool
(true
orfalse
) properties this structure is awkward and complicated by the standard for retrievingbool
values usingis_*
orhas_*
, etc. rather thanget_*
. For example, for a property namedenabled
, the getter should beis_enabled()
notget_enabled()
. The problem is, what should the setter be called: the naturalenable()
or the more awkwardset_enabled()
? This is further complicated by methods that have natural opposites eg.pause()
andresume()
to control the propertypaused
.Furthermore, although it's already been agreed (godotengine/godot#16863) that
bool
properties should be named positively to avoid double negatives, there are a number ofbool
properties that determine what theObject
will do when it's created e.g.loop
. This creates an awkward getter:is_loop()
. Instead it would be better if the property were named for what it will be doing when it's created:looping
, which has the better getter:is_looping()
.However, there is a further complication. The property may be read-only once it is created i.e. there shouldn't be a setter. In other words, there is sometimes a need for two properties: one for controlling what the object will be doing and one for what it is doing. For example,
start
has a natural property calledstarted
that is read-only i.e. it only has a getter:is_started()
. The question is, what should the property to determine whether or not theObject
should automaticallystart
when created be called:start
,auto_start
,auto_started
or, as is often done, something completely different e.g.playing
?Describe the feature / enhancement and how it helps to overcome the problem or limitation
bool
properties have names that describe what theObject
will be or is doing e.g. uselooping
and notloop
.bool
properties don't use negative names (which can be hard to spot) e.g. uselooping
and not notone_shot
. (Yes, the double negative is deliberate.)set_*()
andget_*()
for the properties in addition tois_*()
which maps toget_*()
.auto_*
with an action verb for the former and the gerund i.e.*ing
for the latter e.g.auto_play
andplaying
respectively. Note: sinceplaying
is read-only it will not be exposed as a property, but only have the methodis_playing()
.bool
property has a natural setter and "unsetter", they can be created as helper functions that map toset_*(true)
andset_*(false)
. For exampleenabled
should haveenable()
mapped toset_enabled(true)
and anddisable()
mapped toset_enabled(false)
,paused
should havepause
mapped toset_paused(true)
andresume()
mapped toset_paused(false)
.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Described above.
If this enhancement will not be used often, can it be worked around with a few lines of script?
N/A
Is there a reason why this should be core and not an add-on in the asset library?
N/A
The text was updated successfully, but these errors were encountered: