Align code expression vertically

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sinkaa

Hi !

So I just read through the GDScript Style guide because I figured it would be time to write code correctly. There’s one thing I don’t have enough info about and I would like some clarification.

Quote :


Whitespace
Don’t use spaces to align expressions vertically:

x        = 100
y        = 100
velocity = 500 

And that’s it. No real explanation why it’s bad.
(With the other example on the page, I understand why there is a rule.
But this one… not so much)

They don’t give a substitute or a way around like “use tabulations”, “never do that” or “use this code structure instead” either.

In my case, I have a bunch of variable that work very similarly, so I used spaces to align them to make it clear when I do stuff with them :

@export var short_name_score       : int
@export var really_long_name_score : int

or

short_name_score       += 100
really_long_name_score += 100

So why is it bad ? Should I use tabulation ?
As I am working on a solo project I probably won’t change it, but I would like to learn why I shouldn’t do it.

:bust_in_silhouette: Reply From: jgodfrey

As with most coding style guides, the main motivation is to HAVE some standards in place that everyone can refer to. The details of the suggestions (in this or other such guides) can be reasonably argued one way or another. The point is less about the details of the standard and more about HAVING a standard (though, I’m not suggesting that considerable thought hasn’t gone into the style guide).

In my view, style guides are much more useful when working with a larger team or within an organization where multiple people are interacting with the same code base on a regular basis. In that case, common coding styles serve to improve the effectiveness of the team.

While I don’t know the motivations regarding this specific suggestion (vertical alignment), there’s certainly no reason you need to use it in your own code. You’re obviously free to write your code any way you see fit, though again, a “common” style is ultimately beneficial in that case too.

That being said, I’m not familiar with the internals of the gdscript parser / interpreter / compiler. I suppose there’s a non-zero chance that the extra spaces used for vertical alignment might cost an extra cycle or two during code parsing, though I really have no idea…

Bottom line, if you like to see blocks of code vertically aligned, there’s nothing wrong with that.