Skip to content
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

GDScript: Prevent circular dependencies #1737

Closed
ShalokShalom opened this issue Oct 27, 2020 · 7 comments
Closed

GDScript: Prevent circular dependencies #1737

ShalokShalom opened this issue Oct 27, 2020 · 7 comments

Comments

@ShalokShalom
Copy link

ShalokShalom commented Oct 27, 2020

Describe the project you are working on:

Independent from project, round-based strategy game.

Describe the problem or limitation you are having in your project:

Circular dependencies can still happen.

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

The core idea is to prevent circular dependencies by requiring the file order and code order to be strictly in sync with the dependency order.

This can also be done optionally, in case it is seen as too intrusive as a default setting. 🙂

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

FSharp does this already. See here why and how

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

No.

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

Since GDScript is in core and it's a clear improvement to it.
Much fun 🥳

@Xrayez
Copy link
Contributor

Xrayez commented Oct 27, 2020

See related closed issues: https://github.com/godotengine/godot-proposals/issues?q=is%3Aissue+is%3Aclosed+cyclic

This is currently treated as a bug: godotengine/godot#21461.

But in my opinion, I'd just reopen #460 to avoid duplicate reports. 😛

@ShalokShalom
Copy link
Author

This is all not quite the same as preventing circular dependencies in the first place, thanks a lot for your intent. 😊

@ShalokShalom ShalokShalom changed the title GDScript: Circular dependency prevention GDScript: Prevent circular dependencies Oct 28, 2020
@Xrayez
Copy link
Contributor

Xrayez commented Oct 28, 2020

@ShalokShalom sorry, I see you edited the original post to suggest adding an option for this, I suggest to elaborate on your proposal more. 😮

This is confusing given circular references has not even been resolved yet. I'm not sure whether a simple language like GDScript will allow making it optional.

@ShalokShalom
Copy link
Author

Once circular references are possible, a circular dependency is possible too. This suggestion prevents it.

@vnen
Copy link
Member

vnen commented Nov 3, 2020

You should really add some examples here. In which way are circular dependencies allowed? The only way I see this happening is with preload and inheritance, and both have checks to avoid cycles.

Unless you mean every cyclic reference is also a cyclic dependency. But if we remove that it's pretty much impossible to use static typing.

Also not sure what "file order" means here since GDScript files are compiled individually.

@MonoGameDev
Copy link

Unless you mean every cyclic reference is also a cyclic dependency. But if we remove that it's pretty much impossible to use static typing.

Just out of curiousity, what exactly makes it so difficult to implement static typing while allowing cyclic references? I'd imagine, that you could just check if a class has already been loaded and if so, use it for auto completion.
But I assume there is some deeper reason for why that doesn't work, right?

@Calinou
Copy link
Member

Calinou commented Sep 26, 2022

Support for cyclic references is being added in godotengine/godot#65752 (only for 4.0 – it won't be backported to 3.x as it uses an entirely different GDScript implementation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants