@@ -478,6 +478,27 @@ comments from disabled code.
478
478
:kbd: `Ctrl + K `. This feature adds/removes a single ``# `` sign before any
479
479
code on the selected lines.
480
480
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
+
481
502
Whitespace
482
503
~~~~~~~~~~
483
504
@@ -971,7 +992,7 @@ To declare the return type of a function, use ``-> <type>``:
971
992
Inferred types
972
993
~~~~~~~~~~~~~~
973
994
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 ``:= ``.
975
996
Prefer ``:= `` when the type is written on the same line as the assignment,
976
997
otherwise prefer writing the type explicitly.
977
998
@@ -981,8 +1002,11 @@ otherwise prefer writing the type explicitly.
981
1002
982
1003
::
983
1004
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)
986
1010
987
1011
Include the type hint when the type is ambiguous, and
988
1012
omit the type hint when it's redundant.
@@ -993,8 +1017,11 @@ omit the type hint when it's redundant.
993
1017
994
1018
::
995
1019
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)
998
1025
999
1026
# What type is this? It's not immediately clear to the reader, so it's bad.
1000
1027
var value := complex_function()
0 commit comments