Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Allow new line when using chain call. #5889

Closed
Hapenia-Lans opened this issue Dec 2, 2022 · 5 comments
Closed

Allow new line when using chain call. #5889

Hapenia-Lans opened this issue Dec 2, 2022 · 5 comments

Comments

@Hapenia-Lans
Copy link

Hapenia-Lans commented Dec 2, 2022

Describe the project you are working on

Now, this kind of code is not available:

self.get_parent()
    .get_parent()
    .get_parent()
    .get_node("somechildren")

this example is stupid. but in other complex cases, this can make code cleaner.

Describe the problem or limitation you are having in your project

it should be a basic gdscript feature

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

it helps to shorten long lines

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

...

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

No, it's a gdscript feature.

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

It's a gdscript feature

@KoBeWi
Copy link
Member

KoBeWi commented Dec 2, 2022

Last time it was proposed, vnen (the main GDScript maintainer) said that it would create confusion with the old base call syntax (because in Godot 3 method calls like this will call the method from parent class).

@Mickeon
Copy link

Mickeon commented Dec 2, 2022

said that it would create confusion with the old base call syntax

Honestly, I really don't see it. It would've been easy to differentiate based on the indentation and context (most classes you may chain calls with are not really designed to be extended with scripts).

But now that is . is replaced with super() that is no minor issue, and I personally would love this. It's pretty annoying to ensure a bracket on the new line just to have this. String operations, the new Tweens, Vector manipulations... They all would be much more readable with this.

This is the kind of proposal that needs little introduction because a lot of GDScript users have gone through this and been forced to either write \ at the end of the line, which is discouraged practice, or ensure the trailing round bracket is in the right place.

@zinnschlag
Copy link

Either allow it for all cases (i.e. not only for chain calls) or forbid it for all cases. Personally I am slightly in favour of the later.

Remember: Special cases aren't special enough to break the rules. (quoted from the Zen of Python, also applicable to languages other than Python)

But anyway, a way to implement this feature for all cases would be to let a . at the end of the line have the same effect as a \. You would have to write function(). instead of .function(). But that shouldn't make much of a difference.

@Mickeon
Copy link

Mickeon commented Dec 2, 2022

But anyway, a way to implement this feature for all cases would be to let a . at the end of the line have the same effect as a . You would have to write function(). instead of .function(). But that shouldn't make much of a difference.

Sorry. It may be hypocritical for me to say, considering that I didn't deem the leading . to be too much of an issue in 3.x, but this is just not as easy to read:

self.get_parent().
    get_parent().
    get_parent().
    get_node("somechildren")

This is especially true for users with a background of languages that do not split code by indentation. Am I calling get_parent()
from this class multiple times or am I chaining it?

It's the same reason as to why I prefer to split multiline operations by beginning the sentence with the operator, instead of trailing it on the previous line. Granted, personal preference, of course.

if ( (condition1 and condition2)
or condition3):
    pass

@Calinou
Copy link
Member

Calinou commented Dec 2, 2022

Related to #2201.

Moving to discussions, as there is no concrete technical implementation provided.

@godotengine godotengine locked and limited conversation to collaborators Dec 2, 2022
@Calinou Calinou converted this issue into discussion #5890 Dec 2, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

5 participants