Commit 3f729f9 1 parent 2950c3b commit 3f729f9 Copy full SHA for 3f729f9
File tree 1 file changed +18
-1
lines changed
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Conditionals
2
2
3
3
## Default Values
4
- Use [ ternary operator] ( http://lua-users.org/wiki/TernaryOperator ) 'or' Instead of nil checks for performance and readability optimization .
4
+ Consider [ ternary operator] ( http://lua-users.org/wiki/TernaryOperator ) 'or' instead of nil checks to improve readability.
5
5
``` lua title="BAD"
6
6
if name then
7
7
return name
25
25
``` lua title="GOOD"
26
26
return name == " mark" or name == " stacy"
27
27
```
28
+
29
+ ## Prefer positive boolean expressions
30
+ This makes the code easier to read.
31
+ ``` lua title="BAD"
32
+ if not isHappy then
33
+ return " sad"
34
+ else
35
+ return " happy"
36
+ end
37
+ ```
38
+ ``` lua title="GOOD"
39
+ if isHappy then
40
+ return " happy"
41
+ else
42
+ return " sad"
43
+ end
44
+ ```
You can’t perform that action at this time.
0 commit comments