Skip to content

Commit 8d9085a

Browse files
authored
Add guidelines on inline comments in GDScript style guide (#9433)
* Add guidelines on inline comments in GDScript style guide
1 parent 20ebf26 commit 8d9085a

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

tutorials/scripting/gdscript/gdscript_styleguide.rst

+32-5
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,27 @@ comments from disabled code.
478478
:kbd:`Ctrl + K`. This feature adds/removes a single ``#`` sign before any
479479
code on the selected lines.
480480

481+
Prefer writing comments on their own line as opposed to inline comments
482+
(comments written on the same line as code). Inline comments are best used for
483+
short comments, typically a few words at most:
484+
485+
**Good**:
486+
487+
.. rst-class:: code-example-good
488+
489+
::
490+
491+
# This is a long comment that would make the line below too long if written inline.
492+
print("Example") # Short comment.
493+
494+
**Bad**:
495+
496+
.. rst-class:: code-example-bad
497+
498+
::
499+
500+
print("Example") # This is a long comment that would make this line too long if written inline.
501+
481502
Whitespace
482503
~~~~~~~~~~
483504

@@ -971,7 +992,7 @@ To declare the return type of a function, use ``-> <type>``:
971992
Inferred types
972993
~~~~~~~~~~~~~~
973994

974-
In most cases you can let the compiler infer the type, using ``:=``.
995+
In most cases, you can let the compiler infer the type using ``:=``.
975996
Prefer ``:=`` when the type is written on the same line as the assignment,
976997
otherwise prefer writing the type explicitly.
977998

@@ -981,8 +1002,11 @@ otherwise prefer writing the type explicitly.
9811002

9821003
::
9831004

984-
var health: int = 0 # The type can be int or float, and thus should be stated explicitly.
985-
var direction := Vector3(1, 2, 3) # The type is clearly inferred as Vector3.
1005+
# The type can be int or float, and thus should be stated explicitly.
1006+
var health: int = 0
1007+
1008+
# The type is clearly inferred as Vector3.
1009+
var direction := Vector3(1, 2, 3)
9861010

9871011
Include the type hint when the type is ambiguous, and
9881012
omit the type hint when it's redundant.
@@ -993,8 +1017,11 @@ omit the type hint when it's redundant.
9931017

9941018
::
9951019

996-
var health := 0 # Typed as int, but it could be that float was intended.
997-
var direction: Vector3 = Vector3(1, 2, 3) # The type hint has redundant information.
1020+
# Typed as int, but it could be that float was intended.
1021+
var health := 0
1022+
1023+
# The type hint has redundant information.
1024+
var direction: Vector3 = Vector3(1, 2, 3)
9981025

9991026
# What type is this? It's not immediately clear to the reader, so it's bad.
10001027
var value := complex_function()

0 commit comments

Comments
 (0)