godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.26k stars 101 forks source link

Add a GDScript warning to forbid access to pseudo-private members (name beginning with an underscore) #12580

Open MarianoGnu opened 1 month ago

MarianoGnu commented 1 month ago

Describe the project you are working on

I prototype games in my spare time, and work in a Molecular simulation system at work

Describe the problem or limitation you are having in your project

None, i already use underscore to annotate private members in my code

Describe the feature / enhancement and how it helps to overcome the problem or limitation

As is widely known, GdScript does not provide private variables, and it doesn't need them, but would be a good addition to enforce the usage of underscre prefix convenion for those members that are not meant to be accessed from outside.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

For this reason i htink it would be practical to have a Warning similar to those as unreachable code, incompatible ternary, or souch that could be set to Warn or Error by default, to help new users to get used to this particular aspect of GdScript convenions.

It could also help (if the warning is set to Error) to prevent https://github.com/godotengine/godot-proposals/issues/2285

If this enhancement will not be used often, can it be worked around with a few lines of script?

i am not aware if new warnings could be added with a plugin, but the point of this is helping in the UX of users worldwide, not for myself

Is there a reason why this should be core and not an add-on in the asset library?

i am not aware if new warnings could be added with a plugin