CompiledFrog

Post #32: The GDScript Style Guide

Did you know that GDScript has a style guide?

The style guide is there to help you see and learn what idiomatic GDScript is. To introduce this, we'll give one example from the style guide.

What is wrong with this example?

effect.interpolate_property(sprite, "transform/scale",
	sprite.get_scale(), Vector2(2.0, 2.0), 0.3,
	Tween.TRANS_QUAD, Tween.EASE_OUT)

Well, you might think this looks fine! However, the style guide actually recommends that you, "Use 2 indent levels to distinguish continuation lines from regular code blocks." Therefore, the fixed (correct) example would look like this:

effect.interpolate_property(sprite, "transform/scale",
		sprite.get_scale(), Vector2(2.0, 2.0), 0.3,
		Tween.TRANS_QUAD, Tween.EASE_OUT)

The style guide says that this helps, "distinguish continuation lines from regular code blocks". Whether you may agree or not, sometimes (especially when you have multiple people working on a project) it's better to be consistent, even if you may think it's the wrong choice, compared to being "right" but then introducing multiple paradigms in the codebase. (For the above examples, see the Indentation section.)

Check out the style guide, and hopefully it will help you read and write GDScript more effectively!