godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Rename "Singleton" column in Project Settings / AutoLoad to "Global" (or something else) #1649

Closed hilfazer closed 3 years ago

hilfazer commented 3 years ago

Describe the project you are working on: Top-down dungeon crawler.

Describe the problem or limitation you are having in your project: Checkbox for adding a global reference being called "Singleton" can confuse people since in Godot this word is also used for things that are singletons according to a widespread definition of this word (global + 1 instance limit) like ClassDB, Marshalls or Input.

GodotSingletonConfusion1

GodotSingletonConfusion2

(i took those screenshots from Godot's Discord public channels so i guess it's OK if i post them here; let me know if it's not)

Describe the feature / enhancement and how it helps to overcome the problem or limitation: Rename the "Singleton" column to "Global". The word is better understood by more people and it properly describes what is being done here. It would prevent users from making a connection with engine singletons.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: GodotGlobalAutoload

If this enhancement will not be used often, can it be worked around with a few lines of script?: Judging by Godot's Discord autoloads are used extremely often.

Is there a reason why this should be core and not an add-on in the asset library?: People who could get confused by "Singleton" wouldn't know to install such plugin.

hilfazer commented 3 years ago

If someone needs more convincing there's this recent question on Godot Q&A:

https://godotengine.org/qa/95097/engine-has_singleton-engine-get_singleton-behaving-expected

YuriSizov commented 3 years ago

If someone needs more convincing there's this recent question on Godot Q&A:

https://godotengine.org/qa/95097/engine-has_singleton-engine-get_singleton-behaving-expected

Well, this calls for an alternative and clear way to detect if a user defined "singleton" exists, not for a rename of the column.

The problem with Global is that it doesn't convey they sense of a singular instance of the autoload. It is not a singleton in the programming pattern sense, but this flag does not make something Global, all autoloads are global in that sense. What this flags does is it binds an instance to the name, not the class.

So, in the interest of not confusing beginners and experiensed programmers alike, the rename would be a good thing, but the name suggested is even more cryptic than the existing one.


Edit: To think about it, even calling the column "Single Instance" would be better...

hilfazer commented 3 years ago

This column is for adding a global reference to an autoloaded Node. Therefore a better name would be "Global Reference" but maybe that's too long, I don't know. If this column is unchecked there will be no name in the global namespace and the node will not be available in References and static functions unless they get access to them some other way.

What a coincidence! "Single Instance" happens to be the exact name i'd give to a design pattern that limits instances of a class to 1 but, unlike Singleton, does not give a global access to that instance.

YuriSizov commented 3 years ago

The point is not that it's a reference, but that it's a reference to an instance of the class, not the class itself. From the looks of it, there is currently no easy way to get a reference to a class, other than iterating all items in ProjectSettings and loading each autoload path. Can it even be considered autoloaded at this point? I guess in the editor at least it's added to the resource cache either way...

So, again, I think it makes more sense to address those issues linked by providing a simpler way to work with autoloads. A method to check the existence of a singular instance and a method to get a reference to a class would be helpful and solve the woes.

Column naming is secondary, but it should reflect the essence of it — that it creates an instance.

hilfazer commented 3 years ago

If someone needs more convincing there's this recent question on Godot Q&A: https://godotengine.org/qa/95097/engine-has_singleton-engine-get_singleton-behaving-expected

Well, this calls for an alternative and clear way to detect if a user defined "singleton" exists, not for a rename of the column.

It calls for both. Even if such way gets added people would still sometimes try to use the existing methods to find their "singletons".

Calinou commented 3 years ago

While I agree that we should replace the use of "Singleton" with something else, I'm not sure if either "Global" or "Single Instance" are better names. Godot doesn't actually enforce a singleton pattern over autoloads. You can manually create more than one instance of an autoloaded scene or script.

Edit: I'll go for "Global Variable", which is longer but more explicit.

Xrayez commented 3 years ago

"Global Variable" may also be confusing, it may convey that:

"Global" sounds ok to me as suggested originally in the OP.