Преглед на файлове

Merge pull request #2995 from Calinou/add-gdscript-boolean-operators-guideline

Add a boolean operators guideline to the GDScript style guide
Nathan Lovato преди 5 години
родител
ревизия
0321330075
променени са 1 файла, в които са добавени 24 реда и са изтрити 0 реда
  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
 ~~~~~~~~~~~~~~~