|
@@ -108,6 +108,8 @@ Each indent level should be one greater than the block containing it.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
for i in range(10):
|
|
for i in range(10):
|
|
@@ -115,6 +117,8 @@ Each indent level should be one greater than the block containing it.
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
for i in range(10):
|
|
for i in range(10):
|
|
@@ -128,6 +132,8 @@ regular code blocks.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
effect.interpolate_property(sprite, "transform/scale",
|
|
effect.interpolate_property(sprite, "transform/scale",
|
|
@@ -136,6 +142,8 @@ regular code blocks.
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
effect.interpolate_property(sprite, "transform/scale",
|
|
effect.interpolate_property(sprite, "transform/scale",
|
|
@@ -147,6 +155,8 @@ indentation level to distinguish continuation lines:
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
var party = [
|
|
var party = [
|
|
@@ -170,6 +180,8 @@ indentation level to distinguish continuation lines:
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
var party = [
|
|
var party = [
|
|
@@ -200,6 +212,8 @@ line doesn't need to be modified when adding new elements.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
enum Tiles {
|
|
enum Tiles {
|
|
@@ -211,6 +225,8 @@ line doesn't need to be modified when adding new elements.
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
enum Tiles {
|
|
enum Tiles {
|
|
@@ -224,12 +240,16 @@ Trailing commas are unnecessary in single-line lists, so don't add them in this
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
enum Tiles {TILE_BRICK, TILE_FLOOR, TILE_SPIKE, TILE_TELEPORT}
|
|
enum Tiles {TILE_BRICK, TILE_FLOOR, TILE_SPIKE, TILE_TELEPORT}
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
enum Tiles {TILE_BRICK, TILE_FLOOR, TILE_SPIKE, TILE_TELEPORT,}
|
|
enum Tiles {TILE_BRICK, TILE_FLOOR, TILE_SPIKE, TILE_TELEPORT,}
|
|
@@ -274,6 +294,8 @@ not even with a single line conditional statement.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
if position.x > width:
|
|
if position.x > width:
|
|
@@ -284,6 +306,8 @@ not even with a single line conditional statement.
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
if position.x > width: position.x = 0
|
|
if position.x > width: position.x = 0
|
|
@@ -315,6 +339,8 @@ end of the previous line.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
var angle_degrees = 135
|
|
var angle_degrees = 135
|
|
@@ -334,6 +360,8 @@ end of the previous line.
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
var angle_degrees = 135
|
|
var angle_degrees = 135
|
|
@@ -352,6 +380,8 @@ they only reduce readability.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
if is_colliding():
|
|
if is_colliding():
|
|
@@ -359,6 +389,8 @@ they only reduce readability.
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
if (is_colliding()):
|
|
if (is_colliding()):
|
|
@@ -377,6 +409,8 @@ This can make long expressions easier to read.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
if (foo and bar) or baz:
|
|
if (foo and bar) or baz:
|
|
@@ -384,6 +418,8 @@ This can make long expressions easier to read.
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
if foo && bar || baz:
|
|
if foo && bar || baz:
|
|
@@ -397,6 +433,8 @@ This helps differentiate text comments from disabled code.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
# This is a comment.
|
|
# This is a comment.
|
|
@@ -404,6 +442,8 @@ This helps differentiate text comments from disabled code.
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
#This is a comment.
|
|
#This is a comment.
|
|
@@ -423,6 +463,8 @@ in dictionary references and function calls.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
position.x = 5
|
|
position.x = 5
|
|
@@ -433,6 +475,8 @@ in dictionary references and function calls.
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
position.x=5
|
|
position.x=5
|
|
@@ -476,12 +520,20 @@ Don't omit the leading or trailing zero in floating-point numbers. Otherwise,
|
|
this makes them less readable and harder to distinguish from integers at a
|
|
this makes them less readable and harder to distinguish from integers at a
|
|
glance.
|
|
glance.
|
|
|
|
|
|
-**Good**::
|
|
|
|
|
|
+**Good**:
|
|
|
|
+
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
|
|
var float_number = 0.234
|
|
var float_number = 0.234
|
|
var other_float_number = 13.0
|
|
var other_float_number = 13.0
|
|
|
|
|
|
-**Bad**::
|
|
|
|
|
|
+**Bad**:
|
|
|
|
+
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
|
|
var float_number = .234
|
|
var float_number = .234
|
|
var other_float_number = 13.
|
|
var other_float_number = 13.
|
|
@@ -489,18 +541,30 @@ glance.
|
|
Use lowercase for letters in hexadecimal numbers, as their lower height makes
|
|
Use lowercase for letters in hexadecimal numbers, as their lower height makes
|
|
the number easier to read.
|
|
the number easier to read.
|
|
|
|
|
|
-**Good**::
|
|
|
|
|
|
+**Good**:
|
|
|
|
+
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
|
|
var hex_number = 0xfb8c0b
|
|
var hex_number = 0xfb8c0b
|
|
|
|
|
|
-**Bad**::
|
|
|
|
|
|
+**Bad**:
|
|
|
|
+
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
|
|
var hex_number = 0xFB8C0B
|
|
var hex_number = 0xFB8C0B
|
|
|
|
|
|
Take advantage of GDScript's underscores in literals to make large numbers more
|
|
Take advantage of GDScript's underscores in literals to make large numbers more
|
|
readable.
|
|
readable.
|
|
|
|
|
|
-**Good**::
|
|
|
|
|
|
+**Good**:
|
|
|
|
+
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
|
|
var large_number = 1_234_567_890
|
|
var large_number = 1_234_567_890
|
|
var large_hex_number = 0xffff_f8f8_0000
|
|
var large_hex_number = 0xffff_f8f8_0000
|
|
@@ -508,7 +572,11 @@ readable.
|
|
# Numbers lower than 1000000 generally don't need separators.
|
|
# Numbers lower than 1000000 generally don't need separators.
|
|
var small_number = 12345
|
|
var small_number = 12345
|
|
|
|
|
|
-**Bad**::
|
|
|
|
|
|
+**Bad**:
|
|
|
|
+
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
|
|
var large_number = 1234567890
|
|
var large_number = 1234567890
|
|
var large_hex_number = 0xfffff8f80000
|
|
var large_hex_number = 0xfffff8f80000
|
|
@@ -815,12 +883,16 @@ should set the type explicitly.
|
|
|
|
|
|
**Good**:
|
|
**Good**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-good
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
onready var health_bar: ProgressBar = get_node("UI/LifeBar")
|
|
onready var health_bar: ProgressBar = get_node("UI/LifeBar")
|
|
|
|
|
|
**Bad**:
|
|
**Bad**:
|
|
|
|
|
|
|
|
+.. rst-class:: code-example-bad
|
|
|
|
+
|
|
::
|
|
::
|
|
|
|
|
|
# The compiler can't infer the exact type and will use Node
|
|
# The compiler can't infer the exact type and will use Node
|