-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Naming of boolean setters/getters #33026
Comments
Just my two cents, but I prefer properties to getters and setters. I would prefer to have
Then you can have:
As opposed to:
If we're changing a bunch of getters and setters, we could just remove them. |
Properties are defined via a setter and a getter, so we still need to name them... |
Related to what @aaronfranke mentioned, but in C++ context rather than GDScript: Any plans of getting rid of trivial getters/setters? |
@rxlecky This guideline doesn't explain what are the advantages. Using public members instead of trivial getters/setters can be a problem when one of them becomes non-trivial for any reason, and you end up modifying your whole codebase rather than one method. So I would argue against doing it systematically, even if in some cases it makes sense to improve code readability (like around math stuff, which is already the case in Godot). |
@pouleyKetchoupp You make a really valid point here Using public members instead of trivial getters/setters can be a problem when one of them becomes non-trivial for any reason, and you end up modifying your whole codebase rather than one method. |
PathFollow2D has a |
It would be interesting to make a script to extract boolean getters/setters from the codebase and rename them to follow the convention outlined in the proposal. This way, we can quickly see if any of them look particularly awkward. |
See proposal godotengine/godot-proposals#1994. |
Superseded by godotengine/godot-proposals#1994. |
We have a lot of inconsistency in the current codebase on how we name boolean setters and getters, and especially those we expose to the scripting API.
We should aim at fixing that for 4.0, breaking compatibility where needed. Related to #16863.
Current uses are of the form:
Can also be more tricky if the boolean name is verb, like:
I'm not sure what style we should settle on, but it needs to be consistent.
Here's a proposal to start the discussion:
processing
instead ofprocess
, which solves some of the issues shown above.p_enabled
as parameter in the setter.set_<boolean>
for the setter, andis_<boolean>_enabled
as getter.Example:
The text was updated successfully, but these errors were encountered: