Explorar o código

Add a boolean operators guideline to the GDScript style guide

Hugo Locurcio %!s(int64=6) %!d(string=hai) anos
pai
achega
c6fa2483f8
Modificáronse 1 ficheiros con 24 adicións e 0 borrados
  1. 24 0
      getting_started/scripting/gdscript/gdscript_styleguide.rst

+ 24 - 0
getting_started/scripting/gdscript/gdscript_styleguide.rst

@@ -131,6 +131,30 @@ necessary for order of operations, they only reduce readability.
     if (is_colliding()):
         queue_free()
 
+Boolean operators
+~~~~~~~~~~~~~~~~~
+
+Prefer the spelled-out versions of boolean operators (``and``/``or``) to their
+symbolic equivalents (`&&`/`||`). They're usually more readable as they're plain
+English words.
+
+Add parentheses around boolean operators to avoid ambiguity, even if they're not
+strictly required. This makes long expressions easier to read.
+
+**Good**:
+
+::
+
+    if (foo and bar) or baz:
+        print("condition is true")
+
+**Bad**:
+
+::
+
+    if foo && bar || baz:
+        print("condition is true")
+
 Comment spacing
 ~~~~~~~~~~~~~~~