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

Allow second line brackets #1209

Closed
Tracked by #40488
Shadowblitz16 opened this issue Jul 17, 2020 · 5 comments
Closed
Tracked by #40488

Allow second line brackets #1209

Shadowblitz16 opened this issue Jul 17, 2020 · 5 comments

Comments

@Shadowblitz16
Copy link

Describe the project you are working on:
A space ship project

Describe the problem or limitation you are having in your project:
I just don't like it

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
allow for second line brackets and braces like so..

var arr = 
[  #this
 0,
 1,
 2,
]

var dic= 
{  #this
 "a": 0,
 "b": 1,
 "c": 2,
}

currently this throws a error unless you change it to this..

var arr = [ 
 0,
 1,
 2,
]

var dic= {
 "a": 0,
 "b": 1,
 "c": 2,
}

I think this is not only is utter crap in the way it forces the way you format but it also is less readable for me

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
basically the parser would just allow for this to happen and wouldn't complain.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
I would use it and I'm sure other c developers and no it can't be worked around

Is there a reason why this should be core and not an add-on in the asset library?:
its less confusing to not get a error when this happens

@Calinou
Copy link
Member

Calinou commented Jul 17, 2020

I just don't like it

I think this is not only is utter crap in the way it forces the way you format but it also is less readable for me

You need to use more rational arguments for this 🙂

Most languages with an indent-based syntax won't allow you to write the following:

var arr = 
[  #this
 0,
 1,
 2,
]

var dic= 
{  #this
 "a": 0,
 "b": 1,
 "c": 2,
}

However, you can use backslashes to escape newlines so this becomes valid syntax:

var arr = \
[  #this
 0,
 1,
 2,
]

var dic= \
{  #this
 "a": 0,
 "b": 1,
 "c": 2,
}

Still, just because you can doesn't mean you should. I don't see an issue with the established syntax for writing arrays or dictionaries on multiple lines.

@jonbonazza
Copy link

I don't know of any language that supports this, indent-based or not.

@Calinou
Copy link
Member

Calinou commented Jul 17, 2020

@jonbonazza This apparently works in C (just tested it with GCC and Clang):

struct example {
	int a;
	int b;
};

int main() {
	struct example ex =
	{
		2,
		4,
	};

	return 0;
}

However, this is possible only because C doesn't use an indent-based syntax.

@dalexeev
Copy link
Member

Theoretically, we can allow line breaks for binary operations (= can also be considered a binary operator).
The question is whether it's worth it. This will definitely complicate the parser.

var a = true && # Expected to continue; the line break is ignored.
    false # End of expression.
var b = true
    && false # Will be added to the previous line.

But IMO it is less readable than with parentheses.

@Calinou
Copy link
Member

Calinou commented Nov 3, 2021

Closing, as this isn't worth the added parser complexity in an indentation-based language like GDScript. Backslashes or parentheses can already be used to wrap expressions over multiple lines.

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