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

Add a line length guideline to the GDScript style guide #2567

Closed
Calinou opened this issue Jun 25, 2019 · 2 comments · Fixed by #2994
Closed

Add a line length guideline to the GDScript style guide #2567

Calinou opened this issue Jun 25, 2019 · 2 comments · Fixed by #2994

Comments

@Calinou
Copy link
Member

Calinou commented Jun 25, 2019

Unlike many other languages, the GDScript style guide currently doesn't recommend a maximum line length. We should probably adopt a guideline for this, so that people can write code more consistently across projects.

Values around 80 seem to be quite common in most high-level languages, but in my experience, it tends to feel a bit short when indenting code with tabs (or 4 spaces). This is why some Python formatters such as Black default to 88 characters:

You probably noticed the peculiar default line length. Black defaults to 88 characters per line, which happens to be 10% over 80. This number was found to produce significantly shorter files than sticking with 80 (the most popular), or even 79 (used by the standard library). In general, 90-ish seems like the wise choice.

If we recommend a line length in the style guide, we can then enable the line length guideline in the script editor by default 🙂

@aaronfranke
Copy link
Member

aaronfranke commented Jun 27, 2019

When it comes to programming video games, some things can get unavoidably long, or at least would look less clear if they were shortened. I think it should be a loose guideline for sure, but recommending a maximum amount of columns is a good idea. 80 seems too short, 90 sounds better. EDIT: But I could be wrong, y'all have probably written a lot more GDScript than I have.

By the way, this could also be added to the C# style guide, but C# code tends to be slightly longer and I'd recommend no less than 100 columns for C#.

We could also include a colored line in the editor, as some other editors do, to visually show a recommended maximum width.

@cbscribe
Copy link
Contributor

cbscribe commented Jun 29, 2019

I don't think 80 is unreasonable. It's not supposed to be a hard limit - the purpose is to let you know that you might be trying to do too much on one line. It's a visual reminder to the programmer that "hey, you're getting a bit long there, buddy." It's perfectly acceptable to go past it when necessary.

I did a quick survey of the docs and there isn't much code that goes past it. Even in the VR tutorial, which has some of the deepest nesting, there's only a handful of lines like

body.apply_impulse((raycast.global_transform.origin - body.global_transform.origin).normalized(), direction_vector * 1.2)

that blow well past any reasonable limit.

I would vote for sticking with 80, but I'd be fine with 88 if that were the consensus too.

we can then enable the line length guideline in the script editor by default

This is a good suggestion.

We could also include a colored line in the editor, as some other editors do, to visually show a recommended maximum width.

FYI, this can be enabled in the editor here:

Screen Shot 2019-06-29 at 9 52 14 AM

(Note that 80 is already the default.)

And "Line Length Guideline Color" can be set in the "Highlighting" section.

Calinou added a commit to Calinou/godot-docs that referenced this issue Dec 20, 2019
Calinou added a commit to Calinou/godot-docs that referenced this issue Dec 20, 2019
Calinou added a commit to Calinou/godot-docs that referenced this issue Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants