浏览代码

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

Add a boolean operators guideline to the GDScript style guide
Nathan Lovato 6 年之前
父节点
当前提交
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
 ~~~~~~~~~~~~~~~